diff --git "a/partition_86.json" "b/partition_86.json" new file mode 100644--- /dev/null +++ "b/partition_86.json" @@ -0,0 +1,105754 @@ +[ + { + "hash": "ee8e27ad4facd8123858f3b046f6bba78fea7c89", + "msg": "Fix 2.3 compatibility on windows.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-14T20:31:42+00:00", + "author_timezone": 0, + "committer_date": "2006-03-14T20:31:42+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "7afda6a7aa249f3bfe490e62f61480d9e5e9c941" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 1, + "insertions": 1, + "lines": 2, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/testing/utils.py", + "new_path": "numpy/testing/utils.py", + "filename": "utils.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -64,7 +64,7 @@ def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n \n-if os.name=='nt':\n+if os.name=='nt' and sys.version[:3] > '2.3':\n # Code stolen from enthought/debug/memusage.py\n import win32pdh\n # from win32pdhutil, part of the win32all package\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "\"\"\"\nUtility function to facilitate testing.\n\"\"\"\n\nimport os\nimport sys\n\n__all__ = ['assert_equal', 'assert_almost_equal','assert_approx_equal',\n 'assert_array_equal', 'assert_array_less',\n 'assert_array_almost_equal', 'jiffies', 'memusage', 'rand',\n 'runstring']\n\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 from numpy.core import zeros, Float64\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\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_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 import time\n if not _load_time:\n _load_time.append(time.time())\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[0]))\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=[]):\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 import time\n if not _load_time:\n _load_time.append(time.time())\n return int(100*(time.time()-_load_time[0]))\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\nif os.name=='nt' and sys.version[:3] > '2.3':\n # Code stolen from enthought/debug/memusage.py\n import win32pdh\n # from win32pdhutil, part of the win32all package\n def GetPerformanceAttributes(object, counter, instance = None,\n inum=-1, format = win32pdh.PDH_FMT_LONG, machine=None):\n # NOTE: Many counters require 2 samples to give accurate results,\n # including \"% Processor Time\" (as by definition, at any instant, a\n # thread's CPU usage is either 0 or 100). To read counters like this,\n # you should copy this function, but keep the counter open, and call\n # CollectQueryData() each time you need to know.\n # See http://msdn.microsoft.com/library/en-us/dnperfmo/html/perfmonpt2.asp\n # My older explanation for this was that the \"AddCounter\" process forced\n # the CPU to 100%, but the above makes more sense :)\n path = win32pdh.MakeCounterPath( (machine,object,instance, None, inum,counter) )\n hq = win32pdh.OpenQuery()\n try:\n hc = win32pdh.AddCounter(hq, path)\n try:\n win32pdh.CollectQueryData(hq)\n type, val = win32pdh.GetFormattedCounterValue(hc, format)\n return val\n finally:\n win32pdh.RemoveCounter(hc)\n finally:\n win32pdh.CloseQuery(hq)\n\n def memusage(processName=\"python\", instance=0):\n return GetPerformanceAttributes(\"Process\", \"Virtual Bytes\",\n processName, instance,\n win32pdh.PDH_FMT_LONG, None)\n\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(desired, dict):\n assert isinstance(actual, dict),`type(actual)`\n assert_equal(len(actual),len(desired),err_msg,verbose)\n for k,i in desired.items():\n assert actual.has_key(k),`k`\n assert_equal(actual[k], desired[k], 'key=%r\\n%s' % (k,err_msg), verbose)\n return\n if isinstance(desired, list) and isinstance(actual, list):\n assert_equal(len(actual),len(desired),err_msg,verbose)\n for k in range(len(desired)):\n assert_equal(actual[k], desired[k], 'item=%r\\n%s' % (k,err_msg), verbose)\n return\n from numpy.core import ArrayType\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 return\n\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 from numpy.core import ArrayType\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\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 import math\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n if desired==actual:\n return\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\ndef assert_array_equal(x,y,err_msg=''):\n from numpy.core import asarray, alltrue, equal, shape, ravel, array2string\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\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n from numpy.core import asarray, alltrue, equal, shape, ravel,\\\n array2string, less_equal, around\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\ndef assert_array_less(x,y,err_msg=''):\n from numpy.core import asarray, alltrue, less, equal, shape, ravel, array2string\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\ndef runstring(astr, dict):\n exec astr in dict\n", + "source_code_before": "\"\"\"\nUtility function to facilitate testing.\n\"\"\"\n\nimport os\nimport sys\n\n__all__ = ['assert_equal', 'assert_almost_equal','assert_approx_equal',\n 'assert_array_equal', 'assert_array_less',\n 'assert_array_almost_equal', 'jiffies', 'memusage', 'rand',\n 'runstring']\n\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 from numpy.core import zeros, Float64\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\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_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 import time\n if not _load_time:\n _load_time.append(time.time())\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[0]))\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=[]):\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 import time\n if not _load_time:\n _load_time.append(time.time())\n return int(100*(time.time()-_load_time[0]))\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\nif os.name=='nt':\n # Code stolen from enthought/debug/memusage.py\n import win32pdh\n # from win32pdhutil, part of the win32all package\n def GetPerformanceAttributes(object, counter, instance = None,\n inum=-1, format = win32pdh.PDH_FMT_LONG, machine=None):\n # NOTE: Many counters require 2 samples to give accurate results,\n # including \"% Processor Time\" (as by definition, at any instant, a\n # thread's CPU usage is either 0 or 100). To read counters like this,\n # you should copy this function, but keep the counter open, and call\n # CollectQueryData() each time you need to know.\n # See http://msdn.microsoft.com/library/en-us/dnperfmo/html/perfmonpt2.asp\n # My older explanation for this was that the \"AddCounter\" process forced\n # the CPU to 100%, but the above makes more sense :)\n path = win32pdh.MakeCounterPath( (machine,object,instance, None, inum,counter) )\n hq = win32pdh.OpenQuery()\n try:\n hc = win32pdh.AddCounter(hq, path)\n try:\n win32pdh.CollectQueryData(hq)\n type, val = win32pdh.GetFormattedCounterValue(hc, format)\n return val\n finally:\n win32pdh.RemoveCounter(hc)\n finally:\n win32pdh.CloseQuery(hq)\n\n def memusage(processName=\"python\", instance=0):\n return GetPerformanceAttributes(\"Process\", \"Virtual Bytes\",\n processName, instance,\n win32pdh.PDH_FMT_LONG, None)\n\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(desired, dict):\n assert isinstance(actual, dict),`type(actual)`\n assert_equal(len(actual),len(desired),err_msg,verbose)\n for k,i in desired.items():\n assert actual.has_key(k),`k`\n assert_equal(actual[k], desired[k], 'key=%r\\n%s' % (k,err_msg), verbose)\n return\n if isinstance(desired, list) and isinstance(actual, list):\n assert_equal(len(actual),len(desired),err_msg,verbose)\n for k in range(len(desired)):\n assert_equal(actual[k], desired[k], 'item=%r\\n%s' % (k,err_msg), verbose)\n return\n from numpy.core import ArrayType\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 return\n\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 from numpy.core import ArrayType\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\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 import math\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n if desired==actual:\n return\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\ndef assert_array_equal(x,y,err_msg=''):\n from numpy.core import asarray, alltrue, equal, shape, ravel, array2string\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\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n from numpy.core import asarray, alltrue, equal, shape, ravel,\\\n array2string, less_equal, around\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\ndef assert_array_less(x,y,err_msg=''):\n from numpy.core import asarray, alltrue, less, equal, shape, ravel, array2string\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\ndef runstring(astr, dict):\n exec astr in dict\n", + "methods": [ + { + "name": "rand", + "long_name": "rand( * args )", + "filename": "utils.py", + "nloc": 8, + "complexity": 2, + "token_count": 53, + "parameters": [ + "args" + ], + "start_line": 13, + "end_line": 24, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "jiffies", + "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", + "filename": "utils.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "_proc_pid_stat" + ], + "start_line": 27, + "end_line": 28, + "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": "utils.py", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "_proc_pid_stat" + ], + "start_line": 42, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "jiffies", + "long_name": "jiffies( _load_time = [ ] )", + "filename": "utils.py", + "nloc": 5, + "complexity": 2, + "token_count": 43, + "parameters": [ + "_load_time" + ], + "start_line": 56, + "end_line": 62, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "memusage", + "long_name": "memusage( )", + "filename": "utils.py", + "nloc": 2, + "complexity": 1, + "token_count": 6, + "parameters": [], + "start_line": 63, + "end_line": 65, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "GetPerformanceAttributes", + "long_name": "GetPerformanceAttributes( object , counter , instance = None , inum = - 1 , format = win32pdh . PDH_FMT_LONG , machine = None )", + "filename": "utils.py", + "nloc": 14, + "complexity": 3, + "token_count": 103, + "parameters": [ + "object", + "counter", + "instance", + "inum", + "format", + "machine" + ], + "start_line": 71, + "end_line": 92, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "memusage", + "long_name": "memusage( processName = \"python\" , instance = 0 )", + "filename": "utils.py", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "processName", + "instance" + ], + "start_line": 94, + "end_line": 97, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "assert_equal", + "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", + "filename": "utils.py", + "nloc": 28, + "complexity": 12, + "token_count": 271, + "parameters": [ + "actual", + "desired", + "err_msg", + "verbose" + ], + "start_line": 99, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "assert_almost_equal", + "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", + "filename": "utils.py", + "nloc": 15, + "complexity": 7, + "token_count": 138, + "parameters": [ + "actual", + "desired", + "decimal", + "err_msg", + "verbose" + ], + "start_line": 131, + "end_line": 148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "assert_approx_equal", + "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", + "filename": "utils.py", + "nloc": 26, + "complexity": 8, + "token_count": 202, + "parameters": [ + "actual", + "desired", + "significant", + "err_msg", + "verbose" + ], + "start_line": 151, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "assert_array_equal", + "long_name": "assert_array_equal( x , y , err_msg = '' )", + "filename": "utils.py", + "nloc": 23, + "complexity": 7, + "token_count": 248, + "parameters": [ + "x", + "y", + "err_msg" + ], + "start_line": 185, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "assert_array_almost_equal", + "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", + "filename": "utils.py", + "nloc": 28, + "complexity": 6, + "token_count": 272, + "parameters": [ + "x", + "y", + "decimal", + "err_msg" + ], + "start_line": 210, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "assert_array_less", + "long_name": "assert_array_less( x , y , err_msg = '' )", + "filename": "utils.py", + "nloc": 21, + "complexity": 5, + "token_count": 207, + "parameters": [ + "x", + "y", + "err_msg" + ], + "start_line": 239, + "end_line": 259, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "runstring", + "long_name": "runstring( astr , dict )", + "filename": "utils.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "astr", + "dict" + ], + "start_line": 261, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "rand", + "long_name": "rand( * args )", + "filename": "utils.py", + "nloc": 8, + "complexity": 2, + "token_count": 53, + "parameters": [ + "args" + ], + "start_line": 13, + "end_line": 24, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "jiffies", + "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", + "filename": "utils.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "_proc_pid_stat" + ], + "start_line": 27, + "end_line": 28, + "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": "utils.py", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "_proc_pid_stat" + ], + "start_line": 42, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "jiffies", + "long_name": "jiffies( _load_time = [ ] )", + "filename": "utils.py", + "nloc": 5, + "complexity": 2, + "token_count": 43, + "parameters": [ + "_load_time" + ], + "start_line": 56, + "end_line": 62, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "memusage", + "long_name": "memusage( )", + "filename": "utils.py", + "nloc": 2, + "complexity": 1, + "token_count": 6, + "parameters": [], + "start_line": 63, + "end_line": 65, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "GetPerformanceAttributes", + "long_name": "GetPerformanceAttributes( object , counter , instance = None , inum = - 1 , format = win32pdh . PDH_FMT_LONG , machine = None )", + "filename": "utils.py", + "nloc": 14, + "complexity": 3, + "token_count": 103, + "parameters": [ + "object", + "counter", + "instance", + "inum", + "format", + "machine" + ], + "start_line": 71, + "end_line": 92, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "memusage", + "long_name": "memusage( processName = \"python\" , instance = 0 )", + "filename": "utils.py", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "processName", + "instance" + ], + "start_line": 94, + "end_line": 97, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "assert_equal", + "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", + "filename": "utils.py", + "nloc": 28, + "complexity": 12, + "token_count": 271, + "parameters": [ + "actual", + "desired", + "err_msg", + "verbose" + ], + "start_line": 99, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "assert_almost_equal", + "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", + "filename": "utils.py", + "nloc": 15, + "complexity": 7, + "token_count": 138, + "parameters": [ + "actual", + "desired", + "decimal", + "err_msg", + "verbose" + ], + "start_line": 131, + "end_line": 148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "assert_approx_equal", + "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", + "filename": "utils.py", + "nloc": 26, + "complexity": 8, + "token_count": 202, + "parameters": [ + "actual", + "desired", + "significant", + "err_msg", + "verbose" + ], + "start_line": 151, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "assert_array_equal", + "long_name": "assert_array_equal( x , y , err_msg = '' )", + "filename": "utils.py", + "nloc": 23, + "complexity": 7, + "token_count": 248, + "parameters": [ + "x", + "y", + "err_msg" + ], + "start_line": 185, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "assert_array_almost_equal", + "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", + "filename": "utils.py", + "nloc": 28, + "complexity": 6, + "token_count": 272, + "parameters": [ + "x", + "y", + "decimal", + "err_msg" + ], + "start_line": 210, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "assert_array_less", + "long_name": "assert_array_less( x , y , err_msg = '' )", + "filename": "utils.py", + "nloc": 21, + "complexity": 5, + "token_count": 207, + "parameters": [ + "x", + "y", + "err_msg" + ], + "start_line": 239, + "end_line": 259, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "runstring", + "long_name": "runstring( astr , dict )", + "filename": "utils.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "astr", + "dict" + ], + "start_line": 261, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 213, + "complexity": 58, + "token_count": 1802, + "diff_parsed": { + "added": [ + "if os.name=='nt' and sys.version[:3] > '2.3':" + ], + "deleted": [ + "if os.name=='nt':" + ] + } + } + ] + }, + { + "hash": "440214d5835da50d9dad3103835fb8b3967eb3b5", + "msg": "New version number", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-14T21:24:34+00:00", + "author_timezone": 0, + "committer_date": "2006-03-14T21:24:34+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "ee8e27ad4facd8123858f3b046f6bba78fea7c89" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 1, + "insertions": 1, + "lines": 2, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/version.py", + "new_path": "numpy/version.py", + "filename": "version.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -1,4 +1,4 @@\n-version='0.9.6'\n+version='0.9.7'\n \n import os\n svn_version_file = os.path.join(os.path.dirname(__file__),\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "version='0.9.7'\n\nimport os\nsvn_version_file = os.path.join(os.path.dirname(__file__),\n 'core','__svn_version__.py')\nif os.path.isfile(svn_version_file):\n import imp\n svn = imp.load_module('numpy.core.__svn_version__',\n open(svn_version_file),\n svn_version_file,\n ('.py','U',1))\n version += '.'+svn.version\n", + "source_code_before": "version='0.9.6'\n\nimport os\nsvn_version_file = os.path.join(os.path.dirname(__file__),\n 'core','__svn_version__.py')\nif os.path.isfile(svn_version_file):\n import imp\n svn = imp.load_module('numpy.core.__svn_version__',\n open(svn_version_file),\n svn_version_file,\n ('.py','U',1))\n version += '.'+svn.version\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": 11, + "complexity": 0, + "token_count": 68, + "diff_parsed": { + "added": [ + "version='0.9.7'" + ], + "deleted": [ + "version='0.9.6'" + ] + } + } + ] + }, + { + "hash": "03736884e2fb993e096ef801dd49135b9292b823", + "msg": "Changed the C-API by making the a.flags object a builtin object for speed. Also fixed issues with linalg and matrices.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-15T00:48:04+00:00", + "author_timezone": 0, + "committer_date": "2006-03-15T00:48:04+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "440214d5835da50d9dad3103835fb8b3967eb3b5" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 205, + "insertions": 463, + "lines": 668, + "files": 10, + "dmm_unit_size": 0.56, + "dmm_unit_complexity": 0.696, + "dmm_unit_interfacing": 0.88, + "modified_files": [ + { + "old_path": "numpy/core/_internal.py", + "new_path": "numpy/core/_internal.py", + "filename": "_internal.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -3,156 +3,7 @@\n # that implements more complicated stuff.\n \n import re\n-from multiarray import _flagdict, dtype, ndarray\n-\n-_defflags = _flagdict.keys()\n-\n-_setable = ['WRITEABLE','UPDATEIFCOPY', 'ALIGNED',\n- 'W','U','A']\n-_setable2 = ['write','uic','align']*2\n-_firstltr = {'W':'WRITEABLE',\n- 'A':'ALIGNED',\n- 'C':'CONTIGUOUS',\n- 'F':'FORTRAN',\n- 'O':'OWNDATA',\n- 'U':'UPDATEIFCOPY'}\n-\n-_anum = _flagdict['ALIGNED']\n-_wnum = _flagdict['WRITEABLE']\n-_cnum = _flagdict['CONTIGUOUS']\n-_fnum = _flagdict['FORTRAN']\n-_unum = _flagdict['UPDATEIFCOPY']\n-_onum = _flagdict['OWNDATA']\n-\n-class flagsobj(dict):\n- def __init__(self, arr, flags, scalar):\n- self._arr = arr\n- self._flagnum = flags\n- for k in _defflags:\n- num = _flagdict[k]\n- dict.__setitem__(self, k, flags & num == num)\n- self.scalar = scalar\n-\n- def __getitem__(self, key):\n- if not isinstance(key, str):\n- raise KeyError, \"Unknown flag %s\" % key\n- if len(key) == 1:\n- try:\n- return dict.__getitem__(self, _firstltr[key])\n- except:\n- if (key == 'B'):\n- num = _anum + _wnum\n- return self._flagnum & num == num\n- else:\n- try:\n- return dict.__getitem__(self, key)\n- except: # special cases\n- if (key == 'FNC'):\n- return (self._flagnum & _fnum == _fnum) and not \\\n- (self._flagnum & _cnum == _cnum)\n- if (key == 'FORC'):\n- return (self._flagnum & _fnum == _fnum) or \\\n- (self._flagnum & _cnum == _cnum)\n- if (key == 'BEHAVED'):\n- num = _anum + _wnum\n- return self._flagnum & num == num\n- if (key in ['CARRAY','CA']):\n- num = _anum + _wnum + _cnum\n- return self._flagnum & num == num\n- if (key in ['FARRAY','FA']):\n- num = _anum + _wnum + _fnum\n- return (self._flagnum & num == num) and not \\\n- (self._flagnum & _cnum == _cnum)\n- raise KeyError, \"Unknown flag: %s\" % key\n-\n- def __setitem__(self, item, val):\n- if self.scalar:\n- raise ValueError, \"Cannot set flags on array scalars.\"\n- val = not not val # convert to boolean\n- if item not in _setable:\n- raise KeyError, \"Cannot set flag\", item\n- dict.__setitem__(self, item, val) # Does this matter?\n-\n- kwds = {}\n- for k, name in enumerate(_setable):\n- if item == name:\n- kwds[_setable2[k]] = val\n-\n- # now actually update array flags\n- self._arr.setflags(**kwds)\n-\n-\n- def get_fnc(self):\n- fl = self._flagnum\n- return (fl & _fnum == _fnum) and \\\n- not (fl & _cnum == _cnum)\n-\n- def get_forc(self):\n- fl = self._flagnum\n- return (fl & _cnum == _cnum) or \\\n- (fl & _fnum == _fnum)\n-\n- def get_behaved(self):\n- fl = self._flagnum\n- return (fl & _anum == _anum) and \\\n- (fl & _wnum == _wnum)\n-\n- def get_carray(self):\n- fl = self._flagnum\n- return (fl & _anum == _anum) and \\\n- (fl & _wnum == _wnum) and \\\n- (fl & _cnum == _cnum)\n-\n- def get_farray(self):\n- fl = self._flagnum\n- return (fl & _anum == _anum) and \\\n- (fl & _wnum == _wnum) and \\\n- (fl & _fnum == _fnum) and \\\n- not (fl & _cnum == _cnum)\n-\n- def get_contiguous(self):\n- return (self._flagnum & _cnum == _cnum)\n-\n- def get_fortran(self):\n- return (self._flagnum & _fnum == _fnum)\n-\n- def get_updateifcopy(self):\n- return (self._flagnum & _unum == _unum)\n-\n- def get_owndata(self):\n- return (self._flagnum & _onum == _onum)\n-\n- def get_aligned(self):\n- return (self._flagnum & _anum == _anum)\n-\n- def get_writeable(self):\n- return (self._flagnum & _wnum == _wnum)\n-\n- def set_writeable(self, val):\n- val = not not val\n- self._arr.setflags(write=val)\n-\n- def set_aligned(self, val):\n- val = not not val\n- self._arr.setflags(align=val)\n-\n- def set_updateifcopy(self, val):\n- val = not not val\n- self._arr.setflags(uic=val)\n-\n- contiguous = property(get_contiguous, None, \"\")\n- fortran = property(get_fortran, None, \"\")\n- updateifcopy = property(get_updateifcopy, set_updateifcopy, \"\")\n- owndata = property(get_owndata, None, \"\")\n- aligned = property(get_aligned, set_aligned, \"\")\n- writeable = property(get_writeable, set_writeable, \"\")\n-\n- fnc = property(get_fnc, None, \"\")\n- forc = property(get_forc, None, \"\")\n- behaved = property(get_behaved, None, \"\")\n- carray = property(get_carray, None, \"\")\n- farray = property(get_farray, None, \"\")\n-\n+from multiarray import dtype, ndarray\n \n # make sure the tuple entries are PyArray_Descr\n # or convert them\n", + "added_lines": 1, + "deleted_lines": 150, + "source_code": "\n#A place for code to be called from C-code\n# that implements more complicated stuff.\n\nimport re\nfrom multiarray import dtype, ndarray\n\n# make sure the tuple entries are PyArray_Descr\n# or convert them\n#\n# make sure offsets are all interpretable\n# as positive integers and\n# convert them to positive integers if so\n#\n#\n# return totalsize from last offset and size\n\n# Called in PyArray_DescrConverter function when\n# a dictionary without \"names\" and \"formats\"\n# fields is used as a data-type descriptor.\ndef _usefields(adict, align):\n try:\n names = adict[-1]\n except KeyError:\n names = None\n if names is None:\n allfields = []\n fnames = adict.keys()\n for fname in fnames:\n obj = adict[fname]\n n = len(obj)\n if not isinstance(obj, tuple) or n not in [2,3]:\n raise ValueError, \"entry not a 2- or 3- tuple\"\n if (n > 2) and (obj[2] == fname):\n continue\n num = int(obj[1])\n if (num < 0):\n raise ValueError, \"invalid offset.\"\n format = dtype(obj[0])\n if (format.itemsize == 0):\n raise ValueError, \"all itemsizes must be fixed.\"\n if (n > 2):\n title = obj[2]\n else:\n title = None\n allfields.append((fname, format, num, title))\n # sort by offsets\n allfields.sort(lambda x,y: cmp(x[2],y[2]))\n names = [x[0] for x in allfields]\n formats = [x[1] for x in allfields]\n offsets = [x[2] for x in allfields]\n titles = [x[3] for x in allfields]\n else:\n formats = []\n offsets = []\n titles = []\n for name in names:\n res = adict[name]\n formats.append(res[0])\n offsets.append(res[1])\n if (len(res) > 2):\n titles.append(res[2])\n else:\n titles.append(None)\n\n return dtype({\"names\" : names,\n \"formats\" : formats,\n \"offsets\" : offsets,\n \"titles\" : titles}, align)\n\n\n# construct an array_protocol descriptor list\n# from the fields attribute of a descriptor\n# This calls itself recursively but should eventually hit\n# a descriptor that has no fields and then return\n# a simple typestring\n\ndef _array_descr(descriptor):\n fields = descriptor.fields\n if fields is None:\n return descriptor.str\n\n ordered_fields = [fields[x] + (x,) for x in fields[-1]]\n result = []\n offset = 0\n for field in ordered_fields:\n if field[1] > offset:\n result.append(('','|V%d' % (field[1]-offset)))\n if len(field) > 3:\n name = (field[2],field[3])\n else:\n name = field[2]\n if field[0].subdtype:\n tup = (name, _array_descr(field[0].subdtype[0]),\n field[0].subdtype[1])\n else:\n tup = (name, _array_descr(field[0]))\n offset += field[0].itemsize\n result.append(tup)\n\n return result\n\ndef _reconstruct(subtype, shape, dtype):\n return ndarray.__new__(subtype, shape, dtype)\n\n\n# format_re and _split were taken from numarray by J. Todd Miller\n\ndef _split(input):\n \"\"\"Split the input formats string into field formats without splitting\n the tuple used to specify multi-dimensional arrays.\"\"\"\n\n newlist = []\n hold = ''\n\n for element in input.split(','):\n if hold != '':\n item = hold + ',' + element\n else:\n item = element\n left = item.count('(')\n right = item.count(')')\n\n # if the parenthesis is not balanced, hold the string\n if left > right :\n hold = item\n\n # when balanced, append to the output list and reset the hold\n elif left == right:\n newlist.append(item.strip())\n hold = ''\n\n # too many close parenthesis is unacceptable\n else:\n raise SyntaxError, item\n\n # if there is string left over in hold\n if hold != '':\n raise SyntaxError, hold\n\n return newlist\n\nformat_re = re.compile(r'(?P *[(]?[ ,0-9]*[)]? *)(?P[><|A-Za-z0-9.]*)')\n\n# astr is a string (perhaps comma separated)\n\ndef _commastring(astr):\n res = _split(astr)\n if (len(res)) == 1:\n raise ValueError, \"no commas present\"\n result = []\n for k,item in enumerate(res):\n # convert item\n try:\n (repeats, dtype) = format_re.match(item).groups()\n except (TypeError, AttributeError):\n raise ValueError('format %s is not recognized' % item)\n\n if (repeats == ''):\n newitem = dtype\n else:\n newitem = (dtype, eval(repeats))\n result.append(newitem)\n\n return result\n\n\n", + "source_code_before": "\n#A place for code to be called from C-code\n# that implements more complicated stuff.\n\nimport re\nfrom multiarray import _flagdict, dtype, ndarray\n\n_defflags = _flagdict.keys()\n\n_setable = ['WRITEABLE','UPDATEIFCOPY', 'ALIGNED',\n 'W','U','A']\n_setable2 = ['write','uic','align']*2\n_firstltr = {'W':'WRITEABLE',\n 'A':'ALIGNED',\n 'C':'CONTIGUOUS',\n 'F':'FORTRAN',\n 'O':'OWNDATA',\n 'U':'UPDATEIFCOPY'}\n\n_anum = _flagdict['ALIGNED']\n_wnum = _flagdict['WRITEABLE']\n_cnum = _flagdict['CONTIGUOUS']\n_fnum = _flagdict['FORTRAN']\n_unum = _flagdict['UPDATEIFCOPY']\n_onum = _flagdict['OWNDATA']\n\nclass flagsobj(dict):\n def __init__(self, arr, flags, scalar):\n self._arr = arr\n self._flagnum = flags\n for k in _defflags:\n num = _flagdict[k]\n dict.__setitem__(self, k, flags & num == num)\n self.scalar = scalar\n\n def __getitem__(self, key):\n if not isinstance(key, str):\n raise KeyError, \"Unknown flag %s\" % key\n if len(key) == 1:\n try:\n return dict.__getitem__(self, _firstltr[key])\n except:\n if (key == 'B'):\n num = _anum + _wnum\n return self._flagnum & num == num\n else:\n try:\n return dict.__getitem__(self, key)\n except: # special cases\n if (key == 'FNC'):\n return (self._flagnum & _fnum == _fnum) and not \\\n (self._flagnum & _cnum == _cnum)\n if (key == 'FORC'):\n return (self._flagnum & _fnum == _fnum) or \\\n (self._flagnum & _cnum == _cnum)\n if (key == 'BEHAVED'):\n num = _anum + _wnum\n return self._flagnum & num == num\n if (key in ['CARRAY','CA']):\n num = _anum + _wnum + _cnum\n return self._flagnum & num == num\n if (key in ['FARRAY','FA']):\n num = _anum + _wnum + _fnum\n return (self._flagnum & num == num) and not \\\n (self._flagnum & _cnum == _cnum)\n raise KeyError, \"Unknown flag: %s\" % key\n\n def __setitem__(self, item, val):\n if self.scalar:\n raise ValueError, \"Cannot set flags on array scalars.\"\n val = not not val # convert to boolean\n if item not in _setable:\n raise KeyError, \"Cannot set flag\", item\n dict.__setitem__(self, item, val) # Does this matter?\n\n kwds = {}\n for k, name in enumerate(_setable):\n if item == name:\n kwds[_setable2[k]] = val\n\n # now actually update array flags\n self._arr.setflags(**kwds)\n\n\n def get_fnc(self):\n fl = self._flagnum\n return (fl & _fnum == _fnum) and \\\n not (fl & _cnum == _cnum)\n\n def get_forc(self):\n fl = self._flagnum\n return (fl & _cnum == _cnum) or \\\n (fl & _fnum == _fnum)\n\n def get_behaved(self):\n fl = self._flagnum\n return (fl & _anum == _anum) and \\\n (fl & _wnum == _wnum)\n\n def get_carray(self):\n fl = self._flagnum\n return (fl & _anum == _anum) and \\\n (fl & _wnum == _wnum) and \\\n (fl & _cnum == _cnum)\n\n def get_farray(self):\n fl = self._flagnum\n return (fl & _anum == _anum) and \\\n (fl & _wnum == _wnum) and \\\n (fl & _fnum == _fnum) and \\\n not (fl & _cnum == _cnum)\n\n def get_contiguous(self):\n return (self._flagnum & _cnum == _cnum)\n\n def get_fortran(self):\n return (self._flagnum & _fnum == _fnum)\n\n def get_updateifcopy(self):\n return (self._flagnum & _unum == _unum)\n\n def get_owndata(self):\n return (self._flagnum & _onum == _onum)\n\n def get_aligned(self):\n return (self._flagnum & _anum == _anum)\n\n def get_writeable(self):\n return (self._flagnum & _wnum == _wnum)\n\n def set_writeable(self, val):\n val = not not val\n self._arr.setflags(write=val)\n\n def set_aligned(self, val):\n val = not not val\n self._arr.setflags(align=val)\n\n def set_updateifcopy(self, val):\n val = not not val\n self._arr.setflags(uic=val)\n\n contiguous = property(get_contiguous, None, \"\")\n fortran = property(get_fortran, None, \"\")\n updateifcopy = property(get_updateifcopy, set_updateifcopy, \"\")\n owndata = property(get_owndata, None, \"\")\n aligned = property(get_aligned, set_aligned, \"\")\n writeable = property(get_writeable, set_writeable, \"\")\n\n fnc = property(get_fnc, None, \"\")\n forc = property(get_forc, None, \"\")\n behaved = property(get_behaved, None, \"\")\n carray = property(get_carray, None, \"\")\n farray = property(get_farray, None, \"\")\n\n\n# make sure the tuple entries are PyArray_Descr\n# or convert them\n#\n# make sure offsets are all interpretable\n# as positive integers and\n# convert them to positive integers if so\n#\n#\n# return totalsize from last offset and size\n\n# Called in PyArray_DescrConverter function when\n# a dictionary without \"names\" and \"formats\"\n# fields is used as a data-type descriptor.\ndef _usefields(adict, align):\n try:\n names = adict[-1]\n except KeyError:\n names = None\n if names is None:\n allfields = []\n fnames = adict.keys()\n for fname in fnames:\n obj = adict[fname]\n n = len(obj)\n if not isinstance(obj, tuple) or n not in [2,3]:\n raise ValueError, \"entry not a 2- or 3- tuple\"\n if (n > 2) and (obj[2] == fname):\n continue\n num = int(obj[1])\n if (num < 0):\n raise ValueError, \"invalid offset.\"\n format = dtype(obj[0])\n if (format.itemsize == 0):\n raise ValueError, \"all itemsizes must be fixed.\"\n if (n > 2):\n title = obj[2]\n else:\n title = None\n allfields.append((fname, format, num, title))\n # sort by offsets\n allfields.sort(lambda x,y: cmp(x[2],y[2]))\n names = [x[0] for x in allfields]\n formats = [x[1] for x in allfields]\n offsets = [x[2] for x in allfields]\n titles = [x[3] for x in allfields]\n else:\n formats = []\n offsets = []\n titles = []\n for name in names:\n res = adict[name]\n formats.append(res[0])\n offsets.append(res[1])\n if (len(res) > 2):\n titles.append(res[2])\n else:\n titles.append(None)\n\n return dtype({\"names\" : names,\n \"formats\" : formats,\n \"offsets\" : offsets,\n \"titles\" : titles}, align)\n\n\n# construct an array_protocol descriptor list\n# from the fields attribute of a descriptor\n# This calls itself recursively but should eventually hit\n# a descriptor that has no fields and then return\n# a simple typestring\n\ndef _array_descr(descriptor):\n fields = descriptor.fields\n if fields is None:\n return descriptor.str\n\n ordered_fields = [fields[x] + (x,) for x in fields[-1]]\n result = []\n offset = 0\n for field in ordered_fields:\n if field[1] > offset:\n result.append(('','|V%d' % (field[1]-offset)))\n if len(field) > 3:\n name = (field[2],field[3])\n else:\n name = field[2]\n if field[0].subdtype:\n tup = (name, _array_descr(field[0].subdtype[0]),\n field[0].subdtype[1])\n else:\n tup = (name, _array_descr(field[0]))\n offset += field[0].itemsize\n result.append(tup)\n\n return result\n\ndef _reconstruct(subtype, shape, dtype):\n return ndarray.__new__(subtype, shape, dtype)\n\n\n# format_re and _split were taken from numarray by J. Todd Miller\n\ndef _split(input):\n \"\"\"Split the input formats string into field formats without splitting\n the tuple used to specify multi-dimensional arrays.\"\"\"\n\n newlist = []\n hold = ''\n\n for element in input.split(','):\n if hold != '':\n item = hold + ',' + element\n else:\n item = element\n left = item.count('(')\n right = item.count(')')\n\n # if the parenthesis is not balanced, hold the string\n if left > right :\n hold = item\n\n # when balanced, append to the output list and reset the hold\n elif left == right:\n newlist.append(item.strip())\n hold = ''\n\n # too many close parenthesis is unacceptable\n else:\n raise SyntaxError, item\n\n # if there is string left over in hold\n if hold != '':\n raise SyntaxError, hold\n\n return newlist\n\nformat_re = re.compile(r'(?P *[(]?[ ,0-9]*[)]? *)(?P[><|A-Za-z0-9.]*)')\n\n# astr is a string (perhaps comma separated)\n\ndef _commastring(astr):\n res = _split(astr)\n if (len(res)) == 1:\n raise ValueError, \"no commas present\"\n result = []\n for k,item in enumerate(res):\n # convert item\n try:\n (repeats, dtype) = format_re.match(item).groups()\n except (TypeError, AttributeError):\n raise ValueError('format %s is not recognized' % item)\n\n if (repeats == ''):\n newitem = dtype\n else:\n newitem = (dtype, eval(repeats))\n result.append(newitem)\n\n return result\n\n\n", + "methods": [ + { + "name": "_usefields", + "long_name": "_usefields( adict , align )", + "filename": "_internal.py", + "nloc": 47, + "complexity": 17, + "token_count": 331, + "parameters": [ + "adict", + "align" + ], + "start_line": 21, + "end_line": 69, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 49, + "top_nesting_level": 0 + }, + { + "name": "_array_descr", + "long_name": "_array_descr( descriptor )", + "filename": "_internal.py", + "nloc": 22, + "complexity": 7, + "token_count": 175, + "parameters": [ + "descriptor" + ], + "start_line": 78, + "end_line": 101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_reconstruct", + "long_name": "_reconstruct( subtype , shape , dtype )", + "filename": "_internal.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "subtype", + "shape", + "dtype" + ], + "start_line": 103, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_split", + "long_name": "_split( input )", + "filename": "_internal.py", + "nloc": 20, + "complexity": 6, + "token_count": 99, + "parameters": [ + "input" + ], + "start_line": 109, + "end_line": 141, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_commastring", + "long_name": "_commastring( astr )", + "filename": "_internal.py", + "nloc": 16, + "complexity": 5, + "token_count": 101, + "parameters": [ + "astr" + ], + "start_line": 147, + "end_line": 165, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "__init__", + "long_name": "__init__( self , arr , flags , scalar )", + "filename": "_internal.py", + "nloc": 7, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self", + "arr", + "flags", + "scalar" + ], + "start_line": 28, + "end_line": 34, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , key )", + "filename": "_internal.py", + "nloc": 31, + "complexity": 14, + "token_count": 230, + "parameters": [ + "self", + "key" + ], + "start_line": 36, + "end_line": 66, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "__setitem__", + "long_name": "__setitem__( self , item , val )", + "filename": "_internal.py", + "nloc": 12, + "complexity": 5, + "token_count": 82, + "parameters": [ + "self", + "item", + "val" + ], + "start_line": 68, + "end_line": 82, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "get_fnc", + "long_name": "get_fnc( self )", + "filename": "_internal.py", + "nloc": 4, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 85, + "end_line": 88, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_forc", + "long_name": "get_forc( self )", + "filename": "_internal.py", + "nloc": 4, + "complexity": 2, + "token_count": 27, + "parameters": [ + "self" + ], + "start_line": 90, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_behaved", + "long_name": "get_behaved( self )", + "filename": "_internal.py", + "nloc": 4, + "complexity": 2, + "token_count": 27, + "parameters": [ + "self" + ], + "start_line": 95, + "end_line": 98, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_carray", + "long_name": "get_carray( self )", + "filename": "_internal.py", + "nloc": 5, + "complexity": 3, + "token_count": 36, + "parameters": [ + "self" + ], + "start_line": 100, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "get_farray", + "long_name": "get_farray( self )", + "filename": "_internal.py", + "nloc": 6, + "complexity": 4, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 106, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_contiguous", + "long_name": "get_contiguous( self )", + "filename": "_internal.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 113, + "end_line": 114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_fortran", + "long_name": "get_fortran( self )", + "filename": "_internal.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 116, + "end_line": 117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_updateifcopy", + "long_name": "get_updateifcopy( self )", + "filename": "_internal.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 119, + "end_line": 120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_owndata", + "long_name": "get_owndata( self )", + "filename": "_internal.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 122, + "end_line": 123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_aligned", + "long_name": "get_aligned( self )", + "filename": "_internal.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 125, + "end_line": 126, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_writeable", + "long_name": "get_writeable( self )", + "filename": "_internal.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 128, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "set_writeable", + "long_name": "set_writeable( self , val )", + "filename": "_internal.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "val" + ], + "start_line": 131, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "set_aligned", + "long_name": "set_aligned( self , val )", + "filename": "_internal.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "val" + ], + "start_line": 135, + "end_line": 137, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "set_updateifcopy", + "long_name": "set_updateifcopy( self , val )", + "filename": "_internal.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "val" + ], + "start_line": 139, + "end_line": 141, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_usefields", + "long_name": "_usefields( adict , align )", + "filename": "_internal.py", + "nloc": 47, + "complexity": 17, + "token_count": 331, + "parameters": [ + "adict", + "align" + ], + "start_line": 170, + "end_line": 218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 49, + "top_nesting_level": 0 + }, + { + "name": "_array_descr", + "long_name": "_array_descr( descriptor )", + "filename": "_internal.py", + "nloc": 22, + "complexity": 7, + "token_count": 175, + "parameters": [ + "descriptor" + ], + "start_line": 227, + "end_line": 250, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_reconstruct", + "long_name": "_reconstruct( subtype , shape , dtype )", + "filename": "_internal.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "subtype", + "shape", + "dtype" + ], + "start_line": 252, + "end_line": 253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_split", + "long_name": "_split( input )", + "filename": "_internal.py", + "nloc": 20, + "complexity": 6, + "token_count": 99, + "parameters": [ + "input" + ], + "start_line": 258, + "end_line": 290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_commastring", + "long_name": "_commastring( astr )", + "filename": "_internal.py", + "nloc": 16, + "complexity": 5, + "token_count": 101, + "parameters": [ + "astr" + ], + "start_line": 296, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "__setitem__", + "long_name": "__setitem__( self , item , val )", + "filename": "_internal.py", + "nloc": 12, + "complexity": 5, + "token_count": 82, + "parameters": [ + "self", + "item", + "val" + ], + "start_line": 68, + "end_line": 82, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "get_aligned", + "long_name": "get_aligned( self )", + "filename": "_internal.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 125, + "end_line": 126, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "set_updateifcopy", + "long_name": "set_updateifcopy( self , val )", + "filename": "_internal.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "val" + ], + "start_line": 139, + "end_line": 141, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_writeable", + "long_name": "get_writeable( self )", + "filename": "_internal.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 128, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_forc", + "long_name": "get_forc( self )", + "filename": "_internal.py", + "nloc": 4, + "complexity": 2, + "token_count": 27, + "parameters": [ + "self" + ], + "start_line": 90, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_farray", + "long_name": "get_farray( self )", + "filename": "_internal.py", + "nloc": 6, + "complexity": 4, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 106, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_owndata", + "long_name": "get_owndata( self )", + "filename": "_internal.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 122, + "end_line": 123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "set_aligned", + "long_name": "set_aligned( self , val )", + "filename": "_internal.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "val" + ], + "start_line": 135, + "end_line": 137, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , arr , flags , scalar )", + "filename": "_internal.py", + "nloc": 7, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self", + "arr", + "flags", + "scalar" + ], + "start_line": 28, + "end_line": 34, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "get_behaved", + "long_name": "get_behaved( self )", + "filename": "_internal.py", + "nloc": 4, + "complexity": 2, + "token_count": 27, + "parameters": [ + "self" + ], + "start_line": 95, + "end_line": 98, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_fnc", + "long_name": "get_fnc( self )", + "filename": "_internal.py", + "nloc": 4, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 85, + "end_line": 88, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_carray", + "long_name": "get_carray( self )", + "filename": "_internal.py", + "nloc": 5, + "complexity": 3, + "token_count": 36, + "parameters": [ + "self" + ], + "start_line": 100, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "get_updateifcopy", + "long_name": "get_updateifcopy( self )", + "filename": "_internal.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 119, + "end_line": 120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "set_writeable", + "long_name": "set_writeable( self , val )", + "filename": "_internal.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "val" + ], + "start_line": 131, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_contiguous", + "long_name": "get_contiguous( self )", + "filename": "_internal.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 113, + "end_line": 114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_fortran", + "long_name": "get_fortran( self )", + "filename": "_internal.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 116, + "end_line": 117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , key )", + "filename": "_internal.py", + "nloc": 31, + "complexity": 14, + "token_count": 230, + "parameters": [ + "self", + "key" + ], + "start_line": 36, + "end_line": 66, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + } + ], + "nloc": 110, + "complexity": 36, + "token_count": 748, + "diff_parsed": { + "added": [ + "from multiarray import dtype, ndarray" + ], + "deleted": [ + "from multiarray import _flagdict, dtype, ndarray", + "", + "_defflags = _flagdict.keys()", + "", + "_setable = ['WRITEABLE','UPDATEIFCOPY', 'ALIGNED',", + " 'W','U','A']", + "_setable2 = ['write','uic','align']*2", + "_firstltr = {'W':'WRITEABLE',", + " 'A':'ALIGNED',", + " 'C':'CONTIGUOUS',", + " 'F':'FORTRAN',", + " 'O':'OWNDATA',", + " 'U':'UPDATEIFCOPY'}", + "", + "_anum = _flagdict['ALIGNED']", + "_wnum = _flagdict['WRITEABLE']", + "_cnum = _flagdict['CONTIGUOUS']", + "_fnum = _flagdict['FORTRAN']", + "_unum = _flagdict['UPDATEIFCOPY']", + "_onum = _flagdict['OWNDATA']", + "", + "class flagsobj(dict):", + " def __init__(self, arr, flags, scalar):", + " self._arr = arr", + " self._flagnum = flags", + " for k in _defflags:", + " num = _flagdict[k]", + " dict.__setitem__(self, k, flags & num == num)", + " self.scalar = scalar", + "", + " def __getitem__(self, key):", + " if not isinstance(key, str):", + " raise KeyError, \"Unknown flag %s\" % key", + " if len(key) == 1:", + " try:", + " return dict.__getitem__(self, _firstltr[key])", + " except:", + " if (key == 'B'):", + " num = _anum + _wnum", + " return self._flagnum & num == num", + " else:", + " try:", + " return dict.__getitem__(self, key)", + " except: # special cases", + " if (key == 'FNC'):", + " return (self._flagnum & _fnum == _fnum) and not \\", + " (self._flagnum & _cnum == _cnum)", + " if (key == 'FORC'):", + " return (self._flagnum & _fnum == _fnum) or \\", + " (self._flagnum & _cnum == _cnum)", + " if (key == 'BEHAVED'):", + " num = _anum + _wnum", + " return self._flagnum & num == num", + " if (key in ['CARRAY','CA']):", + " num = _anum + _wnum + _cnum", + " return self._flagnum & num == num", + " if (key in ['FARRAY','FA']):", + " num = _anum + _wnum + _fnum", + " return (self._flagnum & num == num) and not \\", + " (self._flagnum & _cnum == _cnum)", + " raise KeyError, \"Unknown flag: %s\" % key", + "", + " def __setitem__(self, item, val):", + " if self.scalar:", + " raise ValueError, \"Cannot set flags on array scalars.\"", + " val = not not val # convert to boolean", + " if item not in _setable:", + " raise KeyError, \"Cannot set flag\", item", + " dict.__setitem__(self, item, val) # Does this matter?", + "", + " kwds = {}", + " for k, name in enumerate(_setable):", + " if item == name:", + " kwds[_setable2[k]] = val", + "", + " # now actually update array flags", + " self._arr.setflags(**kwds)", + "", + "", + " def get_fnc(self):", + " fl = self._flagnum", + " return (fl & _fnum == _fnum) and \\", + " not (fl & _cnum == _cnum)", + "", + " def get_forc(self):", + " fl = self._flagnum", + " return (fl & _cnum == _cnum) or \\", + " (fl & _fnum == _fnum)", + "", + " def get_behaved(self):", + " fl = self._flagnum", + " return (fl & _anum == _anum) and \\", + " (fl & _wnum == _wnum)", + "", + " def get_carray(self):", + " fl = self._flagnum", + " return (fl & _anum == _anum) and \\", + " (fl & _wnum == _wnum) and \\", + " (fl & _cnum == _cnum)", + "", + " def get_farray(self):", + " fl = self._flagnum", + " return (fl & _anum == _anum) and \\", + " (fl & _wnum == _wnum) and \\", + " (fl & _fnum == _fnum) and \\", + " not (fl & _cnum == _cnum)", + "", + " def get_contiguous(self):", + " return (self._flagnum & _cnum == _cnum)", + "", + " def get_fortran(self):", + " return (self._flagnum & _fnum == _fnum)", + "", + " def get_updateifcopy(self):", + " return (self._flagnum & _unum == _unum)", + "", + " def get_owndata(self):", + " return (self._flagnum & _onum == _onum)", + "", + " def get_aligned(self):", + " return (self._flagnum & _anum == _anum)", + "", + " def get_writeable(self):", + " return (self._flagnum & _wnum == _wnum)", + "", + " def set_writeable(self, val):", + " val = not not val", + " self._arr.setflags(write=val)", + "", + " def set_aligned(self, val):", + " val = not not val", + " self._arr.setflags(align=val)", + "", + " def set_updateifcopy(self, val):", + " val = not not val", + " self._arr.setflags(uic=val)", + "", + " contiguous = property(get_contiguous, None, \"\")", + " fortran = property(get_fortran, None, \"\")", + " updateifcopy = property(get_updateifcopy, set_updateifcopy, \"\")", + " owndata = property(get_owndata, None, \"\")", + " aligned = property(get_aligned, set_aligned, \"\")", + " writeable = property(get_writeable, set_writeable, \"\")", + "", + " fnc = property(get_fnc, None, \"\")", + " forc = property(get_forc, None, \"\")", + " behaved = property(get_behaved, None, \"\")", + " carray = property(get_carray, None, \"\")", + " farray = property(get_farray, None, \"\")", + "" + ] + } + }, + { + "old_path": "numpy/core/code_generators/array_api_order.txt", + "new_path": "numpy/core/code_generators/array_api_order.txt", + "filename": "array_api_order.txt", + "extension": "txt", + "change_type": "MODIFY", + "diff": "@@ -66,4 +66,5 @@ PyArray_FromInterface\n PyArray_FromStructInterface\n PyArray_FromArrayAttr\n PyArray_ScalarKind\n-PyArray_CanCoerceScalar\n\\ No newline at end of file\n+PyArray_CanCoerceScalar\n+PyArray_NewFlagsObject\n", + "added_lines": 2, + "deleted_lines": 1, + "source_code": "# The functions in the numpy_core C API\n# They are defined here so that the order is set.\nPyArray_SetNumericOps\nPyArray_GetNumericOps\nPyArray_INCREF\nPyArray_XDECREF\nPyArray_SetStringFunction\nPyArray_DescrFromType\nPyArray_TypeObjectFromType\nPyArray_Zero\nPyArray_One\nPyArray_CastToType\nPyArray_CastTo\nPyArray_CanCastSafely\nPyArray_CanCastTo\nPyArray_ObjectType\nPyArray_DescrFromObject\nPyArray_ConvertToCommonType\nPyArray_DescrFromScalar\nPyArray_Size\nPyArray_Scalar\nPyArray_ToScalar\nPyArray_FromScalar\nPyArray_ScalarAsCtype\nPyArray_CastScalarToCtype\nPyArray_RegisterDataType\nPyArray_RegisterDescrForType\nPyArray_FromDims\nPyArray_FromDimsAndDataAndDescr\nPyArray_FromAny\nPyArray_EnsureArray\nPyArray_FromFile\nPyArray_FromString\nPyArray_FromBuffer\nPyArray_Return\nPyArray_GetField\nPyArray_SetField\nPyArray_Byteswap\nPyArray_Resize\nPyArray_NewCopy\nPyArray_CopyInto\nPyArray_ToList\nPyArray_ToFile\nPyArray_Dump\nPyArray_Dumps\nPyArray_ValidType\nPyArray_UpdateFlags\nPyArray_New\nPyArray_NewFromDescr\nPyArray_DescrNew\nPyArray_DescrNewFromType\nPyArray_GetPriority\nPyArray_IterNew\nPyArray_MultiIterNew\nPyArray_PyIntAsInt\nPyArray_PyIntAsIntp\nPyArray_Broadcast\nPyArray_FillObjectArray\nPyArray_FillWithScalar\nPyArray_CheckStrides\nPyArray_DescrNewByteorder\nPyArray_IterAllButAxis\nPyArray_CheckFromAny\nPyArray_FromArray\nPyArray_FromInterface\nPyArray_FromStructInterface\nPyArray_FromArrayAttr\nPyArray_ScalarKind\nPyArray_CanCoerceScalar\nPyArray_NewFlagsObject\n", + "source_code_before": "# The functions in the numpy_core C API\n# They are defined here so that the order is set.\nPyArray_SetNumericOps\nPyArray_GetNumericOps\nPyArray_INCREF\nPyArray_XDECREF\nPyArray_SetStringFunction\nPyArray_DescrFromType\nPyArray_TypeObjectFromType\nPyArray_Zero\nPyArray_One\nPyArray_CastToType\nPyArray_CastTo\nPyArray_CanCastSafely\nPyArray_CanCastTo\nPyArray_ObjectType\nPyArray_DescrFromObject\nPyArray_ConvertToCommonType\nPyArray_DescrFromScalar\nPyArray_Size\nPyArray_Scalar\nPyArray_ToScalar\nPyArray_FromScalar\nPyArray_ScalarAsCtype\nPyArray_CastScalarToCtype\nPyArray_RegisterDataType\nPyArray_RegisterDescrForType\nPyArray_FromDims\nPyArray_FromDimsAndDataAndDescr\nPyArray_FromAny\nPyArray_EnsureArray\nPyArray_FromFile\nPyArray_FromString\nPyArray_FromBuffer\nPyArray_Return\nPyArray_GetField\nPyArray_SetField\nPyArray_Byteswap\nPyArray_Resize\nPyArray_NewCopy\nPyArray_CopyInto\nPyArray_ToList\nPyArray_ToFile\nPyArray_Dump\nPyArray_Dumps\nPyArray_ValidType\nPyArray_UpdateFlags\nPyArray_New\nPyArray_NewFromDescr\nPyArray_DescrNew\nPyArray_DescrNewFromType\nPyArray_GetPriority\nPyArray_IterNew\nPyArray_MultiIterNew\nPyArray_PyIntAsInt\nPyArray_PyIntAsIntp\nPyArray_Broadcast\nPyArray_FillObjectArray\nPyArray_FillWithScalar\nPyArray_CheckStrides\nPyArray_DescrNewByteorder\nPyArray_IterAllButAxis\nPyArray_CheckFromAny\nPyArray_FromArray\nPyArray_FromInterface\nPyArray_FromStructInterface\nPyArray_FromArrayAttr\nPyArray_ScalarKind\nPyArray_CanCoerceScalar", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "PyArray_CanCoerceScalar", + "PyArray_NewFlagsObject" + ], + "deleted": [ + "PyArray_CanCoerceScalar" + ] + } + }, + { + "old_path": "numpy/core/code_generators/generate_array_api.py", + "new_path": "numpy/core/code_generators/generate_array_api.py", + "filename": "generate_array_api.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -15,6 +15,7 @@\n static PyTypeObject PyBigArray_Type;\n static PyTypeObject PyArray_Type;\n static PyTypeObject PyArrayDescr_Type;\n+static PyTypeObject PyArrayFlags_Type;\n static PyTypeObject PyArrayIter_Type;\n static PyTypeObject PyArrayMapIter_Type;\n static PyTypeObject PyArrayMultiIter_Type;\n@@ -41,9 +42,10 @@\n #define PyBigArray_Type (*(PyTypeObject *)PyArray_API[0])\n #define PyArray_Type (*(PyTypeObject *)PyArray_API[1])\n #define PyArrayDescr_Type (*(PyTypeObject *)PyArray_API[2])\n-#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[3])\n-#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[4])\n-#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[5])\n+#define PyArrayFlags_Type (*(PyTypeObject *)PyArray_API[3])\n+#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[4])\n+#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[5])\n+#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[6])\n \n %s\n \n@@ -86,6 +88,7 @@\n (void *) &PyBigArray_Type,\n (void *) &PyArray_Type,\n (void *) &PyArrayDescr_Type,\n+ (void *) &PyArrayFlags_Type,\n (void *) &PyArrayIter_Type,\n (void *) &PyArrayMultiIter_Type,\n (int *) &PyArray_NUMUSERTYPES,\n@@ -100,7 +103,7 @@ def generate_api(output_dir):\n 'multiarray_api_order.txt')\n # API fixes for __arrayobject_api.h\n \n- fixed = 6\n+ fixed = 7\n numtypes = len(types) + fixed\n numobject = len(objectapi_list) + numtypes\n nummulti = len(multiapi_list)\n", + "added_lines": 7, + "deleted_lines": 4, + "source_code": "import os\nimport genapi\n\ntypes = ['Generic','Number','Integer','SignedInteger','UnsignedInteger',\n '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\nh_template = r\"\"\"\n#ifdef _MULTIARRAYMODULE\n\nstatic PyTypeObject PyBigArray_Type;\nstatic PyTypeObject PyArray_Type;\nstatic PyTypeObject PyArrayDescr_Type;\nstatic PyTypeObject PyArrayFlags_Type;\nstatic PyTypeObject PyArrayIter_Type;\nstatic PyTypeObject PyArrayMapIter_Type;\nstatic PyTypeObject PyArrayMultiIter_Type;\nstatic int PyArray_NUMUSERTYPES=0;\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 PyArrayDescr_Type (*(PyTypeObject *)PyArray_API[2])\n#define PyArrayFlags_Type (*(PyTypeObject *)PyArray_API[3])\n#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[4])\n#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[5])\n#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[6])\n\n%s\n\n#if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)\nstatic int\nimport_array(void)\n{\n PyObject *numpy = PyImport_ImportModule(\"numpy.core.multiarray\");\n PyObject *c_api = NULL;\n if (numpy == NULL) return -1;\n c_api = PyObject_GetAttrString(numpy, \"_ARRAY_API\");\n if (c_api == NULL) {Py_DECREF(numpy); return -1;}\n if (PyCObject_Check(c_api)) {\n PyArray_API = (void **)PyCObject_AsVoidPtr(c_api);\n }\n Py_DECREF(c_api);\n Py_DECREF(numpy);\n if (PyArray_API == NULL) return -1;\n /* Perform runtime check of C API version */\n if (NDARRAY_VERSION != PyArray_GetNDArrayCVersion()) {\n PyErr_Format(PyExc_RuntimeError, \"module compiled against \"\\\n \"version %%x of C-API but this version of numpy is %%x\", \\\n (int) NDARRAY_VERSION, (int) PyArray_GetNDArrayCVersion());\n return -1;\n }\n return 0;\n}\n#endif\n\n#endif\n\"\"\"\n\n\nc_template = r\"\"\"\n/* These pointers will be stored in the C-object for use in other\n extension modules\n*/\n\nvoid *PyArray_API[] = {\n (void *) &PyBigArray_Type,\n (void *) &PyArray_Type,\n (void *) &PyArrayDescr_Type,\n (void *) &PyArrayFlags_Type,\n (void *) &PyArrayIter_Type,\n (void *) &PyArrayMultiIter_Type,\n (int *) &PyArray_NUMUSERTYPES,\n%s\n};\n\"\"\"\n\ndef generate_api(output_dir):\n objectapi_list = genapi.get_api_functions('OBJECT_API',\n 'array_api_order.txt')\n multiapi_list = genapi.get_api_functions('MULTIARRAY_API',\n 'multiarray_api_order.txt')\n # API fixes for __arrayobject_api.h\n\n fixed = 7\n numtypes = len(types) + fixed\n numobject = len(objectapi_list) + numtypes\n nummulti = len(multiapi_list)\n numtotal = numobject + nummulti\n\n module_list = []\n extension_list = []\n init_list = []\n\n # setup types\n for k, atype in enumerate(types):\n num = fixed + k\n astr = \" (void *) &Py%sArrType_Type,\" % types[k]\n init_list.append(astr)\n astr = \"static PyTypeObject Py%sArrType_Type;\" % types[k]\n module_list.append(astr)\n astr = \"#define Py%sArrType_Type (*(PyTypeObject *)PyArray_API[%d])\" % \\\n (types[k], num)\n extension_list.append(astr)\n\n #setup object API\n genapi.add_api_list(numtypes, 'PyArray_API', objectapi_list,\n module_list, extension_list, init_list)\n\n # setup multiarray module API\n genapi.add_api_list(numobject, 'PyArray_API', multiapi_list,\n module_list, extension_list, init_list)\n\n\n # Write to header\n fid = open(os.path.join(output_dir, '__multiarray_api.h'),'w')\n s = h_template % ('\\n'.join(module_list), '\\n'.join(extension_list))\n fid.write(s)\n fid.close()\n\n # Write to c-code\n fid = open(os.path.join(output_dir,'__multiarray_api.c'),'w')\n s = c_template % '\\n'.join(init_list)\n fid.write(s)\n fid.close()\n", + "source_code_before": "import os\nimport genapi\n\ntypes = ['Generic','Number','Integer','SignedInteger','UnsignedInteger',\n 'Inexact',\n 'Floating', 'ComplexFloating', 'Flexible', 'Character',\n '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\nh_template = r\"\"\"\n#ifdef _MULTIARRAYMODULE\n\nstatic PyTypeObject PyBigArray_Type;\nstatic PyTypeObject PyArray_Type;\nstatic PyTypeObject PyArrayDescr_Type;\nstatic PyTypeObject PyArrayIter_Type;\nstatic PyTypeObject PyArrayMapIter_Type;\nstatic PyTypeObject PyArrayMultiIter_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 PyArrayDescr_Type (*(PyTypeObject *)PyArray_API[2])\n#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[3])\n#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[4])\n#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[5])\n\n%s\n\n#if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)\nstatic int\nimport_array(void)\n{\n PyObject *numpy = PyImport_ImportModule(\"numpy.core.multiarray\");\n PyObject *c_api = NULL;\n if (numpy == NULL) return -1;\n c_api = PyObject_GetAttrString(numpy, \"_ARRAY_API\");\n if (c_api == NULL) {Py_DECREF(numpy); return -1;}\n if (PyCObject_Check(c_api)) {\n PyArray_API = (void **)PyCObject_AsVoidPtr(c_api);\n }\n Py_DECREF(c_api);\n Py_DECREF(numpy);\n if (PyArray_API == NULL) return -1;\n /* Perform runtime check of C API version */\n if (NDARRAY_VERSION != PyArray_GetNDArrayCVersion()) {\n PyErr_Format(PyExc_RuntimeError, \"module compiled against \"\\\n \"version %%x of C-API but this version of numpy is %%x\", \\\n (int) NDARRAY_VERSION, (int) PyArray_GetNDArrayCVersion());\n return -1;\n }\n return 0;\n}\n#endif\n\n#endif\n\"\"\"\n\n\nc_template = r\"\"\"\n/* These pointers will be stored in the C-object for use in other\n extension modules\n*/\n\nvoid *PyArray_API[] = {\n (void *) &PyBigArray_Type,\n (void *) &PyArray_Type,\n (void *) &PyArrayDescr_Type,\n (void *) &PyArrayIter_Type,\n (void *) &PyArrayMultiIter_Type,\n (int *) &PyArray_NUMUSERTYPES,\n%s\n};\n\"\"\"\n\ndef generate_api(output_dir):\n objectapi_list = genapi.get_api_functions('OBJECT_API',\n 'array_api_order.txt')\n multiapi_list = genapi.get_api_functions('MULTIARRAY_API',\n 'multiarray_api_order.txt')\n # API fixes for __arrayobject_api.h\n\n fixed = 6\n numtypes = len(types) + fixed\n numobject = len(objectapi_list) + numtypes\n nummulti = len(multiapi_list)\n numtotal = numobject + nummulti\n\n module_list = []\n extension_list = []\n init_list = []\n\n # setup types\n for k, atype in enumerate(types):\n num = fixed + k\n astr = \" (void *) &Py%sArrType_Type,\" % types[k]\n init_list.append(astr)\n astr = \"static PyTypeObject Py%sArrType_Type;\" % types[k]\n module_list.append(astr)\n astr = \"#define Py%sArrType_Type (*(PyTypeObject *)PyArray_API[%d])\" % \\\n (types[k], num)\n extension_list.append(astr)\n\n #setup object API\n genapi.add_api_list(numtypes, 'PyArray_API', objectapi_list,\n module_list, extension_list, init_list)\n\n # setup multiarray module API\n genapi.add_api_list(numobject, 'PyArray_API', multiapi_list,\n module_list, extension_list, init_list)\n\n\n # Write to header\n fid = open(os.path.join(output_dir, '__multiarray_api.h'),'w')\n s = h_template % ('\\n'.join(module_list), '\\n'.join(extension_list))\n fid.write(s)\n fid.close()\n\n # Write to c-code\n fid = open(os.path.join(output_dir,'__multiarray_api.c'),'w')\n s = c_template % '\\n'.join(init_list)\n fid.write(s)\n fid.close()\n", + "methods": [ + { + "name": "generate_api", + "long_name": "generate_api( output_dir )", + "filename": "generate_array_api.py", + "nloc": 34, + "complexity": 2, + "token_count": 246, + "parameters": [ + "output_dir" + ], + "start_line": 99, + "end_line": 146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "generate_api", + "long_name": "generate_api( output_dir )", + "filename": "generate_array_api.py", + "nloc": 34, + "complexity": 2, + "token_count": 246, + "parameters": [ + "output_dir" + ], + "start_line": 96, + "end_line": 143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "generate_api", + "long_name": "generate_api( output_dir )", + "filename": "generate_array_api.py", + "nloc": 34, + "complexity": 2, + "token_count": 246, + "parameters": [ + "output_dir" + ], + "start_line": 99, + "end_line": 146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + } + ], + "nloc": 127, + "complexity": 2, + "token_count": 324, + "diff_parsed": { + "added": [ + "static PyTypeObject PyArrayFlags_Type;", + "#define PyArrayFlags_Type (*(PyTypeObject *)PyArray_API[3])", + "#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[4])", + "#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[5])", + "#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[6])", + " (void *) &PyArrayFlags_Type,", + " fixed = 7" + ], + "deleted": [ + "#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[3])", + "#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[4])", + "#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[5])", + " fixed = 6" + ] + } + }, + { + "old_path": "numpy/core/include/numpy/arrayobject.h", + "new_path": "numpy/core/include/numpy/arrayobject.h", + "filename": "arrayobject.h", + "extension": "h", + "change_type": "MODIFY", + "diff": "@@ -79,7 +79,7 @@ extern \"C\" CONFUSE_EMACS\n #define PY_SUCCEED 1\n \n /* Helpful to distinguish what is installed */\n-#define NDARRAY_VERSION 0x00090504\n+#define NDARRAY_VERSION 0x00090701\n \n \t/* Some platforms don't define bool, long long, or long double.\n \t Handle that here.\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "\n/* This expects the following variables to be defined (besides\n the usual ones from pyconfig.h\n\n SIZEOF_LONG_DOUBLE -- sizeof(long double) or sizeof(double) if no\n long double is present on platform.\n CHAR_BIT -- number of bits in a char (usually 8)\n (should be in limits.h)\n*/\n\n#ifndef Py_ARRAYOBJECT_H\n#define Py_ARRAYOBJECT_H\n#ifdef __cplusplus\n#define CONFUSE_EMACS {\n#define CONFUSE_EMACS2 }\nextern \"C\" CONFUSE_EMACS\n#undef CONFUSE_EMACS\n#undef CONFUSE_EMACS2\n/* ... otherwise a semi-smart idententer (like emacs) tries to indent\n everything when you're typing */\n#endif\n#include \"config.h\"\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# define CAT2(x,y) x ## y\n# define CAT(x,y) CAT2(x,y)\n# define NS(name) CAT(PY_ARRAY_TYPES_PREFIX, name)\n# define longlong NS(longlong)\n# define ulonglong NS(ulonglong)\n# define Bool NS(Bool)\n# define longdouble NS(longdouble)\n# define byte NS(byte)\n# define ubyte NS(ubyte)\n# define ushort NS(ushort)\n# define uint NS(uint)\n# define ulong NS(ulong)\n# define cfloat NS(cfloat)\n# define cdouble NS(cdouble)\n# define clongdouble NS(clongdouble)\n# define Int8 NS(Int8)\n# define UInt8 NS(UInt8)\n# define Int16 NS(Int16)\n# define UInt16 NS(UInt16)\n# define Int32 NS(Int32)\n# define UInt32 NS(UInt32)\n# define Int64 NS(Int64)\n# define UInt64 NS(UInt64)\n# define Int128 NS(Int128)\n# define UInt128 NS(UInt128)\n# define Int256 NS(Int256)\n# define UInt256 NS(UInt256)\n# define Float16 NS(Float16)\n# define Complex32 NS(Complex32)\n# define Float32 NS(Float32)\n# define Complex64 NS(Complex64)\n# define Float64 NS(Float64)\n# define Complex128 NS(Complex128)\n# define Float80 NS(Float80)\n# define Complex160 NS(Complex160)\n# define Float96 NS(Float96)\n# define Complex192 NS(Complex192)\n# define Float128 NS(Float128)\n# define Complex256 NS(Complex256)\n# define intp NS(intp)\n# define uintp NS(uintp)\n#endif\n\n/* There are several places in the code where an array of dimensions is */\n/* allocated statically. This is the size of that static allocation. */\n/* The array creation itself could have arbitrary dimensions but\n * all the places where static allocation is used would need to\n * be changed to dynamic (including inside of structures)\n */\n\n#define MAX_DIMS 32\n\n/* Used for Converter Functions \"O&\" code in ParseTuple */\n#define PY_FAIL 0\n#define PY_SUCCEED 1\n\n /* Helpful to distinguish what is installed */\n#define NDARRAY_VERSION 0x00090701\n\n\t/* Some platforms don't define bool, long long, or long double.\n\t Handle that here.\n\t */\n\n#ifdef PY_LONG_LONG\ntypedef PY_LONG_LONG longlong;\ntypedef unsigned PY_LONG_LONG ulonglong;\n# ifdef _MSC_VER\n# define LONGLONG_FMT \"I64d\"\n# define ULONGLONG_FMT \"I64u\"\n# define LONGLONG_SUFFIX(x) (x##i64)\n# define ULONGLONG_SUFFIX(x) (x##Ui64)\n# else\n\t/* #define LONGLONG_FMT \"lld\" Another possible variant\n #define ULONGLONG_FMT \"llu\"\n\n\t #define LONGLONG_FMT \"qd\" -- BSD perhaps?\n\t #define ULONGLONG_FMT \"qu\"\n\t*/\n# define LONGLONG_FMT \"Ld\"\n# define ULONGLONG_FMT \"Lu\"\n# define LONGLONG_SUFFIX(x) (x##LL)\n# define ULONGLONG_SUFFIX(x) (x##ULL)\n# endif\n#else\ntypedef long longlong;\ntypedef unsigned long ulonglong;\n# define LONGLONG_SUFFIX(x) (x##L)\n# define ULONGLONG_SUFFIX(x) (x##UL)\n#endif\n\ntypedef unsigned char Bool;\n#ifndef FALSE\n#define FALSE 0\n#endif\n#ifndef TRUE\n#define TRUE 1\n#endif\n\n#if SIZEOF_LONG_DOUBLE==SIZEOF_DOUBLE\n\ttypedef double longdouble;\n #define LONGDOUBLE_FMT \"g\"\n#else\n\ttypedef long double longdouble;\n #define LONGDOUBLE_FMT \"Lg\"\n#endif\n\n#ifndef Py_USING_UNICODE\n#error Must use Python with unicode enabled. \n#endif\n\n\ntypedef signed char byte;\ntypedef unsigned char ubyte;\n#ifndef _BSD_SOURCE\ntypedef unsigned short ushort;\ntypedef unsigned int uint;\ntypedef unsigned long ulong;\n#endif\n\ntypedef struct { float real, imag; } cfloat;\ntypedef struct { double real, imag; } cdouble;\ntypedef struct {longdouble real, imag;} clongdouble;\n\nenum PyArray_TYPES { PyArray_BOOL=0,\n PyArray_BYTE, PyArray_UBYTE,\n\t\t PyArray_SHORT, PyArray_USHORT,\n\t\t PyArray_INT, PyArray_UINT,\n\t\t\tPyArray_LONG, PyArray_ULONG,\n PyArray_LONGLONG, PyArray_ULONGLONG,\n\t\t\tPyArray_FLOAT, PyArray_DOUBLE, PyArray_LONGDOUBLE,\n\t\t\tPyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CLONGDOUBLE,\n\t\t\tPyArray_OBJECT=17,\n PyArray_STRING, PyArray_UNICODE,\n\t\t\tPyArray_VOID,\n\t\t\tPyArray_NTYPES,\n\t\t\tPyArray_NOTYPE,\n\t\t\tPyArray_USERDEF=256 /* leave room for characters */\n};\n\n\t/* basetype array priority */\n#define PyArray_PRIORITY 0.0\n#define PyArray_BIG_PRIORITY 0.1\n\t/* default subtype priority */\n#define PyArray_SUBTYPE_PRIORITY 1.0\n\n\t/* How many floating point types are there */\n#define PyArray_NUM_FLOATTYPE 3\n\n\n\t/* We need to match intp to a signed integer of the same size as\n\t a pointer variable. uintp to the equivalent unsigned integer\n\t*/\n\n\n\t/* These characters correspond to the array type and the\n\t struct module */\n\n\t/* except 'p' -- signed integer for pointer type */\n\nenum PyArray_TYPECHAR { PyArray_BOOLLTR = '?',\n\t\t\tPyArray_BYTELTR = 'b',\n\t\t\tPyArray_UBYTELTR = 'B',\n\t\t\tPyArray_SHORTLTR = 'h',\n\t\t\tPyArray_USHORTLTR = 'H',\n\t\t\tPyArray_INTLTR = 'i',\n\t\t\tPyArray_UINTLTR = 'I',\n\t\t\tPyArray_LONGLTR = 'l',\n\t\t\tPyArray_ULONGLTR = 'L',\n\t\t\tPyArray_LONGLONGLTR = 'q',\n\t\t\tPyArray_ULONGLONGLTR = 'Q',\n\t\t\tPyArray_FLOATLTR = 'f',\n\t\t\tPyArray_DOUBLELTR = 'd',\n\t\t\tPyArray_LONGDOUBLELTR = 'g',\n\t\t\tPyArray_CFLOATLTR = 'F',\n\t\t\tPyArray_CDOUBLELTR = 'D',\n\t\t\tPyArray_CLONGDOUBLELTR = 'G',\n\t\t\tPyArray_OBJECTLTR = 'O',\n\t\t\tPyArray_STRINGLTR = 'S',\n\t\t\tPyArray_STRINGLTR2 = 'a',\n\t\t\tPyArray_UNICODELTR = 'U',\n\t\t PyArray_VOIDLTR = 'V',\n\n\t\t\t/* No Descriptor, just a define -- this let's\n\t\t\t Python users specify an array of integers\n\t\t\t large enough to hold a pointer on the platform*/\n\t\t\tPyArray_INTPLTR = 'p',\n\t\t\tPyArray_UINTPLTR = 'P',\n\n\t\t\tPyArray_GENBOOLLTR ='b',\n\t\t\tPyArray_SIGNEDLTR = 'i',\n\t\t\tPyArray_UNSIGNEDLTR = 'u',\n\t\t\tPyArray_FLOATINGLTR = 'f',\n\t\t\tPyArray_COMPLEXLTR = 'c'\n};\n\ntypedef enum {\n\tPyArray_QUICKSORT=0,\n\tPyArray_HEAPSORT=1,\n\tPyArray_MERGESORT=2,\n\tPyArray_TIMSORT=3 /* the sort Python uses -- specialized */\n} PyArray_SORTKIND;\n#define PyArray_NSORTS PyArray_TIMSORT + 1\n\n\ntypedef enum {\n\tPyArray_NOSCALAR=0,\n\tPyArray_BOOL_SCALAR=1,\n\tPyArray_INTPOS_SCALAR=2,\n\tPyArray_INTNEG_SCALAR=3,\n\tPyArray_FLOAT_SCALAR=4,\n\tPyArray_COMPLEX_SCALAR=5,\n\tPyArray_OBJECT_SCALAR=6,\n} PyArray_SCALARKIND;\n\n\t/* Define bit-width array types and typedefs */\n\n#define MAX_INT8 127\n#define MIN_INT8 -128\n#define MAX_UINT8 255\n#define MAX_INT16 32767\n#define MIN_INT16 -32768\n#define MAX_UINT16 65535\n#define MAX_INT32 2147483647\n#define MIN_INT32 (-MAX_INT32 - 1)\n#define MAX_UINT32 4294967295U\n#define MAX_INT64 LONGLONG_SUFFIX(9223372036854775807)\n#define MIN_INT64 (-MAX_INT64 - LONGLONG_SUFFIX(1))\n#define MAX_UINT64 ULONGLONG_SUFFIX(18446744073709551615)\n#define MAX_INT128 LONGLONG_SUFFIX(85070591730234615865843651857942052864)\n#define MIN_INT128 (-MAX_INT128 - LONGLONG_SUFFIX(1))\n#define MAX_UINT128 ULONGLONG_SUFFIX(170141183460469231731687303715884105728)\n#define MAX_INT256 LONGLONG_SUFFIX(57896044618658097711785492504343953926634992332820282019728792003956564819967)\n#define MIN_INT256 (-MAX_INT256 - LONGLONG_SUFFIX(1))\n#define MAX_UINT256 ULONGLONG_SUFFIX(115792089237316195423570985008687907853269984665640564039457584007913129639935)\n\n\t/* Need to find the number of bits for each type and\n\t make definitions accordingly.\n\n\t C states that sizeof(char) == 1 by definition\n\n\t So, just using the sizeof keyword won't help.\n\n\t It also looks like Python itself uses sizeof(char) quite a\n\t bit, which by definition should be 1 all the time.\n\n\t Idea: Make Use of CHAR_BIT which should tell us how many\n\t BITS per CHARACTER\n\t*/\n\n\t/* Include platform definitions -- These are in the C89/90 standard */\n#include \n#define MAX_BYTE SCHAR_MAX\n#define MIN_BYTE SCHAR_MIN\n#define MAX_UBYTE UCHAR_MAX\n#define MAX_SHORT SHRT_MAX\n#define MIN_SHORT SHRT_MIN\n#define MAX_USHORT USHRT_MAX\n#define MAX_INT INT_MAX\n#ifndef INT_MIN\n#define INT_MIN (-INT_MAX - 1)\n#endif\n#define MIN_INT INT_MIN\n#define MAX_UINT UINT_MAX\n#define MAX_LONG LONG_MAX\n#define MIN_LONG LONG_MIN\n#define MAX_ULONG ULONG_MAX\n\n#define SIZEOF_LONGDOUBLE SIZEOF_LONG_DOUBLE\n#define SIZEOF_LONGLONG SIZEOF_LONG_LONG\n#define BITSOF_BOOL sizeof(Bool)*CHAR_BIT\n#define BITSOF_CHAR CHAR_BIT\n#define BITSOF_SHORT (SIZEOF_SHORT*CHAR_BIT)\n#define BITSOF_INT (SIZEOF_INT*CHAR_BIT)\n#define BITSOF_LONG (SIZEOF_LONG*CHAR_BIT)\n#define BITSOF_LONGLONG (SIZEOF_LONGLONG*CHAR_BIT)\n#define BITSOF_FLOAT (SIZEOF_FLOAT*CHAR_BIT)\n#define BITSOF_DOUBLE (SIZEOF_DOUBLE*CHAR_BIT)\n#define BITSOF_LONGDOUBLE (SIZEOF_LONGDOUBLE*CHAR_BIT)\n\n\n#if BITSOF_LONG == 8\n#define PyArray_INT8 PyArray_LONG\n#define PyArray_UINT8 PyArray_ULONG\n\ttypedef long Int8;\n\ttypedef unsigned long UInt8;\n#define STRBITSOF_LONG \"8\"\n#elif BITSOF_LONG == 16\n#define PyArray_INT16 PyArray_LONG\n#define PyArray_UINT16 PyArray_ULONG\n\ttypedef long Int16;\n\ttypedef unsigned long UInt16;\n#define STRBITSOF_LONG \"16\"\n#elif BITSOF_LONG == 32\n#define PyArray_INT32 PyArray_LONG\n#define PyArray_UINT32 PyArray_ULONG\n\ttypedef long Int32;\n\ttypedef unsigned long UInt32;\n\ttypedef unsigned long PyArray_UCS4;\n#define STRBITSOF_LONG \"32\"\n#elif BITSOF_LONG == 64\n#define PyArray_INT64 PyArray_LONG\n#define PyArray_UINT64 PyArray_ULONG\n\ttypedef long Int64;\n\ttypedef unsigned long UInt64;\n#define STRBITSOF_LONG \"64\"\n#elif BITSOF_LONG == 128\n#define PyArray_INT128 PyArray_LONG\n#define PyArray_UINT128 PyArray_ULONG\n\ttypedef long Int128;\n\ttypedef unsigned long UInt128;\n#define STRBITSOF_LONG \"128\"\n#endif\n\n#if BITSOF_LONGLONG == 8\n# ifndef PyArray_INT8\n# define PyArray_INT8 PyArray_LONGLONG\n# define PyArray_UINT8 PyArray_ULONGLONG\n\ttypedef longlong Int8;\n\ttypedef ulonglong UInt8;\n# endif\n# define MAX_LONGLONG MAX_INT8\n# define MIN_LONGLONG MIN_INT8\n# define MAX_ULONGLONG MAX_UINT8\n#define STRBITSOF_LONGLONG \"8\"\n#elif BITSOF_LONGLONG == 16\n# ifndef PyArray_INT16\n# define PyArray_INT16 PyArray_LONGLONG\n# define PyArray_UINT16 PyArray_ULONGLONG\n\ttypedef longlong Int16;\n\ttypedef ulonglong UInt16;\n# endif\n# define MAX_LONGLONG MAX_INT16\n# define MIN_LONGLONG MIN_INT16\n# define MAX_ULONGLONG MAX_UINT16\n#define STRBITSOF_LONGLONG \"16\"\n#elif BITSOF_LONGLONG == 32\n# ifndef PyArray_INT32\n# define PyArray_INT32 PyArray_LONGLONG\n# define PyArray_UINT32 PyArray_ULONGLONG\n\ttypedef longlong Int32;\n\ttypedef ulonglong UInt32;\n\ttypedef ulonglong PyArray_UCS4;\n# endif\n# define MAX_LONGLONG MAX_INT32\n# define MIN_LONGLONG MIN_INT32\n# define MAX_ULONGLONG MAX_UINT32\n#define STRBITSOF_LONGLONG \"32\"\n#elif BITSOF_LONGLONG == 64\n# ifndef PyArray_INT64\n# define PyArray_INT64 PyArray_LONGLONG\n# define PyArray_UINT64 PyArray_ULONGLONG\n\ttypedef longlong Int64;\n\ttypedef ulonglong UInt64;\n# endif\n# define MAX_LONGLONG MAX_INT64\n# define MIN_LONGLONG MIN_INT64\n# define MAX_ULONGLONG MAX_UINT64\n#define STRBITSOF_LONGLONG \"64\"\n#elif BITSOF_LONGLONG == 128\n# ifndef PyArray_INT128\n# define PyArray_INT128 PyArray_LONGLONG\n# define PyArray_UINT128 PyArray_ULONGLONG\n\ttypedef longlong Int128;\n\ttypedef ulonglong UInt128;\n# endif\n# define MAX_LONGLONG MAX_INT128\n# define MIN_LONGLONG MIN_INT128\n# define MAX_ULONGLONG MAX_UINT128\n#define STRBITSOF_LONGLONG \"128\"\n#elif BITSOF_LONGLONG == 256\n# define PyArray_INT256 PyArray_LONGLONG\n# define PyArray_UINT256 PyArray_ULONGLONG\n\ttypedef longlong Int256;\n\ttypedef ulonglong UInt256;\n# define MAX_LONGLONG MAX_INT256\n# define MIN_LONGLONG MIN_INT256\n# define MAX_ULONGLONG MAX_UINT256\n#define STRBITSOF_LONGLONG \"256\"\n#endif\n\n#if BITSOF_INT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_INT\n#define PyArray_UINT8 PyArray_UINT\n\ttypedef int Int8;\n\ttypedef unsigned int UInt8;\n#endif\n#define STRBITSOF_INT \"8\"\n#elif BITSOF_INT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_INT\n#define PyArray_UINT16 PyArray_UINT\n\ttypedef int Int16;\n\ttypedef unsigned int UInt16;\n#endif\n#define STRBITSOF_INT \"16\"\n#elif BITSOF_INT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_INT\n#define PyArray_UINT32 PyArray_UINT\n\ttypedef int Int32;\n\ttypedef unsigned int UInt32;\n\ttypedef unsigned int PyArray_UCS4;\n#endif\n#define STRBITSOF_INT \"32\"\n#elif BITSOF_INT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_INT\n#define PyArray_UINT64 PyArray_UINT\n\ttypedef int Int64;\n\ttypedef unsigned int UInt64;\n#endif\n#define STRBITSOF_INT \"64\"\n#elif BITSOF_INT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_INT\n#define PyArray_UINT128 PyArray_UINT\n\ttypedef int Int128;\n\ttypedef unsigned int UInt128;\n#endif\n#define STRBITSOF_INT \"128\"\n#endif\n\n#if BITSOF_SHORT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_SHORT\n#define PyArray_UINT8 PyArray_USHORT\n\ttypedef short Int8;\n\ttypedef unsigned short UInt8;\n#endif\n#define STRBITSOF_SHORT \"8\"\n#elif BITSOF_SHORT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_SHORT\n#define PyArray_UINT16 PyArray_USHORT\n\ttypedef short Int16;\n\ttypedef unsigned short UInt16;\n#endif\n#define STRBITSOF_SHORT \"16\"\n#elif BITSOF_SHORT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_SHORT\n#define PyArray_UINT32 PyArray_USHORT\n\ttypedef short Int32;\n\ttypedef unsigned short UInt32;\n\ttypedef unsigned short PyArray_UCS4;\n#endif\n#define STRBITSOF_SHORT \"32\"\n#elif BITSOF_SHORT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_SHORT\n#define PyArray_UINT64 PyArray_USHORT\n\ttypedef short Int64;\n\ttypedef unsigned short UInt64;\n#endif\n#define STRBITSOF_SHORT \"64\"\n#elif BITSOF_SHORT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_SHORT\n#define PyArray_UINT128 PyArray_USHORT\n\ttypedef short Int128;\n\ttypedef unsigned short UInt128;\n#endif\n#define STRBITSOF_SHORT \"128\"\n#endif\n\n\n#if BITSOF_CHAR == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_BYTE\n#define PyArray_UINT8 PyArray_UBYTE\n\ttypedef signed char Int8;\n\ttypedef unsigned char UInt8;\n#endif\n#define STRBITSOF_CHAR \"8\"\n#elif BITSOF_CHAR == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_BYTE\n#define PyArray_UINT16 PyArray_UBYTE\n\ttypedef signed char Int16;\n\ttypedef unsigned char UInt16;\n#endif\n#define STRBITSOF_CHAR \"16\"\n#elif BITSOF_CHAR == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_BYTE\n#define PyArray_UINT32 PyArray_UBYTE\n\ttypedef signed char Int32;\n\ttypedef unsigned char UInt32;\n\ttypedef unsigned char PyArray_UCS4;\n#endif\n#define STRBITSOF_CHAR \"32\"\n#elif BITSOF_CHAR == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_BYTE\n#define PyArray_UINT64 PyArray_UBYTE\n\ttypedef signed char Int64;\n\ttypedef unsigned char UInt64;\n#endif\n#define STRBITSOF_CHAR \"64\"\n#elif BITSOF_CHAR == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_BYTE\n#define PyArray_UINT128 PyArray_UBYTE\n\ttypedef signed char Int128;\n\ttypedef unsigned char UInt128;\n#endif\n#define STRBITSOF_CHAR \"128\"\n#endif\n\n\n\n#if BITSOF_DOUBLE == 16\n#define STRBITSOF_DOUBLE \"16\"\n#define STRBITSOF_CDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_DOUBLE\n#define PyArray_COMPLEX32 PyArray_CDOUBLE\n\ttypedef double Float16;\n\ttypedef cdouble Complex32;\n#endif\n#elif BITSOF_DOUBLE == 32\n#define STRBITSOF_DOUBLE \"32\"\n#define STRBITSOF_CDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_DOUBLE\n#define PyArray_COMPLEX64 PyArray_CDOUBLE\n\ttypedef double Float32;\n\ttypedef cdouble Complex64;\n#endif\n#elif BITSOF_DOUBLE == 64\n#define STRBITSOF_DOUBLE \"64\"\n#define STRBITSOF_CDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_DOUBLE\n#define PyArray_COMPLEX128 PyArray_CDOUBLE\n\ttypedef double Float64;\n\ttypedef cdouble Complex128;\n#endif\n#elif BITSOF_DOUBLE == 80\n#define STRBITSOF_DOUBLE \"80\"\n#define STRBITSOF_CDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_DOUBLE\n#define PyArray_COMPLEX160 PyArray_CDOUBLE\n\ttypedef double Float80;\n\ttypedef cdouble Complex160;\n#endif\n#elif BITSOF_DOUBLE == 96\n#define STRBITSOF_DOUBLE \"96\"\n#define STRBITSOF_CDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_DOUBLE\n#define PyArray_COMPLEX192 PyArray_CDOUBLE\n\ttypedef double Float96;\n\ttypedef cdouble Complex192;\n#endif\n#elif BITSOF_DOUBLE == 128\n#define STRBITSOF_DOUBLE \"128\"\n#define STRBITSOF_CDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_DOUBLE\n#define PyArray_COMPLEX256 PyArray_CDOUBLE\n\ttypedef double Float128;\n\ttypedef cdouble Complex256;\n#endif\n#endif\n\n\n\n#if BITSOF_FLOAT == 16\n#define STRBITSOF_FLOAT \"16\"\n#define STRBITSOF_CFLOAT \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_FLOAT\n#define PyArray_COMPLEX32 PyArray_CFLOAT\n\ttypedef float Float16;\n\ttypedef cfloat Complex32;\n#endif\n#elif BITSOF_FLOAT == 32\n#define STRBITSOF_FLOAT \"32\"\n#define STRBITSOF_CFLOAT \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_FLOAT\n#define PyArray_COMPLEX64 PyArray_CFLOAT\n\ttypedef float Float32;\n\ttypedef cfloat Complex64;\n#endif\n#elif BITSOF_FLOAT == 64\n#define STRBITSOF_FLOAT \"64\"\n#define STRBITSOF_CFLOAT \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_FLOAT\n#define PyArray_COMPLEX128 PyArray_CFLOAT\n\ttypedef float Float64;\n\ttypedef cfloat Complex128;\n#endif\n#elif BITSOF_FLOAT == 80\n#define STRBITSOF_FLOAT \"80\"\n#define STRBITSOF_CFLOAT \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_FLOAT\n#define PyArray_COMPLEX160 PyArray_CFLOAT\n\ttypedef float Float80;\n\ttypedef cfloat Complex160;\n#endif\n#elif BITSOF_FLOAT == 96\n#define STRBITSOF_FLOAT \"96\"\n#define STRBITSOF_CFLOAT \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_FLOAT\n#define PyArray_COMPLEX192 PyArray_CFLOAT\n\ttypedef float Float96;\n\ttypedef cfloat Complex192;\n#endif\n#elif BITSOF_FLOAT == 128\n#define STRBITSOF_FLOAT \"128\"\n#define STRBITSOF_CFLOAT \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_FLOAT\n#define PyArray_COMPLEX256 PyArray_CFLOAT\n\ttypedef float Float128;\n\ttypedef cfloat Complex256;\n#endif\n#endif\n\n\n#if BITSOF_LONGDOUBLE == 16\n#define STRBITSOF_LONGDOUBLE \"16\"\n#define STRBITSOF_CLONGDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX32 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float16;\n\ttypedef clongdouble Complex32;\n#endif\n#elif BITSOF_LONGDOUBLE == 32\n#define STRBITSOF_LONGDOUBLE \"32\"\n#define STRBITSOF_CLONGDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX64 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float32;\n\ttypedef clongdouble Complex64;\n#endif\n#elif BITSOF_LONGDOUBLE == 64\n#define STRBITSOF_LONGDOUBLE \"64\"\n#define STRBITSOF_CLONGDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX128 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float64;\n\ttypedef clongdouble Complex128;\n#endif\n#elif BITSOF_LONGDOUBLE == 80\n#define STRBITSOF_LONGDOUBLE \"80\"\n#define STRBITSOF_CLONGDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX160 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float80;\n\ttypedef clongdouble Complex160;\n#endif\n#elif BITSOF_LONGDOUBLE == 96\n#define STRBITSOF_LONGDOUBLE \"96\"\n#define STRBITSOF_CLONGDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX192 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float96;\n\ttypedef clongdouble Complex192;\n#endif\n#elif BITSOF_LONGDOUBLE == 128\n#define STRBITSOF_LONGDOUBLE \"128\"\n#define STRBITSOF_CLONGDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX256 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float128;\n\ttypedef clongdouble Complex256;\n#endif\n#elif BITSOF_LONGDOUBLE == 256\n#define STRBITSOF_LONGDOUBLE \"256\"\n#define STRBITSOF_CLONGDOUBLE \"512\"\n#define PyArray_FLOAT256 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX512 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float256;\n\ttypedef clongdouble Complex512;\n#endif\n\n\t/* End of typedefs for numarray style bit-width names */\n\n/* This is to typedef Intp to the appropriate pointer size for this platform.\n * Py_intptr_t, Py_uintptr_t are defined in pyport.h. */\ntypedef Py_intptr_t intp;\ntypedef Py_uintptr_t uintp;\n#define SIZEOF_INTP SIZEOF_PY_INTPTR_T\n#define SIZEOF_UINTP SIZEOF_PY_INTPTR_T\n\n#if PY_VERSION_HEX >= 0x02050000\n#define _int_or_ssize_t Py_ssize_t\n#else\n#define _int_or_ssize_t int\n#endif\n\n#define INTP_FMT \"d\"\n\n#if SIZEOF_PY_INTPTR_T == SIZEOF_INT\n\t#define PyArray_INTP PyArray_INT\n\t#define PyArray_UINTP PyArray_UINT\n #define PyIntpArrType_Type PyIntArrType_Type\n #define PyUIntpArrType_Type PyUIntArrType_Type\n\t#define MAX_INTP MAX_INT\n\t#define MIN_INTP MIN_INT\n\t#define MAX_UINTP MAX_UINT\n#elif SIZEOF_PY_INTPTR_T == SIZEOF_LONG\n\t#define PyArray_INTP PyArray_LONG\n\t#define PyArray_UINTP PyArray_ULONG\n #define PyIntpArrType_Type PyLongArrType_Type\n #define PyUIntpArrType_Type PyULongArrType_Type\n\t#define MAX_INTP MAX_LONG\n\t#define MIN_INTP MIN_LONG\n\t#define MAX_UINTP MAX_ULONG\n #undef INTP_FMT\n #define INTP_FMT \"ld\"\n#elif defined(PY_LONG_LONG) && (SIZEOF_PY_INTPTR_T == SIZEOF_LONG_LONG)\n\t#define PyArray_INTP PyArray_LONGLONG\n\t#define PyArray_UINTP PyArray_ULONGLONG\n #define PyIntpArrType_Type PyLongLongArrType_Type\n #define PyUIntpArrType_Type PyULongLongArrType_Type\n\t#define MAX_INTP MAX_LONGLONG\n\t#define MIN_INTP MIN_LONGLONG\n\t#define MAX_UINTP MAX_ULONGLONG\n #undef INTP_FMT\n #define INTP_FMT \"Ld\"\n#endif\n\n#define ERR(str) fprintf(stderr, #str); fflush(stderr);\n#define ERR2(str) fprintf(stderr, str); fflush(stderr);\n\n /* Macros to define how array, and dimension/strides data is\n allocated.\n */\n\n /* Data buffer */\n#define PyDataMem_NEW(size) ((char *)malloc(size))\n /* #define PyArrayMem_NEW(size) PyMem_NEW(char, size)*/\n#define PyDataMem_FREE(ptr) free(ptr)\n /* #define PyArrayMem_FREE(ptr) PyMem_Free(ptr) */\n#define PyDataMem_RENEW(ptr,size) ((char *)realloc(ptr,size))\n\n#define PyArray_USE_PYMEM 0\n\n#if PyArray_USE_PYMEM == 1\n#define _pya_malloc PyObject_Malloc\n#define _pya_free PyObject_Free\n#define _pya_realloc PyObject_Realloc\n#else\n#define _pya_malloc malloc\n#define _pya_free free\n#define _pya_realloc realloc\n#endif\n\n/* Dimensions and strides */\n#define PyDimMem_NEW(size) ((intp *)_pya_malloc(size*sizeof(intp)))\n#define PyDimMem_FREE(ptr) _pya_free(ptr)\n#define PyDimMem_RENEW(ptr,size) ((intp *)_pya_realloc(ptr,size*sizeof(intp)))\n\n\n /* These must deal with unaligned and swapped data if necessary */\ntypedef PyObject * (PyArray_GetItemFunc) (void *, void *);\ntypedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);\n\ntypedef void (PyArray_CopySwapNFunc)(void *, void *, intp, int, int);\ntypedef void (PyArray_CopySwapFunc)(void *, void *, int, int);\ntypedef Bool (PyArray_NonzeroFunc)(void *, void *);\n\n\n /* These assume aligned and notswapped data -- a buffer will be\n used before or contiguous data will be obtained\n */\ntypedef int (PyArray_CompareFunc)(const void *, const void *, void *);\ntypedef int (PyArray_ArgFunc)(void*, intp, intp*, void *);\ntypedef void (PyArray_DotFunc)(void *, intp, void *, intp, void *, intp,\n\t\t\t void *);\ntypedef void (PyArray_VectorUnaryFunc)(void *, void *, intp, void *, void *);\ntypedef int (PyArray_ScanFunc)(FILE *, void *, void *, void *);\ntypedef int (PyArray_FromStrFunc)(char *, void *, char **, void *);\n\ntypedef int (PyArray_FillFunc)(void *, intp, void *);\n\ntypedef int (PyArray_SortFunc)(void *, intp, void *);\ntypedef int (PyArray_ArgSortFunc)(void *, intp *, intp, void *);\n\ntypedef int (PyArray_FillWithScalarFunc)(void *, intp, void *, void *);\n\ntypedef struct {\n intp *ptr;\n int len;\n} PyArray_Dims;\n\ntypedef struct {\n\t/* Functions to cast to all other standard types*/\n\tPyArray_VectorUnaryFunc *cast[PyArray_NTYPES];\n\n\t/* Functions to get and set items with standard\n\t Python types -- not array scalars */\n\tPyArray_GetItemFunc *getitem;\n\tPyArray_SetItemFunc *setitem;\n\n\t/* Copy and/or swap data. Memory areas may not overlap */\n\t/* Use memmove first if they might */\n\tPyArray_CopySwapNFunc *copyswapn;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Function to compare items */\n\tPyArray_CompareFunc *compare;\n\n\t/* Function to select largest */\n\tPyArray_ArgFunc *argmax;\n\n\t/* Function to compute dot product */\n\tPyArray_DotFunc\t*dotfunc;\n\n\t/* Function to scan an ASCII file and\n\t place a single value plus possible separator */\n\tPyArray_ScanFunc *scanfunc;\n\n\t/* Function to read a single value from a string */\n\t/* and adjust the pointer */\n\tPyArray_FromStrFunc *fromstr;\n\n\t/* Function to determine if data is zero or not */\n\tPyArray_NonzeroFunc *nonzero;\n\n\t/* Used for arange */\n\tPyArray_FillFunc *fill;\n\n\t/* Function to fill arrays with scalar values */\n\tPyArray_FillWithScalarFunc *fillwithscalar;\n\n\t/* Sorting functions */\n\tPyArray_SortFunc *sort[PyArray_NSORTS];\n\tPyArray_ArgSortFunc *argsort[PyArray_NSORTS];\n\n} PyArray_ArrFuncs;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tPyTypeObject *typeobj; /* the type object representing an\n\t\t\t\t intance of this type */\n\tchar kind; /* kind for this type */\n\tchar type; /* unique-character representing this type */\n\tchar byteorder; /* '>' (big), '<' (little), '|'\n\t\t\t\t (not-applicable), or '=' (native). */\n char hasobject; /* non-zero if it has object arrays in fields */\n\tint type_num; /* number representing this type */\n\tint elsize; /* element size for this type */\n\tint alignment; /* alignment needed for this type */\n\tstruct _arr_descr\t\t\t\t\t\\\n\t*subarray; /* Non-NULL if this type is\n\t\t\t\t is an array (C-contiguous)\n\t\t\t\t of some other type\n\t\t\t\t*/\n\tPyObject *fields; /* The fields dictionary for this type */\n\t /* For statically defined descr this\n\t\t\t\t is always Py_None */\n\n\tPyArray_ArrFuncs *f; /* a table of functions specific for each\n\t\t\t\t basic data descriptor */\n} PyArray_Descr;\n\ntypedef struct _arr_descr {\n\tPyArray_Descr *base;\n\tPyObject *shape; /* a tuple */\n} PyArray_ArrayDescr;\n\n\n/*\n The main array object structure. It is recommended to use the macros\n defined below (PyArray_DATA and friends) access fields here, instead\n of the members themselves.\n */\n\ntypedef struct PyArrayObject {\n\tPyObject_HEAD\n\tchar *data; /* pointer to raw data buffer */\n\tint nd; /* number of dimensions, also called ndim */\n\tintp *dimensions; /* size in each dimension */\n intp *strides; /* bytes to jump to get to the\n\t\t\t\t next element in each dimension */\n\tPyObject *base; /* This object should be decref'd\n\t\t\t\t upon deletion of array */\n\t /* For views it points to the original array */\n\t /* For creation from buffer object it points\n\t\t\t\t to an object that shold be decref'd on\n\t\t\t\t deletion */\n\t /* For UPDATEIFCOPY flag this is an array\n\t\t\t\t to-be-updated upon deletion of this one */\n\tPyArray_Descr *descr; /* Pointer to type structure */\n\tint flags; /* Flags describing array -- see below*/\n\tPyObject *weakreflist; /* For weakreferences */\n} PyArrayObject;\n\n\n#define fortran fortran_ /* For some compilers */\n\n/* Mirrors buffer object to ptr */\n\ntypedef struct {\n PyObject_HEAD\n PyObject *base;\n void *ptr;\n intp len;\n int flags;\n} PyArray_Chunk;\n\n/* Array flags */\n\n/* Means c-style contiguous (last index varies the fastest). The\n data elements right after each other. */\n#define CONTIGUOUS 0x0001\n/* set if array is a contiguous Fortran array: the first index\n varies the fastest in memory (strides array is reverse of\n C-contiguous array)*/\n#define FORTRAN 0x0002\n\n/*\n Note: all 0-d arrays are CONTIGUOUS and FORTRAN contiguous. If a\n 1-d array is CONTIGUOUS it is also FORTRAN contiguous\n*/\n\n/* If set, the array owns the data: it will be free'd when the array\n is deleted. */\n#define OWNDATA 0x0004\n#define OWN_DATA OWNDATA\n\n/* An array never has these three set; they're only used as parameter\n flags to the the various FromAny functions */\n/* Cause a cast to occur regardless of whether or not it is safe. */\n#define FORCECAST 0x0010\n/* Always copy the array. Returned arrays are always CONTIGUOUS, ALIGNED,\n and WRITEABLE. */\n#define ENSURECOPY 0x0020\n/* Make sure the returned array is an ndarray or a bigndarray */\n#define ENSUREARRAY 0x0040\n\n/* Array data is aligned on the appropiate memory address for the\n type stored (e.g., an array of doubles (8 bytes each) starts on\n a memory address that's a multiple of 8) */\n#define ALIGNED 0x0100\n/* Array data has the native endianness */\n#define NOTSWAPPED 0x0200\n/* Array data is writeable */\n#define WRITEABLE 0x0400\n/* If this flag is set, then base contains a pointer to an array of\n the same size that should be updated with the current contents of\n this array when this array is deallocated\n*/\n#define UPDATEIFCOPY 0x1000\n\n\n#define BEHAVED_FLAGS ALIGNED | WRITEABLE\n#define BEHAVED_NS_FLAGS ALIGNED | WRITEABLE | NOTSWAPPED\n#define CARRAY_FLAGS CONTIGUOUS | BEHAVED_FLAGS\n#define CARRAY_FLAGS_RO CONTIGUOUS | ALIGNED\n#define FARRAY_FLAGS FORTRAN | BEHAVED_FLAGS\n#define FARRAY_FLAGS_RO FORTRAN | ALIGNED\n#define DEFAULT_FLAGS CARRAY_FLAGS\n\n#define UPDATE_ALL_FLAGS CONTIGUOUS | FORTRAN | ALIGNED\n\n\n/* Size of internal buffers used for alignment */\n#define PyArray_BUFSIZE 10000\n#define PyArray_MIN_BUFSIZE 5\n#define PyArray_MAX_BUFSIZE 100000000\n\n/*\n * C API: consists of Macros and functions. The MACROS are defined here.\n */\n\n\n#define PyArray_CHKFLAGS(m, FLAGS) \\\n\t((((PyArrayObject *)(m))->flags & (FLAGS)) == (FLAGS))\n#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, CONTIGUOUS)\n#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, WRITEABLE)\n#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, ALIGNED)\n\n#ifndef MAX\n#define MAX(a,b) (((a)>(b))?(a):(b))\n#endif\n#ifndef MIN\n#define MIN(a,b) (((a)<(b))?(a):(b))\n#endif\n\n/* Useful if a and b have to be evaluated. */\n\n#define tMAX(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_>_y_ ? _x_ : _y_}\n#define tMIN(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_<_y_ ? _x_ : _y_}\n\n#if defined(ALLOW_THREADS)\n#define BEGIN_THREADS_DEF PyThreadState *_save;\n#define BEGIN_THREADS _save = PyEval_SaveThread();\n#define END_THREADS PyEval_RestoreThread(_save);\n#define ALLOW_C_API_DEF PyGILState_STATE __save__;\n#define ALLOW_C_API __save__ = PyGILState_Ensure();\n#define DISABLE_C_API PyGILState_Release(__save__);\n#else\n#define BEGIN_THREADS_DEF\n#define BEGIN_THREADS\n#define END_THREADS\n#define ALLOW_C_API_DEF\n#define\tALLOW_C_API\n#define\tDISABLE_C_API\n#endif\n\n\n\n\ntypedef struct {\n PyObject_HEAD\n\tint nd_m1; /* number of dimensions - 1 */\n intp\t\t index, size;\n\tintp coordinates[MAX_DIMS];/* N-dimensional loop */\n intp dims_m1[MAX_DIMS]; /* ao->dimensions - 1 */\n\tintp strides[MAX_DIMS]; /* ao->strides or fake */\n\tintp backstrides[MAX_DIMS];/* how far to jump back */\n\tintp factors[MAX_DIMS]; /* shape factors */\n\tPyArrayObject *ao;\n\tchar *dataptr; /* pointer to current item*/\n Bool contiguous;\n} PyArrayIterObject;\n\n\n/* Iterator API */\n#define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type)\n\n#define PyArray_ITER_RESET(it) {\t\t\t\t\t\\\n\tit->index = 0;\t\t\t\t\t\t \\\n\tit->dataptr = it->ao->data;\t\t\t\t\t\\\n\tmemset(it->coordinates, 0, (it->nd_m1+1)*sizeof(intp));\t\t\\\n}\n\n#define _PyArray_ITER_NEXT1(it) {\t\t\\\n\t\tit->dataptr += it->strides[0];\t\\\n\t\tit->coordinates[0]++;\t\t\\\n\t}\n\n#define _PyArray_ITER_NEXT2(it) {\t\t\t\t\t\\\n\t\tif (it->coordinates[1] < it->dims_m1[1]) {\t\t\\\n\t\t\tit->coordinates[1]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->coordinates[1] = 0;\t\t\t\t\\\n\t\t\tit->coordinates[0]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[0] -\t\t\t\\\n\t\t\t\tit->backstrides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_NEXT(it) {\t\t\t\t\t\t\\\n\tit->index++;\t\t\t\t\t\t \\\n if (it->nd_m1 == 0) {\t\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT1(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse if (it->contiguous) it->dataptr += it->ao->descr->elsize; \\\n\telse if (it->nd_m1 == 1) {\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT2(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse {\t\t\t\t\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_ >= 0; _i_--) {\t\t\\\n\t\t\tif (it->coordinates[_i_] <\t\t\t\\\n\t\t\t it->dims_m1[_i_]) {\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_]++;\t\t\t\\\n\t\t\t\tit->dataptr += it->strides[_i_];\t\\\n\t\t\t\tbreak;\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t\telse {\t\t\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_] = 0;\t\t\\\n\t\t\t\tit->dataptr -= it->backstrides[_i_];\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_GOTO(it, destination) {\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tit->index = 0;\t\t\t\t\t\t\\\n\t\tit->dataptr = it->ao->data;\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_>=0; _i_--) {\t\t\t\\\n\t\t\tit->dataptr += destination[_i_] *\t\t\\\n\t\t\t\tit->strides[_i_];\t\t\t\\\n\t\t\tit->coordinates[_i_] = destination[_i_];\t\\\n\t\t\tit->index += destination[_i_] *\t\t\t\\\n\t\t\t\t( _i_==it->nd_m1 ? 1 :\t\t\t\\\n\t\t\t\t it->dims_m1[i+1]+1) ;\t\t \\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_GOTO1D(it, ind) { \\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tintp _lind_ = (intp) (ind);\t\t\t\t\\\n\t\tit->index = _lind_;\t\t\t\t\t\\\n if (it->nd_m1 == 0) { \\\n it->dataptr = it->ao->data + (ind) * \\\n it->strides[0]; \\\n } \\\n else if (it->contiguous) \\\n\t\t\tit->dataptr = it->ao->data + (ind) *\t\t\\\n\t\t\t\tit->ao->descr->elsize;\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->dataptr = it->ao->data;\t\t\t\\\n\t\t\tfor (_i_ = 0; _i_<=it->nd_m1; _i_++) {\t\t\\\n\t\t\t\tit->dataptr += (_lind_ / it->factors[_i_]) \\\n\t\t\t\t\t* it->strides[_i_];\t\t\\\n\t\t\t\t_lind_ %= it->factors[_i_];\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_DATA(it) ((PyArrayIterObject *)it)->dataptr\n\n\n/*\n Any object passed to PyArray_Broadcast must be binary compatible with\n this structure.\n*/\n\ntypedef struct {\n\tPyObject_HEAD\n\n\tint numiter; /* number of iters */\n\tintp size; /* broadcasted size */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* iterators */\n} PyArrayMultiIterObject;\n\n#define PyArray_MultiIter_RESET(multi) {\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index = 0;\t\t\t\t \\\n\t\tfor (_mi_ = 0; _mi_ < _mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_RESET(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_NEXT(multi) {\t\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index += 1;\t\t\t\t \\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_NEXT(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_GOTO(multi, dest) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO(_mul_->iters[_mi_], dest);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_GOTO1D(multi, ind) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO1D(_mul_->iters[_mi_], ind);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_DATA(multi, i) \\\n\t((PyArrayMultiIterObject *)multi)->iters[i]->dataptr\n\n#define PyArray_MultiIter_SIZE(multi) \\\n\t((PyArrayMultiIterObject *)multi)->size;\n\n\n/* Store the information needed for fancy-indexing over an array */\n\ntypedef struct {\n\tPyObject_HEAD\n\t/* Multi-iterator portion --- needs to be present in this order to\n\t work with PyArray_Broadcast */\n\n\tint numiter; /* number of index-array\n\t\t\t\t\t\t\t iterators */\n\tintp size; /* size of broadcasted\n\t\t\t\t\t\t\t result */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* index object\n\t\t\t\t\t\t\t iterators */\n\tPyArrayIterObject *ait; /* flat Iterator for\n\t\t\t\t\t\t\t underlying array */\n\n\t/* flat iterator for subspace (when numiter < nd) */\n\tPyArrayIterObject *subspace;\n\n\t/* if subspace iteration, then this is the array of\n\t axes in the underlying array represented by the\n\t index objects */\n\tint iteraxes[MAX_DIMS];\n\t/* if subspace iteration, the these are the coordinates\n\t to the start of the subspace.\n\t*/\n\tintp bscoord[MAX_DIMS];\n\n\tPyObject *indexobj; /* reference to\n\t\t\t\t\t\t\t creating obj */\n\tint view;\n\tint consec;\n\tchar *dataptr;\n\n} PyArrayMapIterObject;\n\n/* All sorts of useful ways to look into a PyArrayObject.\n These are the recommended over casting to PyArrayObject and accessing\n the members directly.\n */\n\n#define PyArray_NDIM(obj) (((PyArrayObject *)(obj))->nd)\n#define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || PyArray_CHKFLAGS(m, CONTIGUOUS) || \\\n\t\t\t\t PyArray_CHKFLAGS(m, FORTRAN))\n#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, FORTRAN) && (PyArray_NDIM(m) > 1))\n#define FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, FORTRAN) ? FORTRAN : 0))\n#define PyArray_DATA(obj) ((void *)(((PyArrayObject *)(obj))->data))\n#define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data)\n#define PyArray_DIMS(obj) (((PyArrayObject *)(obj))->dimensions)\n#define PyArray_STRIDES(obj) (((PyArrayObject *)(obj))->strides)\n#define PyArray_DIM(obj,n) (((PyArrayObject *)(obj))->dimensions[n])\n#define PyArray_STRIDE(obj,n) (((PyArrayObject *)(obj))->strides[n])\n#define PyArray_BASE(obj) (((PyArrayObject *)(obj))->base)\n#define PyArray_DESCR(obj) (((PyArrayObject *)(obj))->descr)\n#define PyArray_FLAGS(obj) (((PyArrayObject *)(obj))->flags)\n#define PyArray_ITEMSIZE(obj) (((PyArrayObject *)(obj))->descr->elsize)\n#define PyArray_TYPE(obj) (((PyArrayObject *)(obj))->descr->type_num)\n#define PyArray_GETITEM(obj,itemptr)\t\t\t\\\n\t((PyArrayObject *)(obj))->descr->f->getitem((char *)itemptr,\t\\\n\t\t\t\t\t\t (PyArrayObject *)obj);\n#define PyArray_SETITEM(obj,itemptr,v)\t\t\t\t\t\\\n\t(obj)->descr->f->setitem((PyObject *)v,(char *)(itemptr),\t\t\\\n\t\t\t (PyArrayObject *)(obj));\n\n\n#define PyTypeNum_ISBOOL(type) (type == PyArray_BOOL)\n#define PyTypeNum_ISUNSIGNED(type) ((type == PyArray_UBYTE) || \\\n\t\t\t\t (type == PyArray_USHORT) || \\\n\t\t\t\t (type == PyArray_UINT) ||\t\\\n\t\t\t\t (type == PyArray_ULONG) || \\\n\t\t\t\t (type == PyArray_ULONGLONG))\n\n#define PyTypeNum_ISSIGNED(type) ((type == PyArray_BYTE) ||\t\\\n\t\t\t (type == PyArray_SHORT) ||\t\\\n\t\t\t (type == PyArray_INT) ||\t\\\n\t\t\t (type == PyArray_LONG) ||\t\\\n\t\t\t (type == PyArray_LONGLONG))\n\n#define PyTypeNum_ISINTEGER(type) ((type >= PyArray_BYTE) &&\t\\\n\t\t\t\t(type <= PyArray_ULONGLONG))\n\n#define PyTypeNum_ISFLOAT(type) ((type >= PyArray_FLOAT) && \\\n\t\t\t (type <= PyArray_LONGDOUBLE))\n\n#define PyTypeNum_ISNUMBER(type) (type <= PyArray_CLONGDOUBLE)\n\n#define PyTypeNum_ISSTRING(type) ((type == PyArray_UCHAR) || \\\n\t\t\t (type == PyArray_UNICODE))\n\n#define PyTypeNum_ISCOMPLEX(type) ((type >= PyArray_CFLOAT) && \\\n\t\t\t\t(type <= PyArray_CLONGDOUBLE))\n\n#define PyTypeNum_ISPYTHON(type) ((type == PyArray_LONG) || \\\n\t\t\t\t (type == PyArray_DOUBLE) ||\t\\\n\t\t\t\t (type == PyArray_CDOUBLE) ||\t\\\n\t\t (type == PyArray_BOOL) || \\\n\t\t\t\t (type == PyArray_OBJECT ))\n\n#define PyTypeNum_ISFLEXIBLE(type) ((type>=PyArray_STRING) && \\\n\t\t\t\t (type<=PyArray_VOID))\n\n#define PyTypeNum_ISUSERDEF(type) ((type >= PyArray_USERDEF) && \\\n\t\t\t\t (type < PyArray_USERDEF+\\\n\t\t\t\t PyArray_NUMUSERTYPES))\n\n#define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \\\n PyTypeNum_ISUSERDEF(type))\n\n#define PyTypeNum_ISOBJECT(type) ((type) == PyArray_OBJECT)\n\n#define _PyADt(o) ((PyArray_Descr *)o)->type_num\n#define PyDescr_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj))\n#define PyDescr_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(_PyADt(obj))\n#define PyDescr_ISSIGNED(obj) PyTypeNum_ISSIGNED(_PyADt(obj))\n#define PyDescr_ISINTEGER(obj) PyTypeNum_ISINTEGER(_PyADt(obj))\n#define PyDescr_ISFLOAT(obj) PyTypeNum_ISFLOAT(_PyADt(obj))\n#define PyDescr_ISNUMBER(obj) PyTypeNum_ISNUMBER(_PyADt(obj))\n#define PyDescr_ISSTRING(obj) PyTypeNum_ISSTRING(_PyADt(obj))\n#define PyDescr_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(_PyADt(obj))\n#define PyDescr_ISPYTHON(obj) PyTypeNum_ISPYTHON(_PyADt(obj))\n#define PyDescr_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(_PyADt(obj))\n#define PyDescr_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(_PyADt(obj))\n#define PyDescr_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(_PyADt(obj))\n#define PyDescr_ISOBJECT(obj) PyTypeNum_ISOBJECT(_PyADt(obj))\n#undef _PyAD\n\n#define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))\n#define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))\n#define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))\n#define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))\n#define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))\n#define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))\n#define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj))\n#define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))\n#define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))\n#define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))\n#define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))\n\n#define PyArray_LITTLE '<'\n#define PyArray_BIG '>'\n#define PyArray_NATIVE '='\n#define PyArray_SWAP 's'\n#define PyArray_IGNORE '|'\n\n#ifdef WORDS_BIGENDIAN\n#define PyArray_NATBYTE PyArray_BIG\n#define PyArray_OPPBYTE PyArray_LITTLE\n#else\n#define PyArray_NATBYTE PyArray_LITTLE\n#define PyArray_OPPBYTE PyArray_BIG\n#endif\n\n#define PyArray_ISNBO(arg) ((arg) != PyArray_OPPBYTE)\n#define PyArray_IsNativeByteOrder PyArray_ISNBO\n#define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)\n\n#define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) &&\t\\\n\t\t\t\t PyArray_ISNOTSWAPPED(m))\n#define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS)\n#define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS_RO)\n#define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS)\n#define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS_RO)\n#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, BEHAVED_FLAGS)\n#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, ALIGNED)\n\n\n\n/* This is the form of the struct that's returned pointed by the\n PyCObject attribute of an array __array_struct__. See\n http://numeric.scipy.org/array_interface.html for the full\n documentation. */\ntypedef struct {\n int version; /* contains the integer 2 as a sanity check */\n int nd; /* number of dimensions */\n char typekind; /* kind in array --- character code of typestr */\n int itemsize; /* size of each element */\n int flags; /* how should be data interpreted. Valid\n flags are CONTIGUOUS (1), FORTRAN (2),\n ALIGNED (0x100), NOTSWAPPED (0x200), and\n WRITEABLE (0x400)*/\n intp *shape; /* A length-nd array of shape information */\n intp *strides; /* A length-nd array of stride information */\n void *data; /* A pointer to the first element of the array */\n} PyArrayInterface;\n\n/* Includes the \"function\" C-API -- these are all stored in a\n list of pointers --- one for each file\n The two lists are concatenated into one in multiarray.\n\n They are available as import_array()\n*/\n\n\n#include \"__multiarray_api.h\"\n\n\n/* C-API that requries previous API to be defined */\n\n#define PyArray_DescrCheck(op) ((op)->ob_type == &PyArrayDescr_Type)\n\n#define PyArray_Check(op) ((op)->ob_type == &PyArray_Type ||\t\t\\\n\t\t\t PyObject_TypeCheck((op), &PyArray_Type))\n#define PyArray_CheckExact(op) ((op)->ob_type == &PyArray_Type)\n\n#define PyArray_IsZeroDim(op) (PyArray_Check(op) && (PyArray_NDIM(op) == 0))\n#define PyArray_IsScalar(obj, cls)\t\t\t\t\\\n\t(PyObject_TypeCheck((obj), &Py##cls##ArrType_Type))\n#define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \\\n PyArray_IsZeroDim(m))\n#define PyArray_IsPythonScalar(obj) \\\n\t(PyInt_Check(obj) || PyFloat_Check(obj) || PyComplex_Check(obj) || \\\n\t PyLong_Check(obj) || PyBool_Check(obj) || PyString_Check(obj) || \\\n\t PyUnicode_Check(obj))\n#define PyArray_IsAnyScalar(obj)\t\t\t\t\t\\\n\t(PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))\n#define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \\\n\t\t\t\t PyArray_CheckScalar(obj))\n\n#define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? Py_INCREF(m), m : \\\n (PyArrayObject *)(PyArray_Copy(m)))\n\n#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))\n#define PyArray_NBYTES(m) (PyArray_ITEMSIZE(m) * PyArray_SIZE(m))\n#define PyArray_FROM_O(m) PyArray_FromAny(m, NULL, 0, 0, 0, NULL)\n#define PyArray_FROM_OF(m,flags) PyArray_CheckFromAny(m, NULL, 0, 0, flags, NULL)\n#define PyArray_FROM_OT(m,type) PyArray_FromAny(m, PyArray_DescrFromType(type), \\\n 0, 0, 0, NULL);\n#define PyArray_FROM_OTF(m, type, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \\\n (((flags) & ENSURECOPY) ? \\\n ((flags) | DEFAULT_FLAGS) : (flags)), NULL)\n#define PyArray_FROMANY(m, type, min, max, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \\\n (((flags) & ENSURECOPY) ? \\\n (flags) | DEFAULT_FLAGS : (flags)), NULL)\n\n#define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), (val), PyArray_NBYTES(obj))\n\n#define REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)\n#define MAX_ELSIZE 2*SIZEOF_LONGDOUBLE\n\n#define PyArray_ContiguousFromAny(op, type, min_depth, max_depth) \\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, DEFAULT_FLAGS, NULL)\n\n#define PyArray_EquivArrTypes(a1, a2)\t\t\t\t\t\\\n\tPyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))\n#define PyArray_EquivTypenums(typenum1, typenum2)\t\t\\\n\tPyArray_EquivTypes(PyArray_DescrFromType(typenum1),\t\\\n\t\t\t PyArray_DescrFromType(typenum2))\n\n#define PyArray_EquivByteorders(b1, b2) \\\n\t((b1 == b2) || (PyArray_ISNBO(b1) == PyArray_ISNBO(b2)))\n\n#define PyArray_SimpleNew(nd, dims, typenum) \\\n\tPyArray_New(&PyArray_Type, nd, dims, typenum, NULL, NULL, 0, 0, NULL)\n#define PyArray_SimpleNewFromData(nd, dims, typenum, data) \\\n PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, data, 0, CARRAY_FLAGS, NULL)\n#define PyArray_SimpleNewFromDescr(nd, dims, descr) \\\n\tPyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, NULL, NULL, 0, NULL)\n#define PyArray_EnsureAnyArray(obj) \\\n\t(PyArray_Check(obj) ? obj : PyArray_EnsureArray(obj))\n\n\n/* These might be faster without the dereferencing of obj\n going on inside -- of course an optimizing compiler should\n inline the constants inside a for loop making it a moot point\n*/\n\n#define PyArray_GETPTR1(obj, i) (void *)(PyArray_BYTES(obj) +\t\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0))\n\n#define PyArray_GETPTR2(obj, i, j) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1))\n\n#define PyArray_GETPTR3(obj, i, j, k) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\\n\t\t\t\t\t k*PyArray_STRIDE(obj, 2)) \\\n\n#define PyArray_GETPTR4(obj, i, j, k, l) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\\n\t\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\\n\t\t\t\t\t\t k*PyArray_STRIDE(obj, 2) + \\\n\t\t\t\t\t\t l*PyArray_STRIDE(obj, 3))\n\n#define PyArray_DESCR_REPLACE(descr) do {\t\\\n\t\tPyArray_Descr *_new_;\t\t\t\\\n\t\t_new_ = PyArray_DescrNew(descr);\t\\\n\t\tPy_XDECREF(descr);\t\t\t\\\n\t\tdescr = _new_;\t\t\t\t\\\n\t} while(0)\n\n/* Copy should always return contiguous array */\n#define PyArray_Copy(obj) PyArray_NewCopy(obj, 0)\n\n#define PyArray_FromObject(op, type, min_depth, max_depth)\t\t\\\n\tPyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, BEHAVED_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_ContiguousFromObject(op, type, min_depth, max_depth)\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_CopyFromObject(op, type, min_depth, max_depth)\t\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, ENSURECOPY | DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_Cast(mp, type_num) \\\n\tPyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)\n\n/* Compatibility with old Numeric stuff -- don't use in new code */\n\n#define PyArray_FromDimsAndData(nd, d, type, data) \\\n\tPyArray_FromDimsAndDataAndDescr(nd, d, PyArray_DescrFromType(type), \\\n\t\t\t\t\tdata)\n\n#define PyArray_UNSIGNED_TYPES\n#define PyArray_SBYTE PyArray_BYTE\n#define PyArray_CHAR PyArray_BYTE\n#define PyArray_CopyArray PyArray_CopyInto\n#define _PyArray_multiply_list PyArray_MultiplyIntList\n#define PyArray_ISSPACESAVER(m) FALSE\n#define PyScalarArray_Check PyArray_CheckScalar\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# undef CAT\n# undef CAT2\n# undef NS\n# undef longlong\n# undef ulonglong\n# undef Bool\n# undef longdouble\n# undef byte\n# undef ubyte\n# undef ushort\n# undef uint\n# undef ulong\n# undef cfloat\n# undef cdouble\n# undef clongdouble\n# undef Int8\n# undef UInt8\n# undef Int16\n# undef UInt16\n# undef Int32\n# undef UInt32\n# undef Int64\n# undef UInt64\n# undef Int128\n# undef UInt128\n# undef Int256\n# undef UInt256\n# undef Float16\n# undef Complex32\n# undef Float32\n# undef Complex64\n# undef Float64\n# undef Complex128\n# undef Float80\n# undef Complex160\n# undef Float96\n# undef Complex192\n# undef Float128\n# undef Complex256\n# undef intp\n# undef uintp\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* !Py_ARRAYOBJECT_H */\n", + "source_code_before": "\n/* This expects the following variables to be defined (besides\n the usual ones from pyconfig.h\n\n SIZEOF_LONG_DOUBLE -- sizeof(long double) or sizeof(double) if no\n long double is present on platform.\n CHAR_BIT -- number of bits in a char (usually 8)\n (should be in limits.h)\n*/\n\n#ifndef Py_ARRAYOBJECT_H\n#define Py_ARRAYOBJECT_H\n#ifdef __cplusplus\n#define CONFUSE_EMACS {\n#define CONFUSE_EMACS2 }\nextern \"C\" CONFUSE_EMACS\n#undef CONFUSE_EMACS\n#undef CONFUSE_EMACS2\n/* ... otherwise a semi-smart idententer (like emacs) tries to indent\n everything when you're typing */\n#endif\n#include \"config.h\"\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# define CAT2(x,y) x ## y\n# define CAT(x,y) CAT2(x,y)\n# define NS(name) CAT(PY_ARRAY_TYPES_PREFIX, name)\n# define longlong NS(longlong)\n# define ulonglong NS(ulonglong)\n# define Bool NS(Bool)\n# define longdouble NS(longdouble)\n# define byte NS(byte)\n# define ubyte NS(ubyte)\n# define ushort NS(ushort)\n# define uint NS(uint)\n# define ulong NS(ulong)\n# define cfloat NS(cfloat)\n# define cdouble NS(cdouble)\n# define clongdouble NS(clongdouble)\n# define Int8 NS(Int8)\n# define UInt8 NS(UInt8)\n# define Int16 NS(Int16)\n# define UInt16 NS(UInt16)\n# define Int32 NS(Int32)\n# define UInt32 NS(UInt32)\n# define Int64 NS(Int64)\n# define UInt64 NS(UInt64)\n# define Int128 NS(Int128)\n# define UInt128 NS(UInt128)\n# define Int256 NS(Int256)\n# define UInt256 NS(UInt256)\n# define Float16 NS(Float16)\n# define Complex32 NS(Complex32)\n# define Float32 NS(Float32)\n# define Complex64 NS(Complex64)\n# define Float64 NS(Float64)\n# define Complex128 NS(Complex128)\n# define Float80 NS(Float80)\n# define Complex160 NS(Complex160)\n# define Float96 NS(Float96)\n# define Complex192 NS(Complex192)\n# define Float128 NS(Float128)\n# define Complex256 NS(Complex256)\n# define intp NS(intp)\n# define uintp NS(uintp)\n#endif\n\n/* There are several places in the code where an array of dimensions is */\n/* allocated statically. This is the size of that static allocation. */\n/* The array creation itself could have arbitrary dimensions but\n * all the places where static allocation is used would need to\n * be changed to dynamic (including inside of structures)\n */\n\n#define MAX_DIMS 32\n\n/* Used for Converter Functions \"O&\" code in ParseTuple */\n#define PY_FAIL 0\n#define PY_SUCCEED 1\n\n /* Helpful to distinguish what is installed */\n#define NDARRAY_VERSION 0x00090504\n\n\t/* Some platforms don't define bool, long long, or long double.\n\t Handle that here.\n\t */\n\n#ifdef PY_LONG_LONG\ntypedef PY_LONG_LONG longlong;\ntypedef unsigned PY_LONG_LONG ulonglong;\n# ifdef _MSC_VER\n# define LONGLONG_FMT \"I64d\"\n# define ULONGLONG_FMT \"I64u\"\n# define LONGLONG_SUFFIX(x) (x##i64)\n# define ULONGLONG_SUFFIX(x) (x##Ui64)\n# else\n\t/* #define LONGLONG_FMT \"lld\" Another possible variant\n #define ULONGLONG_FMT \"llu\"\n\n\t #define LONGLONG_FMT \"qd\" -- BSD perhaps?\n\t #define ULONGLONG_FMT \"qu\"\n\t*/\n# define LONGLONG_FMT \"Ld\"\n# define ULONGLONG_FMT \"Lu\"\n# define LONGLONG_SUFFIX(x) (x##LL)\n# define ULONGLONG_SUFFIX(x) (x##ULL)\n# endif\n#else\ntypedef long longlong;\ntypedef unsigned long ulonglong;\n# define LONGLONG_SUFFIX(x) (x##L)\n# define ULONGLONG_SUFFIX(x) (x##UL)\n#endif\n\ntypedef unsigned char Bool;\n#ifndef FALSE\n#define FALSE 0\n#endif\n#ifndef TRUE\n#define TRUE 1\n#endif\n\n#if SIZEOF_LONG_DOUBLE==SIZEOF_DOUBLE\n\ttypedef double longdouble;\n #define LONGDOUBLE_FMT \"g\"\n#else\n\ttypedef long double longdouble;\n #define LONGDOUBLE_FMT \"Lg\"\n#endif\n\n#ifndef Py_USING_UNICODE\n#error Must use Python with unicode enabled. \n#endif\n\n\ntypedef signed char byte;\ntypedef unsigned char ubyte;\n#ifndef _BSD_SOURCE\ntypedef unsigned short ushort;\ntypedef unsigned int uint;\ntypedef unsigned long ulong;\n#endif\n\ntypedef struct { float real, imag; } cfloat;\ntypedef struct { double real, imag; } cdouble;\ntypedef struct {longdouble real, imag;} clongdouble;\n\nenum PyArray_TYPES { PyArray_BOOL=0,\n PyArray_BYTE, PyArray_UBYTE,\n\t\t PyArray_SHORT, PyArray_USHORT,\n\t\t PyArray_INT, PyArray_UINT,\n\t\t\tPyArray_LONG, PyArray_ULONG,\n PyArray_LONGLONG, PyArray_ULONGLONG,\n\t\t\tPyArray_FLOAT, PyArray_DOUBLE, PyArray_LONGDOUBLE,\n\t\t\tPyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CLONGDOUBLE,\n\t\t\tPyArray_OBJECT=17,\n PyArray_STRING, PyArray_UNICODE,\n\t\t\tPyArray_VOID,\n\t\t\tPyArray_NTYPES,\n\t\t\tPyArray_NOTYPE,\n\t\t\tPyArray_USERDEF=256 /* leave room for characters */\n};\n\n\t/* basetype array priority */\n#define PyArray_PRIORITY 0.0\n#define PyArray_BIG_PRIORITY 0.1\n\t/* default subtype priority */\n#define PyArray_SUBTYPE_PRIORITY 1.0\n\n\t/* How many floating point types are there */\n#define PyArray_NUM_FLOATTYPE 3\n\n\n\t/* We need to match intp to a signed integer of the same size as\n\t a pointer variable. uintp to the equivalent unsigned integer\n\t*/\n\n\n\t/* These characters correspond to the array type and the\n\t struct module */\n\n\t/* except 'p' -- signed integer for pointer type */\n\nenum PyArray_TYPECHAR { PyArray_BOOLLTR = '?',\n\t\t\tPyArray_BYTELTR = 'b',\n\t\t\tPyArray_UBYTELTR = 'B',\n\t\t\tPyArray_SHORTLTR = 'h',\n\t\t\tPyArray_USHORTLTR = 'H',\n\t\t\tPyArray_INTLTR = 'i',\n\t\t\tPyArray_UINTLTR = 'I',\n\t\t\tPyArray_LONGLTR = 'l',\n\t\t\tPyArray_ULONGLTR = 'L',\n\t\t\tPyArray_LONGLONGLTR = 'q',\n\t\t\tPyArray_ULONGLONGLTR = 'Q',\n\t\t\tPyArray_FLOATLTR = 'f',\n\t\t\tPyArray_DOUBLELTR = 'd',\n\t\t\tPyArray_LONGDOUBLELTR = 'g',\n\t\t\tPyArray_CFLOATLTR = 'F',\n\t\t\tPyArray_CDOUBLELTR = 'D',\n\t\t\tPyArray_CLONGDOUBLELTR = 'G',\n\t\t\tPyArray_OBJECTLTR = 'O',\n\t\t\tPyArray_STRINGLTR = 'S',\n\t\t\tPyArray_STRINGLTR2 = 'a',\n\t\t\tPyArray_UNICODELTR = 'U',\n\t\t PyArray_VOIDLTR = 'V',\n\n\t\t\t/* No Descriptor, just a define -- this let's\n\t\t\t Python users specify an array of integers\n\t\t\t large enough to hold a pointer on the platform*/\n\t\t\tPyArray_INTPLTR = 'p',\n\t\t\tPyArray_UINTPLTR = 'P',\n\n\t\t\tPyArray_GENBOOLLTR ='b',\n\t\t\tPyArray_SIGNEDLTR = 'i',\n\t\t\tPyArray_UNSIGNEDLTR = 'u',\n\t\t\tPyArray_FLOATINGLTR = 'f',\n\t\t\tPyArray_COMPLEXLTR = 'c'\n};\n\ntypedef enum {\n\tPyArray_QUICKSORT=0,\n\tPyArray_HEAPSORT=1,\n\tPyArray_MERGESORT=2,\n\tPyArray_TIMSORT=3 /* the sort Python uses -- specialized */\n} PyArray_SORTKIND;\n#define PyArray_NSORTS PyArray_TIMSORT + 1\n\n\ntypedef enum {\n\tPyArray_NOSCALAR=0,\n\tPyArray_BOOL_SCALAR=1,\n\tPyArray_INTPOS_SCALAR=2,\n\tPyArray_INTNEG_SCALAR=3,\n\tPyArray_FLOAT_SCALAR=4,\n\tPyArray_COMPLEX_SCALAR=5,\n\tPyArray_OBJECT_SCALAR=6,\n} PyArray_SCALARKIND;\n\n\t/* Define bit-width array types and typedefs */\n\n#define MAX_INT8 127\n#define MIN_INT8 -128\n#define MAX_UINT8 255\n#define MAX_INT16 32767\n#define MIN_INT16 -32768\n#define MAX_UINT16 65535\n#define MAX_INT32 2147483647\n#define MIN_INT32 (-MAX_INT32 - 1)\n#define MAX_UINT32 4294967295U\n#define MAX_INT64 LONGLONG_SUFFIX(9223372036854775807)\n#define MIN_INT64 (-MAX_INT64 - LONGLONG_SUFFIX(1))\n#define MAX_UINT64 ULONGLONG_SUFFIX(18446744073709551615)\n#define MAX_INT128 LONGLONG_SUFFIX(85070591730234615865843651857942052864)\n#define MIN_INT128 (-MAX_INT128 - LONGLONG_SUFFIX(1))\n#define MAX_UINT128 ULONGLONG_SUFFIX(170141183460469231731687303715884105728)\n#define MAX_INT256 LONGLONG_SUFFIX(57896044618658097711785492504343953926634992332820282019728792003956564819967)\n#define MIN_INT256 (-MAX_INT256 - LONGLONG_SUFFIX(1))\n#define MAX_UINT256 ULONGLONG_SUFFIX(115792089237316195423570985008687907853269984665640564039457584007913129639935)\n\n\t/* Need to find the number of bits for each type and\n\t make definitions accordingly.\n\n\t C states that sizeof(char) == 1 by definition\n\n\t So, just using the sizeof keyword won't help.\n\n\t It also looks like Python itself uses sizeof(char) quite a\n\t bit, which by definition should be 1 all the time.\n\n\t Idea: Make Use of CHAR_BIT which should tell us how many\n\t BITS per CHARACTER\n\t*/\n\n\t/* Include platform definitions -- These are in the C89/90 standard */\n#include \n#define MAX_BYTE SCHAR_MAX\n#define MIN_BYTE SCHAR_MIN\n#define MAX_UBYTE UCHAR_MAX\n#define MAX_SHORT SHRT_MAX\n#define MIN_SHORT SHRT_MIN\n#define MAX_USHORT USHRT_MAX\n#define MAX_INT INT_MAX\n#ifndef INT_MIN\n#define INT_MIN (-INT_MAX - 1)\n#endif\n#define MIN_INT INT_MIN\n#define MAX_UINT UINT_MAX\n#define MAX_LONG LONG_MAX\n#define MIN_LONG LONG_MIN\n#define MAX_ULONG ULONG_MAX\n\n#define SIZEOF_LONGDOUBLE SIZEOF_LONG_DOUBLE\n#define SIZEOF_LONGLONG SIZEOF_LONG_LONG\n#define BITSOF_BOOL sizeof(Bool)*CHAR_BIT\n#define BITSOF_CHAR CHAR_BIT\n#define BITSOF_SHORT (SIZEOF_SHORT*CHAR_BIT)\n#define BITSOF_INT (SIZEOF_INT*CHAR_BIT)\n#define BITSOF_LONG (SIZEOF_LONG*CHAR_BIT)\n#define BITSOF_LONGLONG (SIZEOF_LONGLONG*CHAR_BIT)\n#define BITSOF_FLOAT (SIZEOF_FLOAT*CHAR_BIT)\n#define BITSOF_DOUBLE (SIZEOF_DOUBLE*CHAR_BIT)\n#define BITSOF_LONGDOUBLE (SIZEOF_LONGDOUBLE*CHAR_BIT)\n\n\n#if BITSOF_LONG == 8\n#define PyArray_INT8 PyArray_LONG\n#define PyArray_UINT8 PyArray_ULONG\n\ttypedef long Int8;\n\ttypedef unsigned long UInt8;\n#define STRBITSOF_LONG \"8\"\n#elif BITSOF_LONG == 16\n#define PyArray_INT16 PyArray_LONG\n#define PyArray_UINT16 PyArray_ULONG\n\ttypedef long Int16;\n\ttypedef unsigned long UInt16;\n#define STRBITSOF_LONG \"16\"\n#elif BITSOF_LONG == 32\n#define PyArray_INT32 PyArray_LONG\n#define PyArray_UINT32 PyArray_ULONG\n\ttypedef long Int32;\n\ttypedef unsigned long UInt32;\n\ttypedef unsigned long PyArray_UCS4;\n#define STRBITSOF_LONG \"32\"\n#elif BITSOF_LONG == 64\n#define PyArray_INT64 PyArray_LONG\n#define PyArray_UINT64 PyArray_ULONG\n\ttypedef long Int64;\n\ttypedef unsigned long UInt64;\n#define STRBITSOF_LONG \"64\"\n#elif BITSOF_LONG == 128\n#define PyArray_INT128 PyArray_LONG\n#define PyArray_UINT128 PyArray_ULONG\n\ttypedef long Int128;\n\ttypedef unsigned long UInt128;\n#define STRBITSOF_LONG \"128\"\n#endif\n\n#if BITSOF_LONGLONG == 8\n# ifndef PyArray_INT8\n# define PyArray_INT8 PyArray_LONGLONG\n# define PyArray_UINT8 PyArray_ULONGLONG\n\ttypedef longlong Int8;\n\ttypedef ulonglong UInt8;\n# endif\n# define MAX_LONGLONG MAX_INT8\n# define MIN_LONGLONG MIN_INT8\n# define MAX_ULONGLONG MAX_UINT8\n#define STRBITSOF_LONGLONG \"8\"\n#elif BITSOF_LONGLONG == 16\n# ifndef PyArray_INT16\n# define PyArray_INT16 PyArray_LONGLONG\n# define PyArray_UINT16 PyArray_ULONGLONG\n\ttypedef longlong Int16;\n\ttypedef ulonglong UInt16;\n# endif\n# define MAX_LONGLONG MAX_INT16\n# define MIN_LONGLONG MIN_INT16\n# define MAX_ULONGLONG MAX_UINT16\n#define STRBITSOF_LONGLONG \"16\"\n#elif BITSOF_LONGLONG == 32\n# ifndef PyArray_INT32\n# define PyArray_INT32 PyArray_LONGLONG\n# define PyArray_UINT32 PyArray_ULONGLONG\n\ttypedef longlong Int32;\n\ttypedef ulonglong UInt32;\n\ttypedef ulonglong PyArray_UCS4;\n# endif\n# define MAX_LONGLONG MAX_INT32\n# define MIN_LONGLONG MIN_INT32\n# define MAX_ULONGLONG MAX_UINT32\n#define STRBITSOF_LONGLONG \"32\"\n#elif BITSOF_LONGLONG == 64\n# ifndef PyArray_INT64\n# define PyArray_INT64 PyArray_LONGLONG\n# define PyArray_UINT64 PyArray_ULONGLONG\n\ttypedef longlong Int64;\n\ttypedef ulonglong UInt64;\n# endif\n# define MAX_LONGLONG MAX_INT64\n# define MIN_LONGLONG MIN_INT64\n# define MAX_ULONGLONG MAX_UINT64\n#define STRBITSOF_LONGLONG \"64\"\n#elif BITSOF_LONGLONG == 128\n# ifndef PyArray_INT128\n# define PyArray_INT128 PyArray_LONGLONG\n# define PyArray_UINT128 PyArray_ULONGLONG\n\ttypedef longlong Int128;\n\ttypedef ulonglong UInt128;\n# endif\n# define MAX_LONGLONG MAX_INT128\n# define MIN_LONGLONG MIN_INT128\n# define MAX_ULONGLONG MAX_UINT128\n#define STRBITSOF_LONGLONG \"128\"\n#elif BITSOF_LONGLONG == 256\n# define PyArray_INT256 PyArray_LONGLONG\n# define PyArray_UINT256 PyArray_ULONGLONG\n\ttypedef longlong Int256;\n\ttypedef ulonglong UInt256;\n# define MAX_LONGLONG MAX_INT256\n# define MIN_LONGLONG MIN_INT256\n# define MAX_ULONGLONG MAX_UINT256\n#define STRBITSOF_LONGLONG \"256\"\n#endif\n\n#if BITSOF_INT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_INT\n#define PyArray_UINT8 PyArray_UINT\n\ttypedef int Int8;\n\ttypedef unsigned int UInt8;\n#endif\n#define STRBITSOF_INT \"8\"\n#elif BITSOF_INT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_INT\n#define PyArray_UINT16 PyArray_UINT\n\ttypedef int Int16;\n\ttypedef unsigned int UInt16;\n#endif\n#define STRBITSOF_INT \"16\"\n#elif BITSOF_INT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_INT\n#define PyArray_UINT32 PyArray_UINT\n\ttypedef int Int32;\n\ttypedef unsigned int UInt32;\n\ttypedef unsigned int PyArray_UCS4;\n#endif\n#define STRBITSOF_INT \"32\"\n#elif BITSOF_INT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_INT\n#define PyArray_UINT64 PyArray_UINT\n\ttypedef int Int64;\n\ttypedef unsigned int UInt64;\n#endif\n#define STRBITSOF_INT \"64\"\n#elif BITSOF_INT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_INT\n#define PyArray_UINT128 PyArray_UINT\n\ttypedef int Int128;\n\ttypedef unsigned int UInt128;\n#endif\n#define STRBITSOF_INT \"128\"\n#endif\n\n#if BITSOF_SHORT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_SHORT\n#define PyArray_UINT8 PyArray_USHORT\n\ttypedef short Int8;\n\ttypedef unsigned short UInt8;\n#endif\n#define STRBITSOF_SHORT \"8\"\n#elif BITSOF_SHORT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_SHORT\n#define PyArray_UINT16 PyArray_USHORT\n\ttypedef short Int16;\n\ttypedef unsigned short UInt16;\n#endif\n#define STRBITSOF_SHORT \"16\"\n#elif BITSOF_SHORT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_SHORT\n#define PyArray_UINT32 PyArray_USHORT\n\ttypedef short Int32;\n\ttypedef unsigned short UInt32;\n\ttypedef unsigned short PyArray_UCS4;\n#endif\n#define STRBITSOF_SHORT \"32\"\n#elif BITSOF_SHORT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_SHORT\n#define PyArray_UINT64 PyArray_USHORT\n\ttypedef short Int64;\n\ttypedef unsigned short UInt64;\n#endif\n#define STRBITSOF_SHORT \"64\"\n#elif BITSOF_SHORT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_SHORT\n#define PyArray_UINT128 PyArray_USHORT\n\ttypedef short Int128;\n\ttypedef unsigned short UInt128;\n#endif\n#define STRBITSOF_SHORT \"128\"\n#endif\n\n\n#if BITSOF_CHAR == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_BYTE\n#define PyArray_UINT8 PyArray_UBYTE\n\ttypedef signed char Int8;\n\ttypedef unsigned char UInt8;\n#endif\n#define STRBITSOF_CHAR \"8\"\n#elif BITSOF_CHAR == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_BYTE\n#define PyArray_UINT16 PyArray_UBYTE\n\ttypedef signed char Int16;\n\ttypedef unsigned char UInt16;\n#endif\n#define STRBITSOF_CHAR \"16\"\n#elif BITSOF_CHAR == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_BYTE\n#define PyArray_UINT32 PyArray_UBYTE\n\ttypedef signed char Int32;\n\ttypedef unsigned char UInt32;\n\ttypedef unsigned char PyArray_UCS4;\n#endif\n#define STRBITSOF_CHAR \"32\"\n#elif BITSOF_CHAR == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_BYTE\n#define PyArray_UINT64 PyArray_UBYTE\n\ttypedef signed char Int64;\n\ttypedef unsigned char UInt64;\n#endif\n#define STRBITSOF_CHAR \"64\"\n#elif BITSOF_CHAR == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_BYTE\n#define PyArray_UINT128 PyArray_UBYTE\n\ttypedef signed char Int128;\n\ttypedef unsigned char UInt128;\n#endif\n#define STRBITSOF_CHAR \"128\"\n#endif\n\n\n\n#if BITSOF_DOUBLE == 16\n#define STRBITSOF_DOUBLE \"16\"\n#define STRBITSOF_CDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_DOUBLE\n#define PyArray_COMPLEX32 PyArray_CDOUBLE\n\ttypedef double Float16;\n\ttypedef cdouble Complex32;\n#endif\n#elif BITSOF_DOUBLE == 32\n#define STRBITSOF_DOUBLE \"32\"\n#define STRBITSOF_CDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_DOUBLE\n#define PyArray_COMPLEX64 PyArray_CDOUBLE\n\ttypedef double Float32;\n\ttypedef cdouble Complex64;\n#endif\n#elif BITSOF_DOUBLE == 64\n#define STRBITSOF_DOUBLE \"64\"\n#define STRBITSOF_CDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_DOUBLE\n#define PyArray_COMPLEX128 PyArray_CDOUBLE\n\ttypedef double Float64;\n\ttypedef cdouble Complex128;\n#endif\n#elif BITSOF_DOUBLE == 80\n#define STRBITSOF_DOUBLE \"80\"\n#define STRBITSOF_CDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_DOUBLE\n#define PyArray_COMPLEX160 PyArray_CDOUBLE\n\ttypedef double Float80;\n\ttypedef cdouble Complex160;\n#endif\n#elif BITSOF_DOUBLE == 96\n#define STRBITSOF_DOUBLE \"96\"\n#define STRBITSOF_CDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_DOUBLE\n#define PyArray_COMPLEX192 PyArray_CDOUBLE\n\ttypedef double Float96;\n\ttypedef cdouble Complex192;\n#endif\n#elif BITSOF_DOUBLE == 128\n#define STRBITSOF_DOUBLE \"128\"\n#define STRBITSOF_CDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_DOUBLE\n#define PyArray_COMPLEX256 PyArray_CDOUBLE\n\ttypedef double Float128;\n\ttypedef cdouble Complex256;\n#endif\n#endif\n\n\n\n#if BITSOF_FLOAT == 16\n#define STRBITSOF_FLOAT \"16\"\n#define STRBITSOF_CFLOAT \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_FLOAT\n#define PyArray_COMPLEX32 PyArray_CFLOAT\n\ttypedef float Float16;\n\ttypedef cfloat Complex32;\n#endif\n#elif BITSOF_FLOAT == 32\n#define STRBITSOF_FLOAT \"32\"\n#define STRBITSOF_CFLOAT \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_FLOAT\n#define PyArray_COMPLEX64 PyArray_CFLOAT\n\ttypedef float Float32;\n\ttypedef cfloat Complex64;\n#endif\n#elif BITSOF_FLOAT == 64\n#define STRBITSOF_FLOAT \"64\"\n#define STRBITSOF_CFLOAT \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_FLOAT\n#define PyArray_COMPLEX128 PyArray_CFLOAT\n\ttypedef float Float64;\n\ttypedef cfloat Complex128;\n#endif\n#elif BITSOF_FLOAT == 80\n#define STRBITSOF_FLOAT \"80\"\n#define STRBITSOF_CFLOAT \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_FLOAT\n#define PyArray_COMPLEX160 PyArray_CFLOAT\n\ttypedef float Float80;\n\ttypedef cfloat Complex160;\n#endif\n#elif BITSOF_FLOAT == 96\n#define STRBITSOF_FLOAT \"96\"\n#define STRBITSOF_CFLOAT \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_FLOAT\n#define PyArray_COMPLEX192 PyArray_CFLOAT\n\ttypedef float Float96;\n\ttypedef cfloat Complex192;\n#endif\n#elif BITSOF_FLOAT == 128\n#define STRBITSOF_FLOAT \"128\"\n#define STRBITSOF_CFLOAT \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_FLOAT\n#define PyArray_COMPLEX256 PyArray_CFLOAT\n\ttypedef float Float128;\n\ttypedef cfloat Complex256;\n#endif\n#endif\n\n\n#if BITSOF_LONGDOUBLE == 16\n#define STRBITSOF_LONGDOUBLE \"16\"\n#define STRBITSOF_CLONGDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX32 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float16;\n\ttypedef clongdouble Complex32;\n#endif\n#elif BITSOF_LONGDOUBLE == 32\n#define STRBITSOF_LONGDOUBLE \"32\"\n#define STRBITSOF_CLONGDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX64 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float32;\n\ttypedef clongdouble Complex64;\n#endif\n#elif BITSOF_LONGDOUBLE == 64\n#define STRBITSOF_LONGDOUBLE \"64\"\n#define STRBITSOF_CLONGDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX128 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float64;\n\ttypedef clongdouble Complex128;\n#endif\n#elif BITSOF_LONGDOUBLE == 80\n#define STRBITSOF_LONGDOUBLE \"80\"\n#define STRBITSOF_CLONGDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX160 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float80;\n\ttypedef clongdouble Complex160;\n#endif\n#elif BITSOF_LONGDOUBLE == 96\n#define STRBITSOF_LONGDOUBLE \"96\"\n#define STRBITSOF_CLONGDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX192 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float96;\n\ttypedef clongdouble Complex192;\n#endif\n#elif BITSOF_LONGDOUBLE == 128\n#define STRBITSOF_LONGDOUBLE \"128\"\n#define STRBITSOF_CLONGDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX256 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float128;\n\ttypedef clongdouble Complex256;\n#endif\n#elif BITSOF_LONGDOUBLE == 256\n#define STRBITSOF_LONGDOUBLE \"256\"\n#define STRBITSOF_CLONGDOUBLE \"512\"\n#define PyArray_FLOAT256 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX512 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float256;\n\ttypedef clongdouble Complex512;\n#endif\n\n\t/* End of typedefs for numarray style bit-width names */\n\n/* This is to typedef Intp to the appropriate pointer size for this platform.\n * Py_intptr_t, Py_uintptr_t are defined in pyport.h. */\ntypedef Py_intptr_t intp;\ntypedef Py_uintptr_t uintp;\n#define SIZEOF_INTP SIZEOF_PY_INTPTR_T\n#define SIZEOF_UINTP SIZEOF_PY_INTPTR_T\n\n#if PY_VERSION_HEX >= 0x02050000\n#define _int_or_ssize_t Py_ssize_t\n#else\n#define _int_or_ssize_t int\n#endif\n\n#define INTP_FMT \"d\"\n\n#if SIZEOF_PY_INTPTR_T == SIZEOF_INT\n\t#define PyArray_INTP PyArray_INT\n\t#define PyArray_UINTP PyArray_UINT\n #define PyIntpArrType_Type PyIntArrType_Type\n #define PyUIntpArrType_Type PyUIntArrType_Type\n\t#define MAX_INTP MAX_INT\n\t#define MIN_INTP MIN_INT\n\t#define MAX_UINTP MAX_UINT\n#elif SIZEOF_PY_INTPTR_T == SIZEOF_LONG\n\t#define PyArray_INTP PyArray_LONG\n\t#define PyArray_UINTP PyArray_ULONG\n #define PyIntpArrType_Type PyLongArrType_Type\n #define PyUIntpArrType_Type PyULongArrType_Type\n\t#define MAX_INTP MAX_LONG\n\t#define MIN_INTP MIN_LONG\n\t#define MAX_UINTP MAX_ULONG\n #undef INTP_FMT\n #define INTP_FMT \"ld\"\n#elif defined(PY_LONG_LONG) && (SIZEOF_PY_INTPTR_T == SIZEOF_LONG_LONG)\n\t#define PyArray_INTP PyArray_LONGLONG\n\t#define PyArray_UINTP PyArray_ULONGLONG\n #define PyIntpArrType_Type PyLongLongArrType_Type\n #define PyUIntpArrType_Type PyULongLongArrType_Type\n\t#define MAX_INTP MAX_LONGLONG\n\t#define MIN_INTP MIN_LONGLONG\n\t#define MAX_UINTP MAX_ULONGLONG\n #undef INTP_FMT\n #define INTP_FMT \"Ld\"\n#endif\n\n#define ERR(str) fprintf(stderr, #str); fflush(stderr);\n#define ERR2(str) fprintf(stderr, str); fflush(stderr);\n\n /* Macros to define how array, and dimension/strides data is\n allocated.\n */\n\n /* Data buffer */\n#define PyDataMem_NEW(size) ((char *)malloc(size))\n /* #define PyArrayMem_NEW(size) PyMem_NEW(char, size)*/\n#define PyDataMem_FREE(ptr) free(ptr)\n /* #define PyArrayMem_FREE(ptr) PyMem_Free(ptr) */\n#define PyDataMem_RENEW(ptr,size) ((char *)realloc(ptr,size))\n\n#define PyArray_USE_PYMEM 0\n\n#if PyArray_USE_PYMEM == 1\n#define _pya_malloc PyObject_Malloc\n#define _pya_free PyObject_Free\n#define _pya_realloc PyObject_Realloc\n#else\n#define _pya_malloc malloc\n#define _pya_free free\n#define _pya_realloc realloc\n#endif\n\n/* Dimensions and strides */\n#define PyDimMem_NEW(size) ((intp *)_pya_malloc(size*sizeof(intp)))\n#define PyDimMem_FREE(ptr) _pya_free(ptr)\n#define PyDimMem_RENEW(ptr,size) ((intp *)_pya_realloc(ptr,size*sizeof(intp)))\n\n\n /* These must deal with unaligned and swapped data if necessary */\ntypedef PyObject * (PyArray_GetItemFunc) (void *, void *);\ntypedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);\n\ntypedef void (PyArray_CopySwapNFunc)(void *, void *, intp, int, int);\ntypedef void (PyArray_CopySwapFunc)(void *, void *, int, int);\ntypedef Bool (PyArray_NonzeroFunc)(void *, void *);\n\n\n /* These assume aligned and notswapped data -- a buffer will be\n used before or contiguous data will be obtained\n */\ntypedef int (PyArray_CompareFunc)(const void *, const void *, void *);\ntypedef int (PyArray_ArgFunc)(void*, intp, intp*, void *);\ntypedef void (PyArray_DotFunc)(void *, intp, void *, intp, void *, intp,\n\t\t\t void *);\ntypedef void (PyArray_VectorUnaryFunc)(void *, void *, intp, void *, void *);\ntypedef int (PyArray_ScanFunc)(FILE *, void *, void *, void *);\ntypedef int (PyArray_FromStrFunc)(char *, void *, char **, void *);\n\ntypedef int (PyArray_FillFunc)(void *, intp, void *);\n\ntypedef int (PyArray_SortFunc)(void *, intp, void *);\ntypedef int (PyArray_ArgSortFunc)(void *, intp *, intp, void *);\n\ntypedef int (PyArray_FillWithScalarFunc)(void *, intp, void *, void *);\n\ntypedef struct {\n intp *ptr;\n int len;\n} PyArray_Dims;\n\ntypedef struct {\n\t/* Functions to cast to all other standard types*/\n\tPyArray_VectorUnaryFunc *cast[PyArray_NTYPES];\n\n\t/* Functions to get and set items with standard\n\t Python types -- not array scalars */\n\tPyArray_GetItemFunc *getitem;\n\tPyArray_SetItemFunc *setitem;\n\n\t/* Copy and/or swap data. Memory areas may not overlap */\n\t/* Use memmove first if they might */\n\tPyArray_CopySwapNFunc *copyswapn;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Function to compare items */\n\tPyArray_CompareFunc *compare;\n\n\t/* Function to select largest */\n\tPyArray_ArgFunc *argmax;\n\n\t/* Function to compute dot product */\n\tPyArray_DotFunc\t*dotfunc;\n\n\t/* Function to scan an ASCII file and\n\t place a single value plus possible separator */\n\tPyArray_ScanFunc *scanfunc;\n\n\t/* Function to read a single value from a string */\n\t/* and adjust the pointer */\n\tPyArray_FromStrFunc *fromstr;\n\n\t/* Function to determine if data is zero or not */\n\tPyArray_NonzeroFunc *nonzero;\n\n\t/* Used for arange */\n\tPyArray_FillFunc *fill;\n\n\t/* Function to fill arrays with scalar values */\n\tPyArray_FillWithScalarFunc *fillwithscalar;\n\n\t/* Sorting functions */\n\tPyArray_SortFunc *sort[PyArray_NSORTS];\n\tPyArray_ArgSortFunc *argsort[PyArray_NSORTS];\n\n} PyArray_ArrFuncs;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tPyTypeObject *typeobj; /* the type object representing an\n\t\t\t\t intance of this type */\n\tchar kind; /* kind for this type */\n\tchar type; /* unique-character representing this type */\n\tchar byteorder; /* '>' (big), '<' (little), '|'\n\t\t\t\t (not-applicable), or '=' (native). */\n char hasobject; /* non-zero if it has object arrays in fields */\n\tint type_num; /* number representing this type */\n\tint elsize; /* element size for this type */\n\tint alignment; /* alignment needed for this type */\n\tstruct _arr_descr\t\t\t\t\t\\\n\t*subarray; /* Non-NULL if this type is\n\t\t\t\t is an array (C-contiguous)\n\t\t\t\t of some other type\n\t\t\t\t*/\n\tPyObject *fields; /* The fields dictionary for this type */\n\t /* For statically defined descr this\n\t\t\t\t is always Py_None */\n\n\tPyArray_ArrFuncs *f; /* a table of functions specific for each\n\t\t\t\t basic data descriptor */\n} PyArray_Descr;\n\ntypedef struct _arr_descr {\n\tPyArray_Descr *base;\n\tPyObject *shape; /* a tuple */\n} PyArray_ArrayDescr;\n\n\n/*\n The main array object structure. It is recommended to use the macros\n defined below (PyArray_DATA and friends) access fields here, instead\n of the members themselves.\n */\n\ntypedef struct PyArrayObject {\n\tPyObject_HEAD\n\tchar *data; /* pointer to raw data buffer */\n\tint nd; /* number of dimensions, also called ndim */\n\tintp *dimensions; /* size in each dimension */\n intp *strides; /* bytes to jump to get to the\n\t\t\t\t next element in each dimension */\n\tPyObject *base; /* This object should be decref'd\n\t\t\t\t upon deletion of array */\n\t /* For views it points to the original array */\n\t /* For creation from buffer object it points\n\t\t\t\t to an object that shold be decref'd on\n\t\t\t\t deletion */\n\t /* For UPDATEIFCOPY flag this is an array\n\t\t\t\t to-be-updated upon deletion of this one */\n\tPyArray_Descr *descr; /* Pointer to type structure */\n\tint flags; /* Flags describing array -- see below*/\n\tPyObject *weakreflist; /* For weakreferences */\n} PyArrayObject;\n\n\n#define fortran fortran_ /* For some compilers */\n\n/* Mirrors buffer object to ptr */\n\ntypedef struct {\n PyObject_HEAD\n PyObject *base;\n void *ptr;\n intp len;\n int flags;\n} PyArray_Chunk;\n\n/* Array flags */\n\n/* Means c-style contiguous (last index varies the fastest). The\n data elements right after each other. */\n#define CONTIGUOUS 0x0001\n/* set if array is a contiguous Fortran array: the first index\n varies the fastest in memory (strides array is reverse of\n C-contiguous array)*/\n#define FORTRAN 0x0002\n\n/*\n Note: all 0-d arrays are CONTIGUOUS and FORTRAN contiguous. If a\n 1-d array is CONTIGUOUS it is also FORTRAN contiguous\n*/\n\n/* If set, the array owns the data: it will be free'd when the array\n is deleted. */\n#define OWNDATA 0x0004\n#define OWN_DATA OWNDATA\n\n/* An array never has these three set; they're only used as parameter\n flags to the the various FromAny functions */\n/* Cause a cast to occur regardless of whether or not it is safe. */\n#define FORCECAST 0x0010\n/* Always copy the array. Returned arrays are always CONTIGUOUS, ALIGNED,\n and WRITEABLE. */\n#define ENSURECOPY 0x0020\n/* Make sure the returned array is an ndarray or a bigndarray */\n#define ENSUREARRAY 0x0040\n\n/* Array data is aligned on the appropiate memory address for the\n type stored (e.g., an array of doubles (8 bytes each) starts on\n a memory address that's a multiple of 8) */\n#define ALIGNED 0x0100\n/* Array data has the native endianness */\n#define NOTSWAPPED 0x0200\n/* Array data is writeable */\n#define WRITEABLE 0x0400\n/* If this flag is set, then base contains a pointer to an array of\n the same size that should be updated with the current contents of\n this array when this array is deallocated\n*/\n#define UPDATEIFCOPY 0x1000\n\n\n#define BEHAVED_FLAGS ALIGNED | WRITEABLE\n#define BEHAVED_NS_FLAGS ALIGNED | WRITEABLE | NOTSWAPPED\n#define CARRAY_FLAGS CONTIGUOUS | BEHAVED_FLAGS\n#define CARRAY_FLAGS_RO CONTIGUOUS | ALIGNED\n#define FARRAY_FLAGS FORTRAN | BEHAVED_FLAGS\n#define FARRAY_FLAGS_RO FORTRAN | ALIGNED\n#define DEFAULT_FLAGS CARRAY_FLAGS\n\n#define UPDATE_ALL_FLAGS CONTIGUOUS | FORTRAN | ALIGNED\n\n\n/* Size of internal buffers used for alignment */\n#define PyArray_BUFSIZE 10000\n#define PyArray_MIN_BUFSIZE 5\n#define PyArray_MAX_BUFSIZE 100000000\n\n/*\n * C API: consists of Macros and functions. The MACROS are defined here.\n */\n\n\n#define PyArray_CHKFLAGS(m, FLAGS) \\\n\t((((PyArrayObject *)(m))->flags & (FLAGS)) == (FLAGS))\n#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, CONTIGUOUS)\n#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, WRITEABLE)\n#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, ALIGNED)\n\n#ifndef MAX\n#define MAX(a,b) (((a)>(b))?(a):(b))\n#endif\n#ifndef MIN\n#define MIN(a,b) (((a)<(b))?(a):(b))\n#endif\n\n/* Useful if a and b have to be evaluated. */\n\n#define tMAX(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_>_y_ ? _x_ : _y_}\n#define tMIN(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_<_y_ ? _x_ : _y_}\n\n#if defined(ALLOW_THREADS)\n#define BEGIN_THREADS_DEF PyThreadState *_save;\n#define BEGIN_THREADS _save = PyEval_SaveThread();\n#define END_THREADS PyEval_RestoreThread(_save);\n#define ALLOW_C_API_DEF PyGILState_STATE __save__;\n#define ALLOW_C_API __save__ = PyGILState_Ensure();\n#define DISABLE_C_API PyGILState_Release(__save__);\n#else\n#define BEGIN_THREADS_DEF\n#define BEGIN_THREADS\n#define END_THREADS\n#define ALLOW_C_API_DEF\n#define\tALLOW_C_API\n#define\tDISABLE_C_API\n#endif\n\n\n\n\ntypedef struct {\n PyObject_HEAD\n\tint nd_m1; /* number of dimensions - 1 */\n intp\t\t index, size;\n\tintp coordinates[MAX_DIMS];/* N-dimensional loop */\n intp dims_m1[MAX_DIMS]; /* ao->dimensions - 1 */\n\tintp strides[MAX_DIMS]; /* ao->strides or fake */\n\tintp backstrides[MAX_DIMS];/* how far to jump back */\n\tintp factors[MAX_DIMS]; /* shape factors */\n\tPyArrayObject *ao;\n\tchar *dataptr; /* pointer to current item*/\n Bool contiguous;\n} PyArrayIterObject;\n\n\n/* Iterator API */\n#define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type)\n\n#define PyArray_ITER_RESET(it) {\t\t\t\t\t\\\n\tit->index = 0;\t\t\t\t\t\t \\\n\tit->dataptr = it->ao->data;\t\t\t\t\t\\\n\tmemset(it->coordinates, 0, (it->nd_m1+1)*sizeof(intp));\t\t\\\n}\n\n#define _PyArray_ITER_NEXT1(it) {\t\t\\\n\t\tit->dataptr += it->strides[0];\t\\\n\t\tit->coordinates[0]++;\t\t\\\n\t}\n\n#define _PyArray_ITER_NEXT2(it) {\t\t\t\t\t\\\n\t\tif (it->coordinates[1] < it->dims_m1[1]) {\t\t\\\n\t\t\tit->coordinates[1]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->coordinates[1] = 0;\t\t\t\t\\\n\t\t\tit->coordinates[0]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[0] -\t\t\t\\\n\t\t\t\tit->backstrides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_NEXT(it) {\t\t\t\t\t\t\\\n\tit->index++;\t\t\t\t\t\t \\\n if (it->nd_m1 == 0) {\t\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT1(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse if (it->contiguous) it->dataptr += it->ao->descr->elsize; \\\n\telse if (it->nd_m1 == 1) {\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT2(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse {\t\t\t\t\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_ >= 0; _i_--) {\t\t\\\n\t\t\tif (it->coordinates[_i_] <\t\t\t\\\n\t\t\t it->dims_m1[_i_]) {\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_]++;\t\t\t\\\n\t\t\t\tit->dataptr += it->strides[_i_];\t\\\n\t\t\t\tbreak;\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t\telse {\t\t\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_] = 0;\t\t\\\n\t\t\t\tit->dataptr -= it->backstrides[_i_];\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_GOTO(it, destination) {\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tit->index = 0;\t\t\t\t\t\t\\\n\t\tit->dataptr = it->ao->data;\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_>=0; _i_--) {\t\t\t\\\n\t\t\tit->dataptr += destination[_i_] *\t\t\\\n\t\t\t\tit->strides[_i_];\t\t\t\\\n\t\t\tit->coordinates[_i_] = destination[_i_];\t\\\n\t\t\tit->index += destination[_i_] *\t\t\t\\\n\t\t\t\t( _i_==it->nd_m1 ? 1 :\t\t\t\\\n\t\t\t\t it->dims_m1[i+1]+1) ;\t\t \\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_GOTO1D(it, ind) { \\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tintp _lind_ = (intp) (ind);\t\t\t\t\\\n\t\tit->index = _lind_;\t\t\t\t\t\\\n if (it->nd_m1 == 0) { \\\n it->dataptr = it->ao->data + (ind) * \\\n it->strides[0]; \\\n } \\\n else if (it->contiguous) \\\n\t\t\tit->dataptr = it->ao->data + (ind) *\t\t\\\n\t\t\t\tit->ao->descr->elsize;\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->dataptr = it->ao->data;\t\t\t\\\n\t\t\tfor (_i_ = 0; _i_<=it->nd_m1; _i_++) {\t\t\\\n\t\t\t\tit->dataptr += (_lind_ / it->factors[_i_]) \\\n\t\t\t\t\t* it->strides[_i_];\t\t\\\n\t\t\t\t_lind_ %= it->factors[_i_];\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_DATA(it) ((PyArrayIterObject *)it)->dataptr\n\n\n/*\n Any object passed to PyArray_Broadcast must be binary compatible with\n this structure.\n*/\n\ntypedef struct {\n\tPyObject_HEAD\n\n\tint numiter; /* number of iters */\n\tintp size; /* broadcasted size */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* iterators */\n} PyArrayMultiIterObject;\n\n#define PyArray_MultiIter_RESET(multi) {\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index = 0;\t\t\t\t \\\n\t\tfor (_mi_ = 0; _mi_ < _mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_RESET(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_NEXT(multi) {\t\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index += 1;\t\t\t\t \\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_NEXT(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_GOTO(multi, dest) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO(_mul_->iters[_mi_], dest);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_GOTO1D(multi, ind) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO1D(_mul_->iters[_mi_], ind);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_DATA(multi, i) \\\n\t((PyArrayMultiIterObject *)multi)->iters[i]->dataptr\n\n#define PyArray_MultiIter_SIZE(multi) \\\n\t((PyArrayMultiIterObject *)multi)->size;\n\n\n/* Store the information needed for fancy-indexing over an array */\n\ntypedef struct {\n\tPyObject_HEAD\n\t/* Multi-iterator portion --- needs to be present in this order to\n\t work with PyArray_Broadcast */\n\n\tint numiter; /* number of index-array\n\t\t\t\t\t\t\t iterators */\n\tintp size; /* size of broadcasted\n\t\t\t\t\t\t\t result */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* index object\n\t\t\t\t\t\t\t iterators */\n\tPyArrayIterObject *ait; /* flat Iterator for\n\t\t\t\t\t\t\t underlying array */\n\n\t/* flat iterator for subspace (when numiter < nd) */\n\tPyArrayIterObject *subspace;\n\n\t/* if subspace iteration, then this is the array of\n\t axes in the underlying array represented by the\n\t index objects */\n\tint iteraxes[MAX_DIMS];\n\t/* if subspace iteration, the these are the coordinates\n\t to the start of the subspace.\n\t*/\n\tintp bscoord[MAX_DIMS];\n\n\tPyObject *indexobj; /* reference to\n\t\t\t\t\t\t\t creating obj */\n\tint view;\n\tint consec;\n\tchar *dataptr;\n\n} PyArrayMapIterObject;\n\n/* All sorts of useful ways to look into a PyArrayObject.\n These are the recommended over casting to PyArrayObject and accessing\n the members directly.\n */\n\n#define PyArray_NDIM(obj) (((PyArrayObject *)(obj))->nd)\n#define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || PyArray_CHKFLAGS(m, CONTIGUOUS) || \\\n\t\t\t\t PyArray_CHKFLAGS(m, FORTRAN))\n#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, FORTRAN) && (PyArray_NDIM(m) > 1))\n#define FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, FORTRAN) ? FORTRAN : 0))\n#define PyArray_DATA(obj) ((void *)(((PyArrayObject *)(obj))->data))\n#define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data)\n#define PyArray_DIMS(obj) (((PyArrayObject *)(obj))->dimensions)\n#define PyArray_STRIDES(obj) (((PyArrayObject *)(obj))->strides)\n#define PyArray_DIM(obj,n) (((PyArrayObject *)(obj))->dimensions[n])\n#define PyArray_STRIDE(obj,n) (((PyArrayObject *)(obj))->strides[n])\n#define PyArray_BASE(obj) (((PyArrayObject *)(obj))->base)\n#define PyArray_DESCR(obj) (((PyArrayObject *)(obj))->descr)\n#define PyArray_FLAGS(obj) (((PyArrayObject *)(obj))->flags)\n#define PyArray_ITEMSIZE(obj) (((PyArrayObject *)(obj))->descr->elsize)\n#define PyArray_TYPE(obj) (((PyArrayObject *)(obj))->descr->type_num)\n#define PyArray_GETITEM(obj,itemptr)\t\t\t\\\n\t((PyArrayObject *)(obj))->descr->f->getitem((char *)itemptr,\t\\\n\t\t\t\t\t\t (PyArrayObject *)obj);\n#define PyArray_SETITEM(obj,itemptr,v)\t\t\t\t\t\\\n\t(obj)->descr->f->setitem((PyObject *)v,(char *)(itemptr),\t\t\\\n\t\t\t (PyArrayObject *)(obj));\n\n\n#define PyTypeNum_ISBOOL(type) (type == PyArray_BOOL)\n#define PyTypeNum_ISUNSIGNED(type) ((type == PyArray_UBYTE) || \\\n\t\t\t\t (type == PyArray_USHORT) || \\\n\t\t\t\t (type == PyArray_UINT) ||\t\\\n\t\t\t\t (type == PyArray_ULONG) || \\\n\t\t\t\t (type == PyArray_ULONGLONG))\n\n#define PyTypeNum_ISSIGNED(type) ((type == PyArray_BYTE) ||\t\\\n\t\t\t (type == PyArray_SHORT) ||\t\\\n\t\t\t (type == PyArray_INT) ||\t\\\n\t\t\t (type == PyArray_LONG) ||\t\\\n\t\t\t (type == PyArray_LONGLONG))\n\n#define PyTypeNum_ISINTEGER(type) ((type >= PyArray_BYTE) &&\t\\\n\t\t\t\t(type <= PyArray_ULONGLONG))\n\n#define PyTypeNum_ISFLOAT(type) ((type >= PyArray_FLOAT) && \\\n\t\t\t (type <= PyArray_LONGDOUBLE))\n\n#define PyTypeNum_ISNUMBER(type) (type <= PyArray_CLONGDOUBLE)\n\n#define PyTypeNum_ISSTRING(type) ((type == PyArray_UCHAR) || \\\n\t\t\t (type == PyArray_UNICODE))\n\n#define PyTypeNum_ISCOMPLEX(type) ((type >= PyArray_CFLOAT) && \\\n\t\t\t\t(type <= PyArray_CLONGDOUBLE))\n\n#define PyTypeNum_ISPYTHON(type) ((type == PyArray_LONG) || \\\n\t\t\t\t (type == PyArray_DOUBLE) ||\t\\\n\t\t\t\t (type == PyArray_CDOUBLE) ||\t\\\n\t\t (type == PyArray_BOOL) || \\\n\t\t\t\t (type == PyArray_OBJECT ))\n\n#define PyTypeNum_ISFLEXIBLE(type) ((type>=PyArray_STRING) && \\\n\t\t\t\t (type<=PyArray_VOID))\n\n#define PyTypeNum_ISUSERDEF(type) ((type >= PyArray_USERDEF) && \\\n\t\t\t\t (type < PyArray_USERDEF+\\\n\t\t\t\t PyArray_NUMUSERTYPES))\n\n#define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \\\n PyTypeNum_ISUSERDEF(type))\n\n#define PyTypeNum_ISOBJECT(type) ((type) == PyArray_OBJECT)\n\n#define _PyADt(o) ((PyArray_Descr *)o)->type_num\n#define PyDescr_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj))\n#define PyDescr_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(_PyADt(obj))\n#define PyDescr_ISSIGNED(obj) PyTypeNum_ISSIGNED(_PyADt(obj))\n#define PyDescr_ISINTEGER(obj) PyTypeNum_ISINTEGER(_PyADt(obj))\n#define PyDescr_ISFLOAT(obj) PyTypeNum_ISFLOAT(_PyADt(obj))\n#define PyDescr_ISNUMBER(obj) PyTypeNum_ISNUMBER(_PyADt(obj))\n#define PyDescr_ISSTRING(obj) PyTypeNum_ISSTRING(_PyADt(obj))\n#define PyDescr_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(_PyADt(obj))\n#define PyDescr_ISPYTHON(obj) PyTypeNum_ISPYTHON(_PyADt(obj))\n#define PyDescr_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(_PyADt(obj))\n#define PyDescr_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(_PyADt(obj))\n#define PyDescr_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(_PyADt(obj))\n#define PyDescr_ISOBJECT(obj) PyTypeNum_ISOBJECT(_PyADt(obj))\n#undef _PyAD\n\n#define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))\n#define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))\n#define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))\n#define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))\n#define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))\n#define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))\n#define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj))\n#define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))\n#define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))\n#define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))\n#define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))\n\n#define PyArray_LITTLE '<'\n#define PyArray_BIG '>'\n#define PyArray_NATIVE '='\n#define PyArray_SWAP 's'\n#define PyArray_IGNORE '|'\n\n#ifdef WORDS_BIGENDIAN\n#define PyArray_NATBYTE PyArray_BIG\n#define PyArray_OPPBYTE PyArray_LITTLE\n#else\n#define PyArray_NATBYTE PyArray_LITTLE\n#define PyArray_OPPBYTE PyArray_BIG\n#endif\n\n#define PyArray_ISNBO(arg) ((arg) != PyArray_OPPBYTE)\n#define PyArray_IsNativeByteOrder PyArray_ISNBO\n#define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)\n\n#define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) &&\t\\\n\t\t\t\t PyArray_ISNOTSWAPPED(m))\n#define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS)\n#define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS_RO)\n#define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS)\n#define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS_RO)\n#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, BEHAVED_FLAGS)\n#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, ALIGNED)\n\n\n\n/* This is the form of the struct that's returned pointed by the\n PyCObject attribute of an array __array_struct__. See\n http://numeric.scipy.org/array_interface.html for the full\n documentation. */\ntypedef struct {\n int version; /* contains the integer 2 as a sanity check */\n int nd; /* number of dimensions */\n char typekind; /* kind in array --- character code of typestr */\n int itemsize; /* size of each element */\n int flags; /* how should be data interpreted. Valid\n flags are CONTIGUOUS (1), FORTRAN (2),\n ALIGNED (0x100), NOTSWAPPED (0x200), and\n WRITEABLE (0x400)*/\n intp *shape; /* A length-nd array of shape information */\n intp *strides; /* A length-nd array of stride information */\n void *data; /* A pointer to the first element of the array */\n} PyArrayInterface;\n\n/* Includes the \"function\" C-API -- these are all stored in a\n list of pointers --- one for each file\n The two lists are concatenated into one in multiarray.\n\n They are available as import_array()\n*/\n\n\n#include \"__multiarray_api.h\"\n\n\n/* C-API that requries previous API to be defined */\n\n#define PyArray_DescrCheck(op) ((op)->ob_type == &PyArrayDescr_Type)\n\n#define PyArray_Check(op) ((op)->ob_type == &PyArray_Type ||\t\t\\\n\t\t\t PyObject_TypeCheck((op), &PyArray_Type))\n#define PyArray_CheckExact(op) ((op)->ob_type == &PyArray_Type)\n\n#define PyArray_IsZeroDim(op) (PyArray_Check(op) && (PyArray_NDIM(op) == 0))\n#define PyArray_IsScalar(obj, cls)\t\t\t\t\\\n\t(PyObject_TypeCheck((obj), &Py##cls##ArrType_Type))\n#define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \\\n PyArray_IsZeroDim(m))\n#define PyArray_IsPythonScalar(obj) \\\n\t(PyInt_Check(obj) || PyFloat_Check(obj) || PyComplex_Check(obj) || \\\n\t PyLong_Check(obj) || PyBool_Check(obj) || PyString_Check(obj) || \\\n\t PyUnicode_Check(obj))\n#define PyArray_IsAnyScalar(obj)\t\t\t\t\t\\\n\t(PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))\n#define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \\\n\t\t\t\t PyArray_CheckScalar(obj))\n\n#define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? Py_INCREF(m), m : \\\n (PyArrayObject *)(PyArray_Copy(m)))\n\n#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))\n#define PyArray_NBYTES(m) (PyArray_ITEMSIZE(m) * PyArray_SIZE(m))\n#define PyArray_FROM_O(m) PyArray_FromAny(m, NULL, 0, 0, 0, NULL)\n#define PyArray_FROM_OF(m,flags) PyArray_CheckFromAny(m, NULL, 0, 0, flags, NULL)\n#define PyArray_FROM_OT(m,type) PyArray_FromAny(m, PyArray_DescrFromType(type), \\\n 0, 0, 0, NULL);\n#define PyArray_FROM_OTF(m, type, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \\\n (((flags) & ENSURECOPY) ? \\\n ((flags) | DEFAULT_FLAGS) : (flags)), NULL)\n#define PyArray_FROMANY(m, type, min, max, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \\\n (((flags) & ENSURECOPY) ? \\\n (flags) | DEFAULT_FLAGS : (flags)), NULL)\n\n#define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), (val), PyArray_NBYTES(obj))\n\n#define REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)\n#define MAX_ELSIZE 2*SIZEOF_LONGDOUBLE\n\n#define PyArray_ContiguousFromAny(op, type, min_depth, max_depth) \\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, DEFAULT_FLAGS, NULL)\n\n#define PyArray_EquivArrTypes(a1, a2)\t\t\t\t\t\\\n\tPyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))\n#define PyArray_EquivTypenums(typenum1, typenum2)\t\t\\\n\tPyArray_EquivTypes(PyArray_DescrFromType(typenum1),\t\\\n\t\t\t PyArray_DescrFromType(typenum2))\n\n#define PyArray_EquivByteorders(b1, b2) \\\n\t((b1 == b2) || (PyArray_ISNBO(b1) == PyArray_ISNBO(b2)))\n\n#define PyArray_SimpleNew(nd, dims, typenum) \\\n\tPyArray_New(&PyArray_Type, nd, dims, typenum, NULL, NULL, 0, 0, NULL)\n#define PyArray_SimpleNewFromData(nd, dims, typenum, data) \\\n PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, data, 0, CARRAY_FLAGS, NULL)\n#define PyArray_SimpleNewFromDescr(nd, dims, descr) \\\n\tPyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, NULL, NULL, 0, NULL)\n#define PyArray_EnsureAnyArray(obj) \\\n\t(PyArray_Check(obj) ? obj : PyArray_EnsureArray(obj))\n\n\n/* These might be faster without the dereferencing of obj\n going on inside -- of course an optimizing compiler should\n inline the constants inside a for loop making it a moot point\n*/\n\n#define PyArray_GETPTR1(obj, i) (void *)(PyArray_BYTES(obj) +\t\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0))\n\n#define PyArray_GETPTR2(obj, i, j) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1))\n\n#define PyArray_GETPTR3(obj, i, j, k) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\\n\t\t\t\t\t k*PyArray_STRIDE(obj, 2)) \\\n\n#define PyArray_GETPTR4(obj, i, j, k, l) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\\n\t\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\\n\t\t\t\t\t\t k*PyArray_STRIDE(obj, 2) + \\\n\t\t\t\t\t\t l*PyArray_STRIDE(obj, 3))\n\n#define PyArray_DESCR_REPLACE(descr) do {\t\\\n\t\tPyArray_Descr *_new_;\t\t\t\\\n\t\t_new_ = PyArray_DescrNew(descr);\t\\\n\t\tPy_XDECREF(descr);\t\t\t\\\n\t\tdescr = _new_;\t\t\t\t\\\n\t} while(0)\n\n/* Copy should always return contiguous array */\n#define PyArray_Copy(obj) PyArray_NewCopy(obj, 0)\n\n#define PyArray_FromObject(op, type, min_depth, max_depth)\t\t\\\n\tPyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, BEHAVED_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_ContiguousFromObject(op, type, min_depth, max_depth)\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_CopyFromObject(op, type, min_depth, max_depth)\t\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, ENSURECOPY | DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_Cast(mp, type_num) \\\n\tPyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)\n\n/* Compatibility with old Numeric stuff -- don't use in new code */\n\n#define PyArray_FromDimsAndData(nd, d, type, data) \\\n\tPyArray_FromDimsAndDataAndDescr(nd, d, PyArray_DescrFromType(type), \\\n\t\t\t\t\tdata)\n\n#define PyArray_UNSIGNED_TYPES\n#define PyArray_SBYTE PyArray_BYTE\n#define PyArray_CHAR PyArray_BYTE\n#define PyArray_CopyArray PyArray_CopyInto\n#define _PyArray_multiply_list PyArray_MultiplyIntList\n#define PyArray_ISSPACESAVER(m) FALSE\n#define PyScalarArray_Check PyArray_CheckScalar\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# undef CAT\n# undef CAT2\n# undef NS\n# undef longlong\n# undef ulonglong\n# undef Bool\n# undef longdouble\n# undef byte\n# undef ubyte\n# undef ushort\n# undef uint\n# undef ulong\n# undef cfloat\n# undef cdouble\n# undef clongdouble\n# undef Int8\n# undef UInt8\n# undef Int16\n# undef UInt16\n# undef Int32\n# undef UInt32\n# undef Int64\n# undef UInt64\n# undef Int128\n# undef UInt128\n# undef Int256\n# undef UInt256\n# undef Float16\n# undef Complex32\n# undef Float32\n# undef Complex64\n# undef Float64\n# undef Complex128\n# undef Float80\n# undef Complex160\n# undef Float96\n# undef Complex192\n# undef Float128\n# undef Complex256\n# undef intp\n# undef uintp\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* !Py_ARRAYOBJECT_H */\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": 300, + "complexity": 0, + "token_count": 1410, + "diff_parsed": { + "added": [ + "#define NDARRAY_VERSION 0x00090701" + ], + "deleted": [ + "#define NDARRAY_VERSION 0x00090504" + ] + } + }, + { + "old_path": "numpy/core/numeric.py", + "new_path": "numpy/core/numeric.py", + "filename": "numeric.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -4,7 +4,7 @@\n 'getbuffer',\n 'where', 'concatenate', 'fastCopyAndTranspose', 'lexsort',\n 'register_dtype', 'set_numeric_ops', 'can_cast',\n- 'asarray', 'asanyarray', 'isfortran', 'zeros_like', 'empty_like',\n+ 'asarray', 'asanyarray', 'isfortran', 'empty_like', 'zeros_like',\n 'correlate', 'convolve', 'inner', 'dot', 'outer', 'vdot',\n 'alterdot', 'restoredot', 'cross',\n 'array2string', 'get_printoptions', 'set_printoptions',\n@@ -25,6 +25,47 @@\n import numerictypes\n from numerictypes import *\n \n+# from Fernando Perez's IPython\n+def 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+ try:\n+ return zeros(a.shape, a.dtype, a.flags.fnc)\n+ except AttributeError:\n+ try:\n+ wrap = a.__array_wrap__\n+ except AttributeError:\n+ wrap = None\n+ a = asarray(a)\n+ res = zeros(a.shape, a.dtype)\n+ if wrap:\n+ res = wrap(res)\n+ return res\n+\n+def 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+ try:\n+ return empty(a.shape, a.dtype, a.flags.fnc)\n+ except AttributeError:\n+ try:\n+ wrap = a.__array_wrap__\n+ except AttributeError:\n+ wrap = None\n+ a = asarray(a)\n+ res = empty(a.shape, a.dtype)\n+ if wrap:\n+ res = wrap(res)\n+ return res\n+\n+# end Fernando's utilities\n+\n def extend_all(module):\n adict = {}\n for a in __all__:\n@@ -81,27 +122,6 @@ def asanyarray(a, dtype=None, copy=False, fortran=False, ndmin=0):\n def isfortran(a):\n return a.flags['FNC']\n \n-# from Fernando Perez's IPython\n-def 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- a = asanyarray(a)\n- return a.__array_wrap__(zeros(a.shape, a.dtype, a.flags['FNC']))\n-\n-def 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", + "added_lines": 42, + "deleted_lines": 22, + "source_code": "__all__ = ['newaxis', 'ndarray', 'flatiter', 'ufunc',\n 'arange', 'array', 'zeros', 'empty', 'broadcast', 'dtype',\n 'fromstring', 'fromfile', 'frombuffer','newbuffer',\n 'getbuffer',\n 'where', 'concatenate', 'fastCopyAndTranspose', 'lexsort',\n 'register_dtype', 'set_numeric_ops', 'can_cast',\n 'asarray', 'asanyarray', 'isfortran', 'empty_like', 'zeros_like',\n 'correlate', 'convolve', 'inner', 'dot', 'outer', 'vdot',\n 'alterdot', 'restoredot', 'cross',\n 'array2string', 'get_printoptions', 'set_printoptions',\n 'array_repr', 'array_str', 'set_string_function',\n 'little_endian',\n 'indices', 'fromfunction',\n 'load', 'loads', 'isscalar', 'binary_repr', 'base_repr',\n 'ones', 'identity', 'allclose',\n 'seterr', 'geterr', 'setbufsize', 'getbufsize',\n 'seterrcall', 'geterrcall',\n 'Inf', 'inf', 'infty', 'Infinity',\n 'nan', 'NaN', 'False_', 'True_']\n\nimport sys\nimport multiarray\nimport umath\nfrom umath import *\nimport numerictypes\nfrom numerictypes import *\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 try:\n return zeros(a.shape, a.dtype, a.flags.fnc)\n except AttributeError:\n try:\n wrap = a.__array_wrap__\n except AttributeError:\n wrap = None\n a = asarray(a)\n res = zeros(a.shape, a.dtype)\n if wrap:\n res = wrap(res)\n return res\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 try:\n return empty(a.shape, a.dtype, a.flags.fnc)\n except AttributeError:\n try:\n wrap = a.__array_wrap__\n except AttributeError:\n wrap = None\n a = asarray(a)\n res = empty(a.shape, a.dtype)\n if wrap:\n res = wrap(res)\n return res\n\n# end Fernando's utilities\n\ndef extend_all(module):\n adict = {}\n for a in __all__:\n adict[a] = 1\n try:\n mall = getattr(module, '__all__')\n except AttributeError:\n mall = [k for k in module.__dict__.keys() if not k.startswith('_')]\n for a in mall:\n if a not in adict:\n __all__.append(a)\n\nextend_all(umath)\nextend_all(numerictypes)\n\nnewaxis = None\n\nndarray = multiarray.ndarray\nflatiter = multiarray.flatiter\nbroadcast = multiarray.broadcast\ndtype = multiarray.dtype\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\nnewbuffer = multiarray.newbuffer\ngetbuffer = multiarray.getbuffer\nwhere = multiarray.where\nconcatenate = multiarray.concatenate\nfastCopyAndTranspose = multiarray._fastCopyAndTranspose\nregister_dtype = multiarray.register_dtype\nset_numeric_ops = multiarray.set_numeric_ops\ncan_cast = multiarray.can_cast\nlexsort = multiarray.lexsort\n\n\ndef asarray(a, dtype=None, fortran=False, ndmin=0):\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, ndmin=ndmin)\n\ndef asanyarray(a, dtype=None, copy=False, fortran=False, ndmin=0):\n \"\"\"will pass subclasses through...\n \"\"\"\n return array(a, dtype, copy=copy, fortran=fortran, subok=1, ndmin=ndmin)\n\ndef isfortran(a):\n return a.flags['FNC']\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 multiarray.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 _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, axis=None):\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 if axis is not None:\n axisa,axisb,axisc=(axis,)*3\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.type 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.type.__name__[:-6]\n lf = ''\n if issubclass(arr.dtype.type, flexible):\n typename = str(arr.dtype)\n lf = '\\n'+' '*len(\"array(\")\n return cName + \"(%s, %sdtype=%s)\" % (lst, lf, 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, ' ', \"\", str)\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\ndef isscalar(num):\n if isinstance(num, generic):\n return True\n else:\n return type(num) in ScalarType\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 import math\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\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# 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 a = empty(shape, dtype, fortran)\n a.fill(1)\n # Above is faster now after addition of fast loops.\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 d.ravel().all()\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 umath.update_use_defaults()\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_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\",\n 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 umath.update_use_defaults()\n\n# set the default values\n_setdef()\n\nInf = inf = infty = Infinity = PINF\nnan = NaN = NAN\nFalse_ = bool_(False)\nTrue_ = bool_(True)\n\nimport oldnumeric\nfrom oldnumeric import *\nextend_all(oldnumeric)\n", + "source_code_before": "__all__ = ['newaxis', 'ndarray', 'flatiter', 'ufunc',\n 'arange', 'array', 'zeros', 'empty', 'broadcast', 'dtype',\n 'fromstring', 'fromfile', 'frombuffer','newbuffer',\n 'getbuffer',\n 'where', 'concatenate', 'fastCopyAndTranspose', 'lexsort',\n 'register_dtype', 'set_numeric_ops', 'can_cast',\n 'asarray', 'asanyarray', 'isfortran', 'zeros_like', 'empty_like',\n 'correlate', 'convolve', 'inner', 'dot', 'outer', 'vdot',\n 'alterdot', 'restoredot', 'cross',\n 'array2string', 'get_printoptions', 'set_printoptions',\n 'array_repr', 'array_str', 'set_string_function',\n 'little_endian',\n 'indices', 'fromfunction',\n 'load', 'loads', 'isscalar', 'binary_repr', 'base_repr',\n 'ones', 'identity', 'allclose',\n 'seterr', 'geterr', 'setbufsize', 'getbufsize',\n 'seterrcall', 'geterrcall',\n 'Inf', 'inf', 'infty', 'Infinity',\n 'nan', 'NaN', 'False_', 'True_']\n\nimport sys\nimport multiarray\nimport umath\nfrom umath import *\nimport numerictypes\nfrom numerictypes import *\n\ndef extend_all(module):\n adict = {}\n for a in __all__:\n adict[a] = 1\n try:\n mall = getattr(module, '__all__')\n except AttributeError:\n mall = [k for k in module.__dict__.keys() if not k.startswith('_')]\n for a in mall:\n if a not in adict:\n __all__.append(a)\n\nextend_all(umath)\nextend_all(numerictypes)\n\nnewaxis = None\n\nndarray = multiarray.ndarray\nflatiter = multiarray.flatiter\nbroadcast = multiarray.broadcast\ndtype = multiarray.dtype\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\nnewbuffer = multiarray.newbuffer\ngetbuffer = multiarray.getbuffer\nwhere = multiarray.where\nconcatenate = multiarray.concatenate\nfastCopyAndTranspose = multiarray._fastCopyAndTranspose\nregister_dtype = multiarray.register_dtype\nset_numeric_ops = multiarray.set_numeric_ops\ncan_cast = multiarray.can_cast\nlexsort = multiarray.lexsort\n\n\ndef asarray(a, dtype=None, fortran=False, ndmin=0):\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, ndmin=ndmin)\n\ndef asanyarray(a, dtype=None, copy=False, fortran=False, ndmin=0):\n \"\"\"will pass subclasses through...\n \"\"\"\n return array(a, dtype, copy=copy, fortran=fortran, subok=1, ndmin=ndmin)\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 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 multiarray.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 _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, axis=None):\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 if axis is not None:\n axisa,axisb,axisc=(axis,)*3\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.type 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.type.__name__[:-6]\n lf = ''\n if issubclass(arr.dtype.type, flexible):\n typename = str(arr.dtype)\n lf = '\\n'+' '*len(\"array(\")\n return cName + \"(%s, %sdtype=%s)\" % (lst, lf, 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, ' ', \"\", str)\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\ndef isscalar(num):\n if isinstance(num, generic):\n return True\n else:\n return type(num) in ScalarType\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 import math\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\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# 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 a = empty(shape, dtype, fortran)\n a.fill(1)\n # Above is faster now after addition of fast loops.\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 d.ravel().all()\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 umath.update_use_defaults()\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_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\",\n 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 umath.update_use_defaults()\n\n# set the default values\n_setdef()\n\nInf = inf = infty = Infinity = PINF\nnan = NaN = NAN\nFalse_ = bool_(False)\nTrue_ = bool_(True)\n\nimport oldnumeric\nfrom oldnumeric import *\nextend_all(oldnumeric)\n", + "methods": [ + { + "name": "zeros_like", + "long_name": "zeros_like( a )", + "filename": "numeric.py", + "nloc": 13, + "complexity": 4, + "token_count": 70, + "parameters": [ + "a" + ], + "start_line": 29, + "end_line": 45, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "empty_like", + "long_name": "empty_like( a )", + "filename": "numeric.py", + "nloc": 13, + "complexity": 4, + "token_count": 70, + "parameters": [ + "a" + ], + "start_line": 47, + "end_line": 65, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "extend_all", + "long_name": "extend_all( module )", + "filename": "numeric.py", + "nloc": 11, + "complexity": 7, + "token_count": 73, + "parameters": [ + "module" + ], + "start_line": 69, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( a , dtype = None , fortran = False , ndmin = 0 )", + "filename": "numeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 37, + "parameters": [ + "a", + "dtype", + "fortran", + "ndmin" + ], + "start_line": 110, + "end_line": 115, + "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 , ndmin = 0 )", + "filename": "numeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 45, + "parameters": [ + "a", + "dtype", + "copy", + "fortran", + "ndmin" + ], + "start_line": 117, + "end_line": 120, + "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": 122, + "end_line": 123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "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": 129, + "end_line": 132, + "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": 134, + "end_line": 136, + "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": 57, + "parameters": [ + "a", + "v", + "mode" + ], + "start_line": 139, + "end_line": 147, + "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": 153, + "end_line": 160, + "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": 162, + "end_line": 166, + "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": 174, + "end_line": 175, + "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": 176, + "end_line": 177, + "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": 180, + "end_line": 187, + "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 , axis = None )", + "filename": "numeric.py", + "nloc": 34, + "complexity": 10, + "token_count": 382, + "parameters": [ + "a", + "b", + "axisa", + "axisb", + "axisc", + "axis" + ], + "start_line": 189, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "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": 20, + "complexity": 7, + "token_count": 167, + "parameters": [ + "arr", + "max_line_width", + "precision", + "suppress_small" + ], + "start_line": 242, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "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": 34, + "parameters": [ + "a", + "max_line_width", + "precision", + "suppress_small" + ], + "start_line": 264, + "end_line": 265, + "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": 274, + "end_line": 282, + "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": 284, + "end_line": 294, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "isscalar", + "long_name": "isscalar( num )", + "filename": "numeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "num" + ], + "start_line": 296, + "end_line": 300, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "binary_repr", + "long_name": "binary_repr( num )", + "filename": "numeric.py", + "nloc": 9, + "complexity": 3, + "token_count": 50, + "parameters": [ + "num" + ], + "start_line": 312, + "end_line": 325, + "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": "numeric.py", + "nloc": 15, + "complexity": 3, + "token_count": 99, + "parameters": [ + "number", + "base", + "padding" + ], + "start_line": 327, + "end_line": 344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "load", + "long_name": "load( file )", + "filename": "numeric.py", + "nloc": 4, + "complexity": 2, + "token_count": 29, + "parameters": [ + "file" + ], + "start_line": 350, + "end_line": 353, + "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": 32, + "parameters": [ + "shape", + "dtype", + "fortran" + ], + "start_line": 358, + "end_line": 367, + "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": 369, + "end_line": 375, + "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": 74, + "parameters": [ + "a", + "b", + "rtol", + "atol" + ], + "start_line": 377, + "end_line": 388, + "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": 15, + "complexity": 10, + "token_count": 112, + "parameters": [ + "lst", + "frame", + "where" + ], + "start_line": 390, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_getpyvals", + "long_name": "_getpyvals( frame )", + "filename": "numeric.py", + "nloc": 11, + "complexity": 4, + "token_count": 49, + "parameters": [ + "frame" + ], + "start_line": 409, + "end_line": 419, + "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": 10, + "complexity": 1, + "token_count": 95, + "parameters": [ + "divide", + "over", + "under", + "invalid", + "where" + ], + "start_line": 431, + "end_line": 441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "geterr", + "long_name": "geterr( )", + "filename": "numeric.py", + "nloc": 14, + "complexity": 1, + "token_count": 107, + "parameters": [], + "start_line": 443, + "end_line": 457, + "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": 459, + "end_line": 466, + "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": 468, + "end_line": 470, + "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": 472, + "end_line": 478, + "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": 480, + "end_line": 482, + "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": 6, + "complexity": 1, + "token_count": 41, + "parameters": [], + "start_line": 484, + "end_line": 489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "extend_all", + "long_name": "extend_all( module )", + "filename": "numeric.py", + "nloc": 11, + "complexity": 7, + "token_count": 73, + "parameters": [ + "module" + ], + "start_line": 28, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( a , dtype = None , fortran = False , ndmin = 0 )", + "filename": "numeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 37, + "parameters": [ + "a", + "dtype", + "fortran", + "ndmin" + ], + "start_line": 69, + "end_line": 74, + "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 , ndmin = 0 )", + "filename": "numeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 45, + "parameters": [ + "a", + "dtype", + "copy", + "fortran", + "ndmin" + ], + "start_line": 76, + "end_line": 79, + "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": 81, + "end_line": 82, + "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": 85, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "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": 93, + "end_line": 101, + "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": 109, + "end_line": 112, + "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": 114, + "end_line": 116, + "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": 57, + "parameters": [ + "a", + "v", + "mode" + ], + "start_line": 119, + "end_line": 127, + "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": 133, + "end_line": 140, + "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": 142, + "end_line": 146, + "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": 154, + "end_line": 155, + "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": 156, + "end_line": 157, + "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": 160, + "end_line": 167, + "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 , axis = None )", + "filename": "numeric.py", + "nloc": 34, + "complexity": 10, + "token_count": 382, + "parameters": [ + "a", + "b", + "axisa", + "axisb", + "axisc", + "axis" + ], + "start_line": 169, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "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": 20, + "complexity": 7, + "token_count": 167, + "parameters": [ + "arr", + "max_line_width", + "precision", + "suppress_small" + ], + "start_line": 222, + "end_line": 242, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "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": 34, + "parameters": [ + "a", + "max_line_width", + "precision", + "suppress_small" + ], + "start_line": 244, + "end_line": 245, + "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": 254, + "end_line": 262, + "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": 264, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "isscalar", + "long_name": "isscalar( num )", + "filename": "numeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "num" + ], + "start_line": 276, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "binary_repr", + "long_name": "binary_repr( num )", + "filename": "numeric.py", + "nloc": 9, + "complexity": 3, + "token_count": 50, + "parameters": [ + "num" + ], + "start_line": 292, + "end_line": 305, + "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": "numeric.py", + "nloc": 15, + "complexity": 3, + "token_count": 99, + "parameters": [ + "number", + "base", + "padding" + ], + "start_line": 307, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "load", + "long_name": "load( file )", + "filename": "numeric.py", + "nloc": 4, + "complexity": 2, + "token_count": 29, + "parameters": [ + "file" + ], + "start_line": 330, + "end_line": 333, + "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": 32, + "parameters": [ + "shape", + "dtype", + "fortran" + ], + "start_line": 338, + "end_line": 347, + "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": 349, + "end_line": 355, + "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": 74, + "parameters": [ + "a", + "b", + "rtol", + "atol" + ], + "start_line": 357, + "end_line": 368, + "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": 15, + "complexity": 10, + "token_count": 112, + "parameters": [ + "lst", + "frame", + "where" + ], + "start_line": 370, + "end_line": 387, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_getpyvals", + "long_name": "_getpyvals( frame )", + "filename": "numeric.py", + "nloc": 11, + "complexity": 4, + "token_count": 49, + "parameters": [ + "frame" + ], + "start_line": 389, + "end_line": 399, + "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": 10, + "complexity": 1, + "token_count": 95, + "parameters": [ + "divide", + "over", + "under", + "invalid", + "where" + ], + "start_line": 411, + "end_line": 421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "geterr", + "long_name": "geterr( )", + "filename": "numeric.py", + "nloc": 14, + "complexity": 1, + "token_count": 107, + "parameters": [], + "start_line": 423, + "end_line": 437, + "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": 439, + "end_line": 446, + "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": 448, + "end_line": 450, + "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": 452, + "end_line": 458, + "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": 460, + "end_line": 462, + "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": 6, + "complexity": 1, + "token_count": 41, + "parameters": [], + "start_line": 464, + "end_line": 469, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "zeros_like", + "long_name": "zeros_like( a )", + "filename": "numeric.py", + "nloc": 13, + "complexity": 4, + "token_count": 70, + "parameters": [ + "a" + ], + "start_line": 29, + "end_line": 45, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "empty_like", + "long_name": "empty_like( a )", + "filename": "numeric.py", + "nloc": 13, + "complexity": 4, + "token_count": 70, + "parameters": [ + "a" + ], + "start_line": 47, + "end_line": 65, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + } + ], + "nloc": 356, + "complexity": 87, + "token_count": 2680, + "diff_parsed": { + "added": [ + " 'asarray', 'asanyarray', 'isfortran', 'empty_like', 'zeros_like',", + "# from Fernando Perez's IPython", + "def zeros_like(a):", + " \"\"\"Return an array of zeros of the shape and typecode of a.", + "", + " If you don't explicitly need the array to be zeroed, you should instead", + " use empty_like(), which is faster as it only allocates memory.\"\"\"", + " try:", + " return zeros(a.shape, a.dtype, a.flags.fnc)", + " except AttributeError:", + " try:", + " wrap = a.__array_wrap__", + " except AttributeError:", + " wrap = None", + " a = asarray(a)", + " res = zeros(a.shape, a.dtype)", + " if wrap:", + " res = wrap(res)", + " return res", + "", + "def empty_like(a):", + " \"\"\"Return an empty (uninitialized) array of the shape and typecode of a.", + "", + " Note that this does NOT initialize the returned array. If you require", + " your array to be initialized, you should use zeros_like().", + "", + " \"\"\"", + " try:", + " return empty(a.shape, a.dtype, a.flags.fnc)", + " except AttributeError:", + " try:", + " wrap = a.__array_wrap__", + " except AttributeError:", + " wrap = None", + " a = asarray(a)", + " res = empty(a.shape, a.dtype)", + " if wrap:", + " res = wrap(res)", + " return res", + "", + "# end Fernando's utilities", + "" + ], + "deleted": [ + " 'asarray', 'asanyarray', 'isfortran', 'zeros_like', 'empty_like',", + "# from Fernando Perez's IPython", + "def zeros_like(a):", + " \"\"\"Return an array of zeros of the shape and typecode of a.", + "", + " If you don't explicitly need the array to be zeroed, you should instead", + " use empty_like(), which is faster as it only allocates memory.\"\"\"", + " a = asanyarray(a)", + " return a.__array_wrap__(zeros(a.shape, a.dtype, a.flags['FNC']))", + "", + "def empty_like(a):", + " \"\"\"Return an empty (uninitialized) array of the shape and typecode of a.", + "", + " Note that this does NOT initialize the returned array. If you require", + " your array to be initialized, you should use zeros_like().", + "", + " \"\"\"", + " a = asanyarray(a)", + " return a.__array_wrap__(empty(a.shape, a.dtype, a.flags['FNC']))", + "", + "# end Fernando's utilities", + "" + ] + } + }, + { + "old_path": "numpy/core/src/arrayobject.c", + "new_path": "numpy/core/src/arrayobject.c", + "filename": "arrayobject.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -4434,8 +4434,7 @@ array_ndim_get(PyArrayObject *self)\n static PyObject *\n array_flags_get(PyArrayObject *self)\n {\n- return PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\",\n- self, self->flags, 0);\n+ return PyArray_NewFlagsObject((PyObject *)self);\n }\n \n static PyObject *\n@@ -8414,7 +8413,7 @@ arraydescr_dealloc(PyArray_Descr *self)\n \t\tPy_DECREF(self->subarray->base);\n \t\t_pya_free(self->subarray);\n \t}\n-\tself->ob_type->tp_free(self);\n+\tself->ob_type->tp_free((PyObject *)self);\n }\n \n /* we need to be careful about setting attributes because these\n@@ -9081,3 +9080,386 @@ static PyTypeObject PyArrayDescr_Type = {\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n };\n+\n+\n+/** Array Flags Object **/\n+\n+typedef struct PyArrayFlagsObject {\n+ PyObject_HEAD\n+ PyObject *arr;\n+ int flags;\n+} PyArrayFlagsObject;\n+\n+/*OBJECT_API\n+ Get New ArrayFlagsObject\n+*/\n+static PyObject *\n+PyArray_NewFlagsObject(PyObject *obj)\n+{\n+ PyObject *flagobj;\n+ int flags;\n+ if (obj == NULL) {\n+ flags = CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n+ }\n+ else {\n+ flags = PyArray_FLAGS(obj);\n+ }\n+ flagobj = PyArrayFlags_Type.tp_alloc(&PyArrayFlags_Type, 0);\n+ if (flagobj == NULL) return NULL;\n+ Py_XINCREF(obj);\n+ ((PyArrayFlagsObject *)flagobj)->arr = obj;\n+ ((PyArrayFlagsObject *)flagobj)->flags = flags;\n+\n+ return flagobj;\n+}\n+\n+static void\n+arrayflags_dealloc(PyArrayFlagsObject *self)\n+{\n+\tPy_XDECREF(self->arr);\n+\tself->ob_type->tp_free((PyObject *)self);\n+}\n+\n+\n+#define _define_get(UPPER, lower) \\\n+static PyObject * \\\n+arrayflags_ ## lower ## _get(PyArrayFlagsObject *self) \\\n+{ \\\n+ PyObject *item; \\\n+ item = ((self->flags & (UPPER)) == (UPPER)) ? Py_True : Py_False; \\\n+ Py_INCREF(item); \\\n+ return item; \\\n+}\n+\n+_define_get(CONTIGUOUS, contiguous)\n+_define_get(FORTRAN, fortran)\n+_define_get(UPDATEIFCOPY, updateifcopy)\n+_define_get(OWNDATA, owndata)\n+_define_get(ALIGNED, aligned)\n+_define_get(WRITEABLE, writeable)\n+\n+_define_get(ALIGNED|WRITEABLE, behaved)\n+_define_get(ALIGNED|WRITEABLE|CONTIGUOUS, carray)\n+\n+static PyObject *\n+arrayflags_forc_get(PyArrayFlagsObject *self)\n+{\n+ PyObject *item;\n+ \n+ if (((self->flags & FORTRAN) == FORTRAN) ||\n+ ((self->flags & CONTIGUOUS) == CONTIGUOUS))\n+ item = Py_True;\n+ else\n+ item = Py_False;\n+ \n+ Py_INCREF(item);\n+ return item;\n+}\n+\n+static PyObject *\n+arrayflags_fnc_get(PyArrayFlagsObject *self)\n+{\n+ PyObject *item;\n+ \n+ if (((self->flags & FORTRAN) == FORTRAN) &&\n+ !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n+ item = Py_True;\n+ else\n+ item = Py_False;\n+ \n+ Py_INCREF(item);\n+ return item;\n+}\n+\n+static PyObject *\n+arrayflags_farray_get(PyArrayFlagsObject *self)\n+{\n+ PyObject *item;\n+ \n+ if (((self->flags & (ALIGNED|WRITEABLE|FORTRAN)) == \\\n+ (ALIGNED|WRITEABLE|FORTRAN)) &&\n+ !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n+ item = Py_True;\n+ else\n+ item = Py_False;\n+ \n+ Py_INCREF(item);\n+ return item;\n+}\n+\n+static PyObject *\n+arrayflags_num_get(PyArrayFlagsObject *self)\n+{\n+ return PyInt_FromLong(self->flags);\n+}\n+\n+/* relies on setflags order being write, align, uic */\n+static int\n+arrayflags_updateifcopy_set(PyArrayFlagsObject *self, PyObject *obj)\n+{\n+ PyObject *res;\n+ if (self->arr == NULL) {\n+ PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n+ return -1;\n+ }\n+ res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, Py_None, \n+ (PyObject_IsTrue(obj) ? Py_True : Py_False));\n+ if (res == NULL) return -1;\n+ Py_DECREF(res);\n+ return 0;\n+}\n+\n+static int\n+arrayflags_aligned_set(PyArrayFlagsObject *self, PyObject *obj)\n+{\n+ PyObject *res;\n+ if (self->arr == NULL) {\n+ PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n+ return -1;\n+ }\n+ res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, \n+ (PyObject_IsTrue(obj) ? Py_True : Py_False),\n+ Py_None);\n+ if (res == NULL) return -1;\n+ Py_DECREF(res);\n+ return 0;\n+}\n+\n+static int\n+arrayflags_writeable_set(PyArrayFlagsObject *self, PyObject *obj)\n+{\n+ PyObject *res;\n+ if (self->arr == NULL) {\n+ PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n+ return -1;\n+ }\n+ res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", \n+ (PyObject_IsTrue(obj) ? Py_True : Py_False),\n+ Py_None, Py_None);\n+ if (res == NULL) return -1;\n+ Py_DECREF(res);\n+ return 0;\n+}\n+\n+\n+static PyGetSetDef arrayflags_getsets[] = {\n+\t{\"contiguous\",\n+\t (getter)arrayflags_contiguous_get,\n+\t NULL,\n+\t \"\"},\n+ {\"fortran\",\n+ (getter)arrayflags_fortran_get,\n+ NULL,\n+ \"\"},\n+ {\"updateifcopy\",\n+ (getter)arrayflags_updateifcopy_get,\n+ (setter)arrayflags_updateifcopy_set,\n+ \"\"},\n+ {\"owndata\",\n+ (getter)arrayflags_owndata_get,\n+ NULL,\n+ \"\"},\n+ {\"aligned\",\n+ (getter)arrayflags_aligned_get,\n+ (setter)arrayflags_aligned_set,\n+ \"\"},\n+ {\"writeable\",\n+ (getter)arrayflags_writeable_get,\n+ (setter)arrayflags_writeable_set,\n+ \"\"},\n+ {\"fnc\",\n+ (getter)arrayflags_fnc_get,\n+ NULL,\n+ \"\"},\n+ {\"forc\",\n+ (getter)arrayflags_forc_get,\n+ NULL,\n+ \"\"},\n+ {\"behaved\",\n+ (getter)arrayflags_behaved_get,\n+ NULL,\n+ \"\"},\n+ {\"carray\",\n+ (getter)arrayflags_carray_get,\n+ NULL,\n+ \"\"},\n+ {\"farray\",\n+ (getter)arrayflags_farray_get,\n+ NULL,\n+ \"\"},\n+ {\"num\",\n+ (getter)arrayflags_num_get,\n+ NULL,\n+ \"\"},\n+\t{NULL, NULL, NULL, NULL},\n+};\n+\n+static PyObject *\n+arrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)\n+{\n+ char *key;\n+ int n;\n+ if (!PyString_Check(ind)) goto fail;\n+ key = PyString_AS_STRING(ind);\n+ n = PyString_GET_SIZE(ind);\n+ if ((strncmp(key,\"CONTIGUOUS\",n)==0) ||\n+ (strncmp(key,\"C\",n)))\n+ return arrayflags_contiguous_get(self);\n+ else if ((strncmp(key, \"FORTRAN\", n)==0) ||\n+ (strncmp(key, \"F\", n)==0)) \n+ return arrayflags_fortran_get(self);\n+ else if ((strncmp(key, \"WRITEABLE\", n)==0) ||\n+ (strncmp(key, \"W\", n)==0))\n+ return arrayflags_writeable_get(self);\n+ else if ((strncmp(key, \"BEHAVED\", n)==0) ||\n+ (strncmp(key, \"B\", n)==0))\n+ return arrayflags_behaved_get(self);\n+ else if ((strncmp(key, \"OWNDATA\", n)==0) ||\n+ (strncmp(key, \"O\", n)==0))\n+ return arrayflags_owndata_get(self);\n+ else if ((strncmp(key, \"ALIGNED\", n)==0) ||\n+ (strncmp(key, \"A\", n)==0))\n+ return arrayflags_aligned_get(self);\n+ else if ((strncmp(key, \"UPDATEIFCOPY\", n)==0) ||\n+ (strncmp(key, \"U\", n)==0))\n+ return arrayflags_updateifcopy_get(self);\n+ else if ((strncmp(key, \"FNC\", n)==0))\n+ return arrayflags_fnc_get(self);\n+ else if ((strncmp(key, \"FORC\", n)==0))\n+ return arrayflags_forc_get(self);\n+ else if ((strncmp(key, \"CARRAY\", n)==0) ||\n+ (strncmp(key, \"CA\", n)==0))\n+ return arrayflags_carray_get(self);\n+ else if ((strncmp(key, \"FARRAY\", n)==0) ||\n+ (strncmp(key, \"FA\", n)==0))\n+ return arrayflags_farray_get(self);\n+ else goto fail;\n+\n+ fail:\n+ PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n+ return NULL;\n+}\n+\n+static int\n+arrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)\n+{ \n+ char *key;\n+ int n;\n+ if (!PyString_Check(ind)) goto fail;\n+ key = PyString_AS_STRING(ind);\n+ n = PyString_GET_SIZE(ind);\n+ if ((strncmp(key, \"WRITEABLE\", n)==0) ||\n+ (strncmp(key, \"W\", n)==0))\n+ return arrayflags_writeable_set(self, item);\n+ else if ((strncmp(key, \"ALIGNED\", n)==0) ||\n+ (strncmp(key, \"A\", n)==0))\n+ return arrayflags_aligned_set(self, item);\n+ else if ((strncmp(key, \"UPDATEIFCOPY\", n)==0) ||\n+ (strncmp(key, \"U\", n)==0))\n+ return arrayflags_updateifcopy_set(self, item); \n+ else goto fail;\n+ return 0;\n+\n+fail:\n+ PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n+ return -1;\n+}\n+\n+static char *\n+_torf_(int flags, int val)\n+{\n+ if ((flags & val) == val) return \"True\";\n+ else return \"False\"; \n+}\n+\n+static PyObject *\n+arrayflags_print(PyArrayFlagsObject *self)\n+{\n+ int fl = self->flags;\n+ \n+ return PyString_FromFormat(\" %s : %s\\n %s : %s\\n %s : %s\\n\"\\\n+ \" %s : %s\\n %s : %s\\n %s : %s\",\n+ \"CONTIGUOUS\", _torf_(fl, CONTIGUOUS),\n+ \"FORTRAN\", _torf_(fl, FORTRAN),\n+ \"OWNDATA\", _torf_(fl, OWNDATA),\n+ \"WRITEABLE\", _torf_(fl, WRITEABLE),\n+ \"ALIGNED\", _torf_(fl, ALIGNED),\n+ \"UPDATEIFCOPY\", _torf_(fl, UPDATEIFCOPY));\n+}\n+\n+\n+static PyMappingMethods arrayflags_as_mapping = {\n+#if PY_VERSION_HEX >= 0x02050000\n+ (lenfunc)NULL, \t\t /*mp_length*/\n+#else\n+ (inquiry)NULL, \t\t /*mp_length*/\n+#endif\n+ (binaryfunc)arrayflags_getitem,\t /*mp_subscript*/\n+ (objobjargproc)arrayflags_setitem, /*mp_ass_subscript*/\n+};\n+\n+\n+static PyObject *\n+arrayflags_new(PyTypeObject *self, PyObject *args, PyObject *kwds)\n+{\n+ PyObject *arg=NULL;\n+ if (!PyArg_UnpackTuple(args, \"flagsobj\", 0, 1, &arg))\n+ return NULL;\n+\n+ if ((arg != NULL) && PyArray_Check(arg)) {\n+ return PyArray_NewFlagsObject(arg);\n+ }\n+ else {\n+ return PyArray_NewFlagsObject(NULL);\n+ }\n+}\n+\n+static PyTypeObject PyArrayFlags_Type = {\n+ PyObject_HEAD_INIT(NULL)\n+ 0,\n+ \"numpy.flagsobj\",\n+ sizeof(PyArrayFlagsObject),\n+ 0,\t\t\t\t\t /* tp_itemsize */\n+ /* methods */\n+ (destructor)arrayflags_dealloc,\t\t/* tp_dealloc */\n+ 0,\t\t\t\t\t/* tp_print */\n+ 0,\t\t\t\t\t/* tp_getattr */\n+ 0,\t\t\t\t\t/* tp_setattr */\n+\t0,\t\t /* tp_compare */\n+ (reprfunc)arrayflags_print, /* tp_repr */\n+ 0,\t\t\t\t\t/* tp_as_number */\n+ 0,\t\t\t /* tp_as_sequence */\n+ &arrayflags_as_mapping,\t /* tp_as_mapping */\n+ 0,\t\t\t\t\t/* tp_hash */\n+ 0,\t\t\t\t\t/* tp_call */\n+ (reprfunc)arrayflags_print, /* tp_str */\n+ 0,\t \t /* tp_getattro */\n+ 0,\t\t\t\t\t/* tp_setattro */\n+ 0,\t\t\t\t\t/* tp_as_buffer */\n+ Py_TPFLAGS_DEFAULT, /* tp_flags */\n+ 0,\t\t\t\t\t/* tp_doc */\n+ 0,\t /* tp_traverse */\n+ 0,\t\t\t\t\t/* tp_clear */\n+ 0,\t\t\t\t\t/* tp_richcompare */\n+ 0,\t\t\t\t\t/* tp_weaklistoffset */\n+ 0,\t /* tp_iter */\n+ 0,\t\t /* tp_iternext */\n+ 0,\t \t /* tp_methods */\n+ 0,\t /* tp_members */\n+ arrayflags_getsets, /* tp_getset */\n+ 0,\t\t\t\t /* tp_base */\n+ 0,\t\t\t\t\t /* tp_dict */\n+ 0,\t\t\t\t\t /* tp_descr_get */\n+ 0,\t\t\t\t\t /* tp_descr_set */\n+ 0,\t\t\t\t\t /* tp_dictoffset */\n+ 0, \t /* tp_init */\n+ 0,\t /* tp_alloc */\n+ arrayflags_new,\t /* tp_new */\n+ 0,\t /* tp_free */\n+ 0,\t\t\t\t\t /* tp_is_gc */\n+ 0,\t\t\t\t\t /* tp_bases */\n+ 0,\t\t\t\t\t /* tp_mro */\n+ 0,\t\t\t\t\t /* tp_cache */\n+ 0,\t\t\t\t\t /* tp_subclasses */\n+ 0\t\t\t\t\t /* tp_weaklist */\n+};\n", + "added_lines": 385, + "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/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_)\n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear();\n priority = default_;\n }\n Py_XDECREF(ret);\n return priority;\n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a\n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n }\n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int\ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides,\n\t intp *src_dimensions, int src_nd, int elsize,\n\t int copies) {\n intp i, j;\n\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1,\n dest_dimensions+1, dest_nd-1,\n src, src_strides,\n src_dimensions, src_nd,\n elsize, copies) == -1)\n return -1;\n }\n return 0;\n }\n\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError,\n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) &&\n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] !=\n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src)\n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\n dest_strides_ptr = dest_strides;\n\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1)\n return NULL;\n\n new_data = (char *)_pya_malloc(stride);\n\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions,\n dest_nd, src->data, src_strides,\n src_dimensions, src_nd, elsize, copies);\n\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *,\n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int\nPyArray_INCREF(PyArrayObject *mp)\n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap)\n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n\n\n if ((numitems == 1) || (itemsize == srcstrides))\n memcpy(d1, s1, itemsize*numitems);\n else {\n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n }\n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG\n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i)\n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp\nPyArray_Size(PyObject *op)\n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n }\n\telse {\n return 0;\n }\n}\n\n/* If destination is not the right type, then src\n will be cast to destination.\n*/\n\n/* Does a flat iterator-based copy.\n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however.\n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n\n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError,\n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n\n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, elsize);\n PyArray_INCREF(dest);\n return 0;\n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n }\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int\nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)\n{\n PyArrayObject *src;\n int ret;\n\t\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d,\n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t}\n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,\n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd,\n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran,\n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\n return (PyObject *)ret;\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) {\n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED;\n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=0;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use\n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifndef Py_UNICODE_WIDE\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\treturn obj;\n#endif\n\t\t}\n\t\telse {\n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, itemsize);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this.\n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag\n*/\n\n/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp)\n{\n\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n\n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int\nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs,\n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/*\n copyies over from the old descr table for anything\n NULL or zero in what is given.\n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)\n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data,\n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError,\n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr,\n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element\"\\\n \" %d to file\",\n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj);\n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj),\n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\",\n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1)\n fwrite(sep, 1, n3, fp);\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self)\n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0)\n\t\treturn self->descr->f->getitem(self->data,self);\n\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n\n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void\narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an\n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE\n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n\n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\narray_length(PyArrayObject *self)\n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i)\n{\n\tchar *item;\n\tPyArrayObject *r;\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1,\n\t\t\t\t\t\t self->dimensions+1,\n\t\t\t\t\t\t self->strides+1, item,\n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\nstatic PyObject *\narray_item_nice(PyArrayObject *self, _int_or_ssize_t i)\n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\n\nstatic int\narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v)\n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret;\n }\n\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if PY_VERSION_HEX < 0x02050000\n #if SIZEOF_INT == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#else\n #if SIZEOF_SIZE_T == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#endif\n#ifndef array_ass_item\nstatic int\narray_ass_item(PyArrayObject *self, _int_or_ssize_t i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int\nparse_index(PyArrayObject *self, PyObject *op,\n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError,\n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\n nd_old = nd_new = 0;\n\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n\t/* tuple for transpose is\n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of\n\t the broadcasted index array\n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the\n\t result\n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2)\n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call.\n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type,\n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret))\n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, PyArray_ITEMSIZE(arr));\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS];\n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL)\n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0\n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from\n Python when using a[object] unless object is a standard slice object\n (not an extended one).\n\n*/\n\n/* There are two situations:\n\n 1 - the subscript is a standard view and a reference to the\n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned.\n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *);\n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op)\n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr,\n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis) {\n\t\t\t/* XXX: This leads to a small inconsistency\n\t\t\t XXX: with the nd>0 case where (x[...] is x)\n\t\t\t XXX: is false for nd>0 case. */\n\t\t\tPy_INCREF(self);\n\t\t\treturn (PyObject *)self;\n\t\t}\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op)) {\n\t\t\t\tPy_INCREF(self);\n\t\t\t\treturn (PyObject *)self;\n\t\t\t}\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset))\n == -1)\n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset,\n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL)\n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be\n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *);\n\nstatic int\narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)\n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr,\n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1;\n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to\n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op)\n{\n\t/* The following is just a copy of PyArray_Return with an\n\t additional logic in the nd == 0 case. More efficient\n\t implementation may be possible by refactoring\n\t array_subscript */\n\n\tPyArrayObject *mp = (PyArrayObject *)array_subscript(self, op);\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tBool noellipses = TRUE;\n\t\tif (op == Py_Ellipsis)\n\t\t\tnoellipses = FALSE;\n\t\telse if (PySequence_Check(op)) {\n\t\t\tint n, i;\n\t\t\tn = PySequence_Size(op);\n\t\t\tfor (i = 0; i < n; ++i) \n\t\t\t\tif (PySequence_GetItem(op, i) == Py_Ellipsis) {\n\t\t\t\t\tnoellipses = FALSE;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t\tif (noellipses) {\n\t\t\tPyObject *ret;\n\t\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\t\tPy_DECREF(mp);\n\t\t\treturn ret;\n\t\t}\n\t}\n\treturn (PyObject *)mp;\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t /*mp_length*/\n#else\n (inquiry)array_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic _int_or_ssize_t\narray_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp)\n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic _int_or_ssize_t\narray_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"accessing non-existing array segment\");\n return -1;\n }\n\n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic _int_or_ssize_t\narray_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (PyArray_CHKFLAGS(self, WRITEABLE))\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic _int_or_ssize_t\narray_getcharbuf(PyArrayObject *self, _int_or_ssize_t segment, const char **ptrptr)\n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError,\n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (writebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (segcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (charbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#else\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#endif\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n *square,\n *reciprocal,\n *ones_like,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum,\n\t\t*rint;\n} NumericOps;\n\nstatic NumericOps n_ops; /* NB: static objects inlitialized to zero */\n\n/* Dictionary can contain any of the numeric operations, by name.\n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n\n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint\nPyArray_SetNumericOps(PyObject *dict)\n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n SET(square);\n SET(reciprocal);\n SET(ones_like);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\n SET(true_divide);\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n\tSET(rint);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void)\n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL)\n\t\treturn NULL;\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n GET(square);\n GET(reciprocal);\n GET(ones_like);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide);\n GET(true_divide);\n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\tGET(rint);\n\treturn dict;\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,\n\t\t\t\t PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2)\n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\n\nstatic PyObject *array_float(PyArrayObject *v);\n\n\nstatic int\narray_power_is_scalar(PyObject *o2, double* exp)\n{\n PyObject *temp;\n const int optimize_fpexps = 1;\n if (PyInt_Check(o2)) {\n *exp = (double)PyInt_AsLong(o2);\n return 1;\n }\n if (optimize_fpexps && PyFloat_Check(o2)) {\n *exp = PyFloat_AsDouble(o2);\n return 1;\n }\n if (PyArray_CheckScalar(o2)) {\n if (PyArray_ISINTEGER(o2) || (optimize_fpexps && PyArray_ISFLOAT(o2))) {\n temp = array_float((PyArrayObject *)o2);\n if (temp != NULL) {\n *exp = PyFloat_AsDouble(o2);\n Py_DECREF(temp);\n return 1;\n }\n }\n }\n return 0;\n}\n\n/* optimize float array or complex array to a scalar power */\nstatic PyObject *\nfast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) {\n double exp;\n if (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) || PyArray_ISCOMPLEX(a1))) {\n if (array_power_is_scalar(o2, &exp)) {\n PyObject *fastop = NULL;\n if (exp == 1.0) {\n /* we have to do this one special, as the \"copy\" method of\n array objects isn't set up early enough to be added\n by PyArray_SetNumericOps.\n */\n if (inplace) {\n return (PyObject *)a1;\n } else {\n return PyArray_Copy(a1);\n }\n } else if (exp == -1.0) {\n fastop = n_ops.reciprocal;\n } else if (exp == 0.0) {\n fastop = n_ops.ones_like;\n } else if (exp == 0.5) {\n fastop = n_ops.sqrt;\n } else if (exp == 2.0) {\n fastop = n_ops.square;\n } else {\n return NULL;\n }\n if (inplace) {\n PyArray_GenericInplaceUnaryFunction(a1, fastop);\n } else {\n return PyArray_GenericUnaryFunction(a1, fastop);\n }\n }\n }\n return NULL;\n}\n\nstatic PyObject *\narray_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 0);\n if (!value) {\n value = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\n\nstatic PyObject *\narray_negative(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 1);\n if (!value) {\n value = PyArray_GenericInplaceBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int\narray_any_nonzero(PyArrayObject *mp)\n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2)\n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_float(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to a \"\\\n\t\t\t\t\"float; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_long(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/\n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected\n*/\n\n\nstatic PyObject *\narray_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t _int_or_ssize_t ihigh)\n{\n PyArrayObject *r;\n _int_or_ssize_t l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n self->dimensions[0] = l;\n\tif (r == NULL) return NULL;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS);\n return (PyObject *)r;\n}\n\n\nstatic int\narray_ass_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t\t_int_or_ssize_t ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res;\n int ret;\n\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\nstatic PySequenceMethods array_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (ssizeargfunc)NULL,\n\t(ssizeargfunc)array_item_nice,\n\t(ssizessizeargfunc)array_slice,\n (ssizeobjargproc)array_ass_item,\t /*sq_ass_item*/\n (ssizessizeobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(ssizeargfunc)NULL,\n#else\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t /*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n#endif\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int\ndump_data(char **string, int *n, int *max_n, char *data, int nd,\n intp *dimensions, intp *strides, PyArrayObject* self)\n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\n if (nd == 0) {\n\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata,\n\t\t self->nd, self->dimensions,\n self->strides, self) < 0) {\n\t\t_pya_free(string); return NULL;\n\t}\n\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void\nPyArray_SetStringFunction(PyObject *op, int repr)\n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_ReprFunction = op;\n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_StrFunction = op;\n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)\n{\n PyObject *array_other, *result;\n\tint typenum;\n\n switch (cmp_op)\n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then return False\n\t\t\t\t This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of False\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the\n\t\t\t two array objects can not be compared together so\n\t\t\t return zero\n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be\n\t\t\t\t compared and cannot be equal, therefore,\n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t other,\n\t\t\t\t\t\t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL,\n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int\n_IsFortranContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap)\n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object\n\t If it is a writeable array, then return TRUE\n\t If we can find an array object\n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable\n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA))\n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly\n\t and unpickled array can be set and reset writeable\n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t\telse ret->flags &= ~WRITEABLE;\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not\n ever be able to walk outside of the memory implied numbytes and offset.\n\n The available memory is assumed to start at -offset and proceed\n to numbytes-offset. The strides are checked to ensure\n that accessing memory using striding will not try to reach beyond\n this memory for any of the axes.\n\n If numbytes is 0 it will be calculated using the dimensions and\n element-size.\n\n This function checks for walking beyond the beginning and right-end\n of the buffer and therefore works for any integer stride (positive\n or negative).\n*/\n\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\tintp byte_begin;\n\tintp begin;\n\tintp end;\n\n\tif (numbytes == 0)\n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\n\tbegin = -offset;\n\tend = numbytes - offset - elsize;\n\tfor (i=0; i end))\n\t\t\treturn FALSE;\n\t}\n\treturn TRUE;\n\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings\n depending on data and strides:\n\n If data is given, then flags is flags associated with data.\n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument\n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set).\n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired.\n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize,\n\t\t int inflag, int *objflags)\n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\n/* and update the dimensions and strides\n appropriately. Dimensions and strides are added\n to the end unless we have a FORTRAN array\n and then they are added to the beginning\n\n Strides are only added if given (because data is given).\n*/\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,\n\t\t\t intp *newstrides, int oldnd, int isfortran)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\tint tuple;\n\n\told = *des;\n\t*des = old->subarray->base;\n\n\n\tmydim = newdims + oldnd;\n\ttuple = PyTuple_Check(old->subarray->shape);\n\tif (tuple) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t}\n\telse {\n\t\tnumnew = 1;\n\t}\n\n\n\tnewnd = oldnd + numnew;\n\tif (newnd > MAX_DIMS) goto finish;\n\tif (isfortran) {\n\t\tmemmove(newdims+numnew, newdims, oldnd*sizeof(intp));\n\t\tmydim = newdims;\n\t}\n\n\tif (tuple) {\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\tif (isfortran) {\n\t\t\tmemmove(newstrides+numnew, newstrides,\n\t\t\t\toldnd*sizeof(intp));\n\t\t\tmystrides = newstrides;\n\t\t}\n\t\t/* Make new strides -- alwasy C-contiguous */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\n finish:\n\tPy_INCREF(*des);\n\tPy_DECREF(old);\n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,\n\t\t intp *dims, intp *strides, void *data,\n\t\t int flags, PyObject *obj)\n{\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tint isfortran=0;\n\t\tisfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || \\\n\t\t\t(!data && flags);\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims,\n\t\t\t\t\t\t newstrides, nd, isfortran);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims,\n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { \n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN;\n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse { /* we allow strides even when we create\n\t\t\t the memory, but be careful with this...\n\t\t */\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays\n\t\t e.g. shape=(0,) -- otherwise buffer exposure\n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in,\n\t\t\t\t\t this object won't own it\n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for\n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype.\n\t If obj is NULL, then call method with Py_None \n\t*/\n\tif ((subtype != &PyArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (strides != NULL) { /* did not allocate own data \n\t\t\t\t\t or funny strides */\n\t\t\t/* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tif (obj == NULL) obj=Py_None;\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n If refcheck is 0, then the reference count is not checked\n and assumed to be 1.\n You still must own this data and have no weak-references and no base\n object.\n*/\nstatic PyObject *\nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\n if (!PyArray_ISONESEGMENT(self)) {\n PyErr_SetString(PyExc_ValueError,\n \"resize only works on single-segment arrays\");\n return NULL;\n }\n\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n\n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (refcheck) refcnt = REFCOUNT(self);\n\t\telse refcnt = 1;\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (newsize == 0) sd = self->descr->elsize;\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n\n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) {\n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0,\n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n\n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n\n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n self->flags, &(self->flags));\n\n\n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\n return Py_None;\n\n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\tPyArray_FillWithScalarFunc* fillwithscalar =\n\t\t\tarr->descr->f->fillwithscalar;\n\t\tif (fillwithscalar && PyArray_ISALIGNED(arr)) {\n\t\t\tcopyswap(fromptr, NULL, swap, itemsize);\n\t\t\tfillwithscalar(toptr, size, fromptr, arr);\n\t\t}\n\t\telse {\n\t\t\twhile (size--) {\n\t\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\t\ttoptr += itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL;\n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous\n\t array of a specific type and shape.\n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims,\n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter,\n &strides,\n &fortran))\n\t\tgoto fail;\n\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"data-type with unspecified variable length\");\n\t\tgoto fail;\n\t}\n\t\n\tif (strides.ptr != NULL) {\n\t\tintp nb, off;\n\t\tif (strides.len != dims.len) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides, if given, must be \"\t\\\n\t\t\t\t\t\"the same length as shape\");\n\t\t\tgoto fail;\n\t\t}\n\n\t\tif (buffer.ptr == NULL) {\n\t\t\tnb = 0;\n\t\t\toff = 0;\n\t\t}\n\t\telse {\n\t\t\tnb = buffer.len;\n\t\t\toff = offset;\n\t\t}\n\t\t\n\n\t\tif (!PyArray_CheckStrides(itemsize, dims.len, \n\t\t\t\t\t nb, off,\n\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides is incompatible \"\t\\\n\t\t\t\t\t\"with shape of requested \"\t\\\n\t\t\t\t\t\"array and size of buffer\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\t\t\t\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len,\n\t\t\t\t\t dims.ptr,\n\t\t\t\t\t strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = (buffer.len-offset) / itemsize;\n }\n else if ((strides.ptr == NULL) && \\\n\t\t\t buffer.len < itemsize*\t\t\t\t\\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError,\n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t offset + (char *)buffer.ptr,\n\t\t\t\t\t buffer.flags, NULL);\n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base);\n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyArray_NewFlagsObject((PyObject *)self);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n\tint nd;\n\tPyObject *ret;\n\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret),\n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret),\n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes=0;\n\tintp offset=0;\n\tint buf_len;\n\tchar *buf;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base && PyArray_Check(new->base)) {\n\t\tnew = (PyArrayObject *)(new->base);\n\t}\n\t/* Get the available memory through the buffer\n\t interface on new->base or if that fails\n\t from the current new */\n\tif (new->base && PyObject_AsReadBuffer(new->base,\n\t\t\t\t\t (const void **)&buf,\n\t\t\t\t\t &buf_len) >= 0) {\n\t\toffset = self->data - buf;\n\t\tnumbytes = buf_len + offset;\n\t}\n\telse {\n\t\tPyErr_Clear();\n \t\tnumbytes = PyArray_MultiplyList(new->dimensions,\n\t\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\toffset = self->data - new->data;\n\t}\n\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes,\n\t\t\t\t offset,\n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self))\n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self)\n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0,\n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf,\n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse\n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse\n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed.\n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the\n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0)\n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n\telse if (newtype->elsize > self->descr->elsize) {\n\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update\n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\t/* We would decref newtype here --- temp will\n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tif (temp == NULL) return -1;\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\tPy_INCREF(temp->descr);\n\t\t/* Fool deallocator not to delete these*/\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype;\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA);\n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num -\n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type,\n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new);\n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int\narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode,\n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr));\n memmove(selfit->dataptr, arrit->dataptr,\n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size)\n PyArray_ITER_RESET(arrit);\n }\n retval = 0;\n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->descr->elsize);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size)\n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\",\n\t (getter)array_ndim_get,\n\t NULL,\n\t \"number of array dimensions\"},\n {\"flags\",\n\t (getter)array_flags_get,\n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\",\n\t (getter)array_shape_get,\n\t (setter)array_shape_set,\n\t \"tuple of array dimensions\"},\n {\"strides\",\n\t (getter)array_strides_get,\n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)array_data_get,\n\t (setter)array_data_set,\n\t \"pointer to start of data\"},\n {\"itemsize\",\n\t (getter)array_itemsize_get,\n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\",\n\t (getter)array_real_get,\n\t (setter)array_real_set,\n\t \"real part of array\"},\n {\"imag\",\n\t (getter)array_imag_get,\n\t (setter)array_imag_set,\n\t \"imaginary part of array\"},\n\t{\"flat\",\n\t (getter)array_flat_get,\n\t (setter)array_flat_set,\n\t \"a 1-d view of a contiguous array\"},\n\t{\"__array_data__\",\n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\",\n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n\t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */\n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] =\n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\nstatic PyTypeObject PyArray_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0,\t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n &array_as_sequence,\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str,\t /*tp_str*/\n\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n &array_as_buffer, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT\n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter,\t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n array_alloc,\t /* tp_alloc */\n (newfunc)array_new,\t\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int\ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple)\n{\n int d=0;\n PyObject *e;\n\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0)\n\t\treturn 1;\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize)\n{\n\tint n, r, i;\n\tPyObject *e;\n\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s)\n\t\t\t*itemsize = MAX(*itemsize, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype ---\n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately\n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE &&\n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\nstatic PyArray_Descr *\n_array_find_python_scalar_type(PyObject *op)\n{\n if (PyFloat_Check(op)) {\n return PyArray_DescrFromType(PyArray_DOUBLE);\n } else if (PyComplex_Check(op)) {\n return PyArray_DescrFromType(PyArray_CDOUBLE);\n } else if (PyInt_Check(op)) {\n /* bools are a subclass of int */\n if (PyBool_Check(op)) {\n return PyArray_DescrFromType(PyArray_BOOL);\n } else {\n return PyArray_DescrFromType(PyArray_LONG);\n }\n } else if (PyLong_Check(op)) {\n /* if integer can fit into a longlong then return that\n */\n if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n PyErr_Clear();\n return PyArray_DescrFromType(PyArray_OBJECT);\n }\n return PyArray_DescrFromType(PyArray_LONGLONG);\n }\n return NULL;\n}\n\n/* op is an object to be converted to an ndarray.\n\n minitype is the minimum type-descriptor needed.\n\n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n\n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\n\tif (minitype == NULL)\n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\n if (max < 0) goto deflt;\n\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n chktype = _array_find_python_scalar_type(op);\n if (chktype) {\n goto finish;\n }\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n\n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind,\n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n }\n\n\tif (PyInstance_Check(op)) goto deflt;\n\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\n finish:\n\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype;\n}\n\nstatic int\nAssign_Array(PyArrayObject *self, PyObject *v)\n{\n PyObject *e;\n int l, r;\n\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\n l=PyObject_Length(v);\n if(l < 0) return -1;\n\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1;\n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */\n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode)\n{\n PyArrayObject *ret;\n\tint itemsize;\n\tint type;\n\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= 4;\n\n\t\tif (itemsize != typecode->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(typecode);\n\t\t\ttypecode->elsize = itemsize;\n\t\t}\n\t}\n\n ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL,\n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\tif (ret == NULL) return NULL;\n\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode */\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string,\n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid input sequence\");\n\t\tgoto fail;\n }\n\n\tif (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {\n\t\tnd = max_depth;\n\t}\n\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid number of dimensions\");\n\t\tgoto fail;\n }\n\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\n if(!r) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int\nPyArray_ValidType(int type)\n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in))\n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, 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\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n oelsize);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject *\nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING)\n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd,\n\t\t\t\t mp->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\n}\n\n/* The number of elements in out must be an integer multiple\n of the number of elements in mp.\n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1;\n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * mpsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr,\n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)\n{\n\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1)\n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse {\n if ((flags & ENSUREARRAY)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype,\n\t\t\t\t\t\t newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr;\n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\n\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong))\n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char))\n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long))\n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap)\n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n\n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL;\n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n\n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data,\n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr));\n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n\n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context)\n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, \n\t\t\t\t\t\t\t\t NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None,\n\t\t\t\t\t\t context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", \n\t\t\t\t\t\t typecode, context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", \n\t\t\t\t\t\t\t typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError,\n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n}\n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,\n int max_depth, int flags, PyObject *context)\n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op))\n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t} else if (newtype == NULL &&\n (newtype = _array_find_python_scalar_type(op))) {\n r = Array_FromScalar(op, newtype);\n }\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, \n\t\t\t\t\t\tflags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\n\t/* Be sure we succeed here */\n\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int\nPyArray_ObjectType(PyObject *op, int minimum_type)\n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of\n CONTIGUOUS,\n FORTRAN,\n ALIGNED,\n WRITEABLE,\n NOTSWAPPED,\n ENSURECOPY,\n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should\n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or\n not it has such features.\n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well.\n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n\n FORTRAN can be set in the FLAGS to request a FORTRAN array.\n Fortran arrays are always behaved (aligned,\n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d).\n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array.\n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe.\n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,\n int max_depth, int requires, PyObject *context)\n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0,\n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place\n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op)) return op;\n\n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int\nPyArray_CanCastSafely(int fromtype, int totype)\n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype))\n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode\n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\n\t\t*/\n\t}\n\treturn ret;\n}\n\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n\n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd;\n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D)\n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic _int_or_ssize_t\niter_length(PyArrayIterObject *self)\n{\n return self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr,\n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1)\n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t 1, &n_steps,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail;\n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0,\n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n\t\t\t\t itemsize);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size)\n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size)\n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)\n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size)\n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0,\n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)iter_length,\t\t /*mp_length*/\n#else\n (inquiry)iter_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op)\n{\n\n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options:\n 1) underlying array is contiguous\n -- return 1-d wrapper around it\n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, it->ao->data,\n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r);\n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n\n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\",\n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &iter_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t\t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular\n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators\n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++)\n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already\n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1)\n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\n\t\t\t\t\t\t\t\"to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of\n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord,\n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t sizeof(intp));\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so,\n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size.\n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere.\n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well.\n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0\n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t/* But, be sure to do it with a true array.\n\t */\n\tif (PyArray_CheckExact(arr)) {\n\t\tsub = array_subscript(arr, mit->indexobj);\n\t}\n\telse {\n\t\tPy_INCREF(arr);\n\t\tobj = PyArray_EnsureArray((PyObject *)arr);\n\t\tif (obj == NULL) goto fail;\n\t\tsub = array_subscript((PyArrayObject *)obj, mit->indexobj);\n\t\tPy_DECREF(obj);\n\t}\n\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects\n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been\n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj))\n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj,\n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1;\n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) *indptr, (int) (dimsize-1),\n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0,\n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n\tmit->index = 0;\n\tmit->ait = NULL;\n\tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY\n#undef SOBJ_ISFANCY\n#undef SOBJ_BADARRAY\n#undef SOBJ_TOOMANY\n#undef SOBJ_LISTTUP\n\n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple\n\t (with at least 1 list or arrayobject or Bool object), */\n\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i,\n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing\n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n\n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work.\n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a);\n mapiter is equivalent to a[indexobj].flat but the latter gets to use\n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t\t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t\t /* tp_iter */\n (iternextfunc)0,\t /* tp_iternext */\n 0,\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\n\tint i, err=0;\n\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\n\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL)\n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i,\n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(multi->iters[i]);\n\t_pya_free(multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\",\n\t (getter)arraymultiter_size_get,\n\t NULL,\n\t \"total size of broadcasted result\"},\n {\"index\",\n\t (getter)arraymultiter_index_get,\n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter),\n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t\t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods,\t /* tp_methods */\n arraymultiter_members,\t\t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types.\n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these\n builtins will be attempted leading to problems.\n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically\n allocated).\n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless\n there is a reference-count problem\n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set.\n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base,\n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0)\n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\",\n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self)\n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\",\n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr)\n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr)\n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv))\n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\n\t/* Now return the state which is at least\n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize\n and alignment for EXTENDED arrays\n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\n\tif (PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are:\n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args)\n{\n\tchar endian=PyArray_SWAP;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS,\n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n\tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\ndescr_length(PyArray_Descr *self)\n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op)\n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError,\n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)descr_length,\t\t /*mp_length*/\n#else\n (inquiry)descr_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t\t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &descr_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t/* tp_iternext */\n arraydescr_methods,\t\t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n\n/** Array Flags Object **/\n\ntypedef struct PyArrayFlagsObject {\n PyObject_HEAD\n PyObject *arr;\n int flags;\n} PyArrayFlagsObject;\n\n/*OBJECT_API\n Get New ArrayFlagsObject\n*/\nstatic PyObject *\nPyArray_NewFlagsObject(PyObject *obj)\n{\n PyObject *flagobj;\n int flags;\n if (obj == NULL) {\n flags = CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n }\n else {\n flags = PyArray_FLAGS(obj);\n }\n flagobj = PyArrayFlags_Type.tp_alloc(&PyArrayFlags_Type, 0);\n if (flagobj == NULL) return NULL;\n Py_XINCREF(obj);\n ((PyArrayFlagsObject *)flagobj)->arr = obj;\n ((PyArrayFlagsObject *)flagobj)->flags = flags;\n\n return flagobj;\n}\n\nstatic void\narrayflags_dealloc(PyArrayFlagsObject *self)\n{\n\tPy_XDECREF(self->arr);\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n\n#define _define_get(UPPER, lower) \\\nstatic PyObject * \\\narrayflags_ ## lower ## _get(PyArrayFlagsObject *self) \\\n{ \\\n PyObject *item; \\\n item = ((self->flags & (UPPER)) == (UPPER)) ? Py_True : Py_False; \\\n Py_INCREF(item); \\\n return item; \\\n}\n\n_define_get(CONTIGUOUS, contiguous)\n_define_get(FORTRAN, fortran)\n_define_get(UPDATEIFCOPY, updateifcopy)\n_define_get(OWNDATA, owndata)\n_define_get(ALIGNED, aligned)\n_define_get(WRITEABLE, writeable)\n\n_define_get(ALIGNED|WRITEABLE, behaved)\n_define_get(ALIGNED|WRITEABLE|CONTIGUOUS, carray)\n\nstatic PyObject *\narrayflags_forc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) ||\n ((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_fnc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_farray_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & (ALIGNED|WRITEABLE|FORTRAN)) == \\\n (ALIGNED|WRITEABLE|FORTRAN)) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_num_get(PyArrayFlagsObject *self)\n{\n return PyInt_FromLong(self->flags);\n}\n\n/* relies on setflags order being write, align, uic */\nstatic int\narrayflags_updateifcopy_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False));\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_aligned_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_writeable_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None, Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\n\nstatic PyGetSetDef arrayflags_getsets[] = {\n\t{\"contiguous\",\n\t (getter)arrayflags_contiguous_get,\n\t NULL,\n\t \"\"},\n {\"fortran\",\n (getter)arrayflags_fortran_get,\n NULL,\n \"\"},\n {\"updateifcopy\",\n (getter)arrayflags_updateifcopy_get,\n (setter)arrayflags_updateifcopy_set,\n \"\"},\n {\"owndata\",\n (getter)arrayflags_owndata_get,\n NULL,\n \"\"},\n {\"aligned\",\n (getter)arrayflags_aligned_get,\n (setter)arrayflags_aligned_set,\n \"\"},\n {\"writeable\",\n (getter)arrayflags_writeable_get,\n (setter)arrayflags_writeable_set,\n \"\"},\n {\"fnc\",\n (getter)arrayflags_fnc_get,\n NULL,\n \"\"},\n {\"forc\",\n (getter)arrayflags_forc_get,\n NULL,\n \"\"},\n {\"behaved\",\n (getter)arrayflags_behaved_get,\n NULL,\n \"\"},\n {\"carray\",\n (getter)arrayflags_carray_get,\n NULL,\n \"\"},\n {\"farray\",\n (getter)arrayflags_farray_get,\n NULL,\n \"\"},\n {\"num\",\n (getter)arrayflags_num_get,\n NULL,\n \"\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyObject *\narrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)\n{\n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n if ((strncmp(key,\"CONTIGUOUS\",n)==0) ||\n (strncmp(key,\"C\",n)))\n return arrayflags_contiguous_get(self);\n else if ((strncmp(key, \"FORTRAN\", n)==0) ||\n (strncmp(key, \"F\", n)==0)) \n return arrayflags_fortran_get(self);\n else if ((strncmp(key, \"WRITEABLE\", n)==0) ||\n (strncmp(key, \"W\", n)==0))\n return arrayflags_writeable_get(self);\n else if ((strncmp(key, \"BEHAVED\", n)==0) ||\n (strncmp(key, \"B\", n)==0))\n return arrayflags_behaved_get(self);\n else if ((strncmp(key, \"OWNDATA\", n)==0) ||\n (strncmp(key, \"O\", n)==0))\n return arrayflags_owndata_get(self);\n else if ((strncmp(key, \"ALIGNED\", n)==0) ||\n (strncmp(key, \"A\", n)==0))\n return arrayflags_aligned_get(self);\n else if ((strncmp(key, \"UPDATEIFCOPY\", n)==0) ||\n (strncmp(key, \"U\", n)==0))\n return arrayflags_updateifcopy_get(self);\n else if ((strncmp(key, \"FNC\", n)==0))\n return arrayflags_fnc_get(self);\n else if ((strncmp(key, \"FORC\", n)==0))\n return arrayflags_forc_get(self);\n else if ((strncmp(key, \"CARRAY\", n)==0) ||\n (strncmp(key, \"CA\", n)==0))\n return arrayflags_carray_get(self);\n else if ((strncmp(key, \"FARRAY\", n)==0) ||\n (strncmp(key, \"FA\", n)==0))\n return arrayflags_farray_get(self);\n else goto fail;\n\n fail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return NULL;\n}\n\nstatic int\narrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)\n{ \n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n if ((strncmp(key, \"WRITEABLE\", n)==0) ||\n (strncmp(key, \"W\", n)==0))\n return arrayflags_writeable_set(self, item);\n else if ((strncmp(key, \"ALIGNED\", n)==0) ||\n (strncmp(key, \"A\", n)==0))\n return arrayflags_aligned_set(self, item);\n else if ((strncmp(key, \"UPDATEIFCOPY\", n)==0) ||\n (strncmp(key, \"U\", n)==0))\n return arrayflags_updateifcopy_set(self, item); \n else goto fail;\n return 0;\n\nfail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return -1;\n}\n\nstatic char *\n_torf_(int flags, int val)\n{\n if ((flags & val) == val) return \"True\";\n else return \"False\"; \n}\n\nstatic PyObject *\narrayflags_print(PyArrayFlagsObject *self)\n{\n int fl = self->flags;\n \n return PyString_FromFormat(\" %s : %s\\n %s : %s\\n %s : %s\\n\"\\\n \" %s : %s\\n %s : %s\\n %s : %s\",\n \"CONTIGUOUS\", _torf_(fl, CONTIGUOUS),\n \"FORTRAN\", _torf_(fl, FORTRAN),\n \"OWNDATA\", _torf_(fl, OWNDATA),\n \"WRITEABLE\", _torf_(fl, WRITEABLE),\n \"ALIGNED\", _torf_(fl, ALIGNED),\n \"UPDATEIFCOPY\", _torf_(fl, UPDATEIFCOPY));\n}\n\n\nstatic PyMappingMethods arrayflags_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)NULL, \t\t /*mp_length*/\n#else\n (inquiry)NULL, \t\t /*mp_length*/\n#endif\n (binaryfunc)arrayflags_getitem,\t /*mp_subscript*/\n (objobjargproc)arrayflags_setitem, /*mp_ass_subscript*/\n};\n\n\nstatic PyObject *\narrayflags_new(PyTypeObject *self, PyObject *args, PyObject *kwds)\n{\n PyObject *arg=NULL;\n if (!PyArg_UnpackTuple(args, \"flagsobj\", 0, 1, &arg))\n return NULL;\n\n if ((arg != NULL) && PyArray_Check(arg)) {\n return PyArray_NewFlagsObject(arg);\n }\n else {\n return PyArray_NewFlagsObject(NULL);\n }\n}\n\nstatic PyTypeObject PyArrayFlags_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\n \"numpy.flagsobj\",\n sizeof(PyArrayFlagsObject),\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayflags_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t0,\t\t /* tp_compare */\n (reprfunc)arrayflags_print, /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &arrayflags_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arrayflags_print, /* tp_str */\n 0,\t \t /* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t /* tp_iternext */\n 0,\t \t /* tp_methods */\n 0,\t /* tp_members */\n arrayflags_getsets, /* tp_getset */\n 0,\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t /* tp_init */\n 0,\t /* tp_alloc */\n arrayflags_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "source_code_before": "/*\n Provide multidimensional arrays as a basic object type in python.\n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004\n\nHeavily modified in 2005 with inspiration from Numarray\n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University\n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by\nSpace Science Telescope Institute\n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_)\n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear();\n priority = default_;\n }\n Py_XDECREF(ret);\n return priority;\n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a\n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n }\n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int\ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides,\n\t intp *src_dimensions, int src_nd, int elsize,\n\t int copies) {\n intp i, j;\n\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1,\n dest_dimensions+1, dest_nd-1,\n src, src_strides,\n src_dimensions, src_nd,\n elsize, copies) == -1)\n return -1;\n }\n return 0;\n }\n\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError,\n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) &&\n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] !=\n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src)\n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\n dest_strides_ptr = dest_strides;\n\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1)\n return NULL;\n\n new_data = (char *)_pya_malloc(stride);\n\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions,\n dest_nd, src->data, src_strides,\n src_dimensions, src_nd, elsize, copies);\n\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *,\n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int\nPyArray_INCREF(PyArrayObject *mp)\n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap)\n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n\n\n if ((numitems == 1) || (itemsize == srcstrides))\n memcpy(d1, s1, itemsize*numitems);\n else {\n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n }\n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG\n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i)\n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp\nPyArray_Size(PyObject *op)\n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n }\n\telse {\n return 0;\n }\n}\n\n/* If destination is not the right type, then src\n will be cast to destination.\n*/\n\n/* Does a flat iterator-based copy.\n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however.\n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n\n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError,\n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n\n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, elsize);\n PyArray_INCREF(dest);\n return 0;\n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n }\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int\nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)\n{\n PyArrayObject *src;\n int ret;\n\t\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d,\n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t}\n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,\n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd,\n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran,\n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\n return (PyObject *)ret;\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) {\n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED;\n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=0;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use\n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifndef Py_UNICODE_WIDE\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\treturn obj;\n#endif\n\t\t}\n\t\telse {\n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, itemsize);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this.\n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag\n*/\n\n/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp)\n{\n\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n\n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int\nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs,\n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/*\n copyies over from the old descr table for anything\n NULL or zero in what is given.\n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)\n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data,\n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError,\n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr,\n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element\"\\\n \" %d to file\",\n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj);\n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj),\n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\",\n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1)\n fwrite(sep, 1, n3, fp);\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self)\n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0)\n\t\treturn self->descr->f->getitem(self->data,self);\n\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n\n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void\narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an\n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE\n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n\n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\narray_length(PyArrayObject *self)\n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i)\n{\n\tchar *item;\n\tPyArrayObject *r;\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1,\n\t\t\t\t\t\t self->dimensions+1,\n\t\t\t\t\t\t self->strides+1, item,\n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\nstatic PyObject *\narray_item_nice(PyArrayObject *self, _int_or_ssize_t i)\n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\n\nstatic int\narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v)\n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret;\n }\n\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if PY_VERSION_HEX < 0x02050000\n #if SIZEOF_INT == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#else\n #if SIZEOF_SIZE_T == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#endif\n#ifndef array_ass_item\nstatic int\narray_ass_item(PyArrayObject *self, _int_or_ssize_t i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int\nparse_index(PyArrayObject *self, PyObject *op,\n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError,\n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\n nd_old = nd_new = 0;\n\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n\t/* tuple for transpose is\n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of\n\t the broadcasted index array\n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the\n\t result\n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2)\n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call.\n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type,\n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret))\n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, PyArray_ITEMSIZE(arr));\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS];\n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL)\n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0\n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from\n Python when using a[object] unless object is a standard slice object\n (not an extended one).\n\n*/\n\n/* There are two situations:\n\n 1 - the subscript is a standard view and a reference to the\n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned.\n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *);\n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op)\n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr,\n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis) {\n\t\t\t/* XXX: This leads to a small inconsistency\n\t\t\t XXX: with the nd>0 case where (x[...] is x)\n\t\t\t XXX: is false for nd>0 case. */\n\t\t\tPy_INCREF(self);\n\t\t\treturn (PyObject *)self;\n\t\t}\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op)) {\n\t\t\t\tPy_INCREF(self);\n\t\t\t\treturn (PyObject *)self;\n\t\t\t}\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset))\n == -1)\n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset,\n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL)\n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be\n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *);\n\nstatic int\narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)\n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr,\n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1;\n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to\n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op)\n{\n\t/* The following is just a copy of PyArray_Return with an\n\t additional logic in the nd == 0 case. More efficient\n\t implementation may be possible by refactoring\n\t array_subscript */\n\n\tPyArrayObject *mp = (PyArrayObject *)array_subscript(self, op);\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tBool noellipses = TRUE;\n\t\tif (op == Py_Ellipsis)\n\t\t\tnoellipses = FALSE;\n\t\telse if (PySequence_Check(op)) {\n\t\t\tint n, i;\n\t\t\tn = PySequence_Size(op);\n\t\t\tfor (i = 0; i < n; ++i) \n\t\t\t\tif (PySequence_GetItem(op, i) == Py_Ellipsis) {\n\t\t\t\t\tnoellipses = FALSE;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t\tif (noellipses) {\n\t\t\tPyObject *ret;\n\t\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\t\tPy_DECREF(mp);\n\t\t\treturn ret;\n\t\t}\n\t}\n\treturn (PyObject *)mp;\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t /*mp_length*/\n#else\n (inquiry)array_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic _int_or_ssize_t\narray_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp)\n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic _int_or_ssize_t\narray_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"accessing non-existing array segment\");\n return -1;\n }\n\n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic _int_or_ssize_t\narray_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (PyArray_CHKFLAGS(self, WRITEABLE))\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic _int_or_ssize_t\narray_getcharbuf(PyArrayObject *self, _int_or_ssize_t segment, const char **ptrptr)\n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError,\n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (writebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (segcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (charbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#else\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#endif\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n *square,\n *reciprocal,\n *ones_like,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum,\n\t\t*rint;\n} NumericOps;\n\nstatic NumericOps n_ops; /* NB: static objects inlitialized to zero */\n\n/* Dictionary can contain any of the numeric operations, by name.\n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n\n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint\nPyArray_SetNumericOps(PyObject *dict)\n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n SET(square);\n SET(reciprocal);\n SET(ones_like);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\n SET(true_divide);\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n\tSET(rint);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void)\n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL)\n\t\treturn NULL;\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n GET(square);\n GET(reciprocal);\n GET(ones_like);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide);\n GET(true_divide);\n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\tGET(rint);\n\treturn dict;\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,\n\t\t\t\t PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2)\n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\n\nstatic PyObject *array_float(PyArrayObject *v);\n\n\nstatic int\narray_power_is_scalar(PyObject *o2, double* exp)\n{\n PyObject *temp;\n const int optimize_fpexps = 1;\n if (PyInt_Check(o2)) {\n *exp = (double)PyInt_AsLong(o2);\n return 1;\n }\n if (optimize_fpexps && PyFloat_Check(o2)) {\n *exp = PyFloat_AsDouble(o2);\n return 1;\n }\n if (PyArray_CheckScalar(o2)) {\n if (PyArray_ISINTEGER(o2) || (optimize_fpexps && PyArray_ISFLOAT(o2))) {\n temp = array_float((PyArrayObject *)o2);\n if (temp != NULL) {\n *exp = PyFloat_AsDouble(o2);\n Py_DECREF(temp);\n return 1;\n }\n }\n }\n return 0;\n}\n\n/* optimize float array or complex array to a scalar power */\nstatic PyObject *\nfast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) {\n double exp;\n if (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) || PyArray_ISCOMPLEX(a1))) {\n if (array_power_is_scalar(o2, &exp)) {\n PyObject *fastop = NULL;\n if (exp == 1.0) {\n /* we have to do this one special, as the \"copy\" method of\n array objects isn't set up early enough to be added\n by PyArray_SetNumericOps.\n */\n if (inplace) {\n return (PyObject *)a1;\n } else {\n return PyArray_Copy(a1);\n }\n } else if (exp == -1.0) {\n fastop = n_ops.reciprocal;\n } else if (exp == 0.0) {\n fastop = n_ops.ones_like;\n } else if (exp == 0.5) {\n fastop = n_ops.sqrt;\n } else if (exp == 2.0) {\n fastop = n_ops.square;\n } else {\n return NULL;\n }\n if (inplace) {\n PyArray_GenericInplaceUnaryFunction(a1, fastop);\n } else {\n return PyArray_GenericUnaryFunction(a1, fastop);\n }\n }\n }\n return NULL;\n}\n\nstatic PyObject *\narray_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 0);\n if (!value) {\n value = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\n\nstatic PyObject *\narray_negative(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 1);\n if (!value) {\n value = PyArray_GenericInplaceBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int\narray_any_nonzero(PyArrayObject *mp)\n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2)\n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_float(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to a \"\\\n\t\t\t\t\"float; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_long(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/\n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected\n*/\n\n\nstatic PyObject *\narray_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t _int_or_ssize_t ihigh)\n{\n PyArrayObject *r;\n _int_or_ssize_t l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n self->dimensions[0] = l;\n\tif (r == NULL) return NULL;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS);\n return (PyObject *)r;\n}\n\n\nstatic int\narray_ass_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t\t_int_or_ssize_t ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res;\n int ret;\n\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\nstatic PySequenceMethods array_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (ssizeargfunc)NULL,\n\t(ssizeargfunc)array_item_nice,\n\t(ssizessizeargfunc)array_slice,\n (ssizeobjargproc)array_ass_item,\t /*sq_ass_item*/\n (ssizessizeobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(ssizeargfunc)NULL,\n#else\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t /*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n#endif\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int\ndump_data(char **string, int *n, int *max_n, char *data, int nd,\n intp *dimensions, intp *strides, PyArrayObject* self)\n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\n if (nd == 0) {\n\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata,\n\t\t self->nd, self->dimensions,\n self->strides, self) < 0) {\n\t\t_pya_free(string); return NULL;\n\t}\n\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void\nPyArray_SetStringFunction(PyObject *op, int repr)\n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_ReprFunction = op;\n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_StrFunction = op;\n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)\n{\n PyObject *array_other, *result;\n\tint typenum;\n\n switch (cmp_op)\n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then return False\n\t\t\t\t This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of False\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the\n\t\t\t two array objects can not be compared together so\n\t\t\t return zero\n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be\n\t\t\t\t compared and cannot be equal, therefore,\n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t other,\n\t\t\t\t\t\t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL,\n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int\n_IsFortranContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap)\n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object\n\t If it is a writeable array, then return TRUE\n\t If we can find an array object\n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable\n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA))\n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly\n\t and unpickled array can be set and reset writeable\n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t\telse ret->flags &= ~WRITEABLE;\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not\n ever be able to walk outside of the memory implied numbytes and offset.\n\n The available memory is assumed to start at -offset and proceed\n to numbytes-offset. The strides are checked to ensure\n that accessing memory using striding will not try to reach beyond\n this memory for any of the axes.\n\n If numbytes is 0 it will be calculated using the dimensions and\n element-size.\n\n This function checks for walking beyond the beginning and right-end\n of the buffer and therefore works for any integer stride (positive\n or negative).\n*/\n\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\tintp byte_begin;\n\tintp begin;\n\tintp end;\n\n\tif (numbytes == 0)\n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\n\tbegin = -offset;\n\tend = numbytes - offset - elsize;\n\tfor (i=0; i end))\n\t\t\treturn FALSE;\n\t}\n\treturn TRUE;\n\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings\n depending on data and strides:\n\n If data is given, then flags is flags associated with data.\n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument\n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set).\n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired.\n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize,\n\t\t int inflag, int *objflags)\n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\n/* and update the dimensions and strides\n appropriately. Dimensions and strides are added\n to the end unless we have a FORTRAN array\n and then they are added to the beginning\n\n Strides are only added if given (because data is given).\n*/\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,\n\t\t\t intp *newstrides, int oldnd, int isfortran)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\tint tuple;\n\n\told = *des;\n\t*des = old->subarray->base;\n\n\n\tmydim = newdims + oldnd;\n\ttuple = PyTuple_Check(old->subarray->shape);\n\tif (tuple) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t}\n\telse {\n\t\tnumnew = 1;\n\t}\n\n\n\tnewnd = oldnd + numnew;\n\tif (newnd > MAX_DIMS) goto finish;\n\tif (isfortran) {\n\t\tmemmove(newdims+numnew, newdims, oldnd*sizeof(intp));\n\t\tmydim = newdims;\n\t}\n\n\tif (tuple) {\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\tif (isfortran) {\n\t\t\tmemmove(newstrides+numnew, newstrides,\n\t\t\t\toldnd*sizeof(intp));\n\t\t\tmystrides = newstrides;\n\t\t}\n\t\t/* Make new strides -- alwasy C-contiguous */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\n finish:\n\tPy_INCREF(*des);\n\tPy_DECREF(old);\n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,\n\t\t intp *dims, intp *strides, void *data,\n\t\t int flags, PyObject *obj)\n{\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tint isfortran=0;\n\t\tisfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || \\\n\t\t\t(!data && flags);\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims,\n\t\t\t\t\t\t newstrides, nd, isfortran);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims,\n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { \n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN;\n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse { /* we allow strides even when we create\n\t\t\t the memory, but be careful with this...\n\t\t */\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays\n\t\t e.g. shape=(0,) -- otherwise buffer exposure\n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in,\n\t\t\t\t\t this object won't own it\n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for\n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype.\n\t If obj is NULL, then call method with Py_None \n\t*/\n\tif ((subtype != &PyArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (strides != NULL) { /* did not allocate own data \n\t\t\t\t\t or funny strides */\n\t\t\t/* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tif (obj == NULL) obj=Py_None;\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n If refcheck is 0, then the reference count is not checked\n and assumed to be 1.\n You still must own this data and have no weak-references and no base\n object.\n*/\nstatic PyObject *\nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\n if (!PyArray_ISONESEGMENT(self)) {\n PyErr_SetString(PyExc_ValueError,\n \"resize only works on single-segment arrays\");\n return NULL;\n }\n\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n\n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (refcheck) refcnt = REFCOUNT(self);\n\t\telse refcnt = 1;\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (newsize == 0) sd = self->descr->elsize;\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n\n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) {\n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0,\n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n\n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n\n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n self->flags, &(self->flags));\n\n\n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\n return Py_None;\n\n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\tPyArray_FillWithScalarFunc* fillwithscalar =\n\t\t\tarr->descr->f->fillwithscalar;\n\t\tif (fillwithscalar && PyArray_ISALIGNED(arr)) {\n\t\t\tcopyswap(fromptr, NULL, swap, itemsize);\n\t\t\tfillwithscalar(toptr, size, fromptr, arr);\n\t\t}\n\t\telse {\n\t\t\twhile (size--) {\n\t\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\t\ttoptr += itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL;\n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous\n\t array of a specific type and shape.\n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims,\n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter,\n &strides,\n &fortran))\n\t\tgoto fail;\n\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"data-type with unspecified variable length\");\n\t\tgoto fail;\n\t}\n\t\n\tif (strides.ptr != NULL) {\n\t\tintp nb, off;\n\t\tif (strides.len != dims.len) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides, if given, must be \"\t\\\n\t\t\t\t\t\"the same length as shape\");\n\t\t\tgoto fail;\n\t\t}\n\n\t\tif (buffer.ptr == NULL) {\n\t\t\tnb = 0;\n\t\t\toff = 0;\n\t\t}\n\t\telse {\n\t\t\tnb = buffer.len;\n\t\t\toff = offset;\n\t\t}\n\t\t\n\n\t\tif (!PyArray_CheckStrides(itemsize, dims.len, \n\t\t\t\t\t nb, off,\n\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides is incompatible \"\t\\\n\t\t\t\t\t\"with shape of requested \"\t\\\n\t\t\t\t\t\"array and size of buffer\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\t\t\t\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len,\n\t\t\t\t\t dims.ptr,\n\t\t\t\t\t strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = (buffer.len-offset) / itemsize;\n }\n else if ((strides.ptr == NULL) && \\\n\t\t\t buffer.len < itemsize*\t\t\t\t\\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError,\n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t offset + (char *)buffer.ptr,\n\t\t\t\t\t buffer.flags, NULL);\n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base);\n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\",\n self, self->flags, 0);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n\tint nd;\n\tPyObject *ret;\n\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret),\n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret),\n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes=0;\n\tintp offset=0;\n\tint buf_len;\n\tchar *buf;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base && PyArray_Check(new->base)) {\n\t\tnew = (PyArrayObject *)(new->base);\n\t}\n\t/* Get the available memory through the buffer\n\t interface on new->base or if that fails\n\t from the current new */\n\tif (new->base && PyObject_AsReadBuffer(new->base,\n\t\t\t\t\t (const void **)&buf,\n\t\t\t\t\t &buf_len) >= 0) {\n\t\toffset = self->data - buf;\n\t\tnumbytes = buf_len + offset;\n\t}\n\telse {\n\t\tPyErr_Clear();\n \t\tnumbytes = PyArray_MultiplyList(new->dimensions,\n\t\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\toffset = self->data - new->data;\n\t}\n\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes,\n\t\t\t\t offset,\n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self))\n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self)\n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0,\n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf,\n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse\n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse\n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed.\n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the\n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0)\n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n\telse if (newtype->elsize > self->descr->elsize) {\n\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update\n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\t/* We would decref newtype here --- temp will\n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tif (temp == NULL) return -1;\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\tPy_INCREF(temp->descr);\n\t\t/* Fool deallocator not to delete these*/\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype;\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA);\n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num -\n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type,\n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new);\n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int\narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode,\n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr));\n memmove(selfit->dataptr, arrit->dataptr,\n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size)\n PyArray_ITER_RESET(arrit);\n }\n retval = 0;\n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->descr->elsize);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size)\n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\",\n\t (getter)array_ndim_get,\n\t NULL,\n\t \"number of array dimensions\"},\n {\"flags\",\n\t (getter)array_flags_get,\n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\",\n\t (getter)array_shape_get,\n\t (setter)array_shape_set,\n\t \"tuple of array dimensions\"},\n {\"strides\",\n\t (getter)array_strides_get,\n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)array_data_get,\n\t (setter)array_data_set,\n\t \"pointer to start of data\"},\n {\"itemsize\",\n\t (getter)array_itemsize_get,\n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\",\n\t (getter)array_real_get,\n\t (setter)array_real_set,\n\t \"real part of array\"},\n {\"imag\",\n\t (getter)array_imag_get,\n\t (setter)array_imag_set,\n\t \"imaginary part of array\"},\n\t{\"flat\",\n\t (getter)array_flat_get,\n\t (setter)array_flat_set,\n\t \"a 1-d view of a contiguous array\"},\n\t{\"__array_data__\",\n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\",\n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n\t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */\n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] =\n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\nstatic PyTypeObject PyArray_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0,\t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n &array_as_sequence,\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str,\t /*tp_str*/\n\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n &array_as_buffer, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT\n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter,\t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n array_alloc,\t /* tp_alloc */\n (newfunc)array_new,\t\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int\ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple)\n{\n int d=0;\n PyObject *e;\n\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0)\n\t\treturn 1;\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize)\n{\n\tint n, r, i;\n\tPyObject *e;\n\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s)\n\t\t\t*itemsize = MAX(*itemsize, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype ---\n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately\n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE &&\n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\nstatic PyArray_Descr *\n_array_find_python_scalar_type(PyObject *op)\n{\n if (PyFloat_Check(op)) {\n return PyArray_DescrFromType(PyArray_DOUBLE);\n } else if (PyComplex_Check(op)) {\n return PyArray_DescrFromType(PyArray_CDOUBLE);\n } else if (PyInt_Check(op)) {\n /* bools are a subclass of int */\n if (PyBool_Check(op)) {\n return PyArray_DescrFromType(PyArray_BOOL);\n } else {\n return PyArray_DescrFromType(PyArray_LONG);\n }\n } else if (PyLong_Check(op)) {\n /* if integer can fit into a longlong then return that\n */\n if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n PyErr_Clear();\n return PyArray_DescrFromType(PyArray_OBJECT);\n }\n return PyArray_DescrFromType(PyArray_LONGLONG);\n }\n return NULL;\n}\n\n/* op is an object to be converted to an ndarray.\n\n minitype is the minimum type-descriptor needed.\n\n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n\n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\n\tif (minitype == NULL)\n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\n if (max < 0) goto deflt;\n\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n chktype = _array_find_python_scalar_type(op);\n if (chktype) {\n goto finish;\n }\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n\n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind,\n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n }\n\n\tif (PyInstance_Check(op)) goto deflt;\n\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\n finish:\n\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype;\n}\n\nstatic int\nAssign_Array(PyArrayObject *self, PyObject *v)\n{\n PyObject *e;\n int l, r;\n\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\n l=PyObject_Length(v);\n if(l < 0) return -1;\n\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1;\n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */\n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode)\n{\n PyArrayObject *ret;\n\tint itemsize;\n\tint type;\n\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= 4;\n\n\t\tif (itemsize != typecode->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(typecode);\n\t\t\ttypecode->elsize = itemsize;\n\t\t}\n\t}\n\n ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL,\n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\tif (ret == NULL) return NULL;\n\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode */\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string,\n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid input sequence\");\n\t\tgoto fail;\n }\n\n\tif (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {\n\t\tnd = max_depth;\n\t}\n\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid number of dimensions\");\n\t\tgoto fail;\n }\n\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\n if(!r) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int\nPyArray_ValidType(int type)\n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in))\n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, 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\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n oelsize);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject *\nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING)\n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd,\n\t\t\t\t mp->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\n}\n\n/* The number of elements in out must be an integer multiple\n of the number of elements in mp.\n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1;\n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * mpsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr,\n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)\n{\n\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1)\n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse {\n if ((flags & ENSUREARRAY)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype,\n\t\t\t\t\t\t newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr;\n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\n\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong))\n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char))\n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long))\n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap)\n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n\n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL;\n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n\n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data,\n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr));\n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n\n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context)\n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, \n\t\t\t\t\t\t\t\t NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None,\n\t\t\t\t\t\t context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", \n\t\t\t\t\t\t typecode, context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", \n\t\t\t\t\t\t\t typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError,\n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n}\n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,\n int max_depth, int flags, PyObject *context)\n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op))\n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t} else if (newtype == NULL &&\n (newtype = _array_find_python_scalar_type(op))) {\n r = Array_FromScalar(op, newtype);\n }\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, \n\t\t\t\t\t\tflags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\n\t/* Be sure we succeed here */\n\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int\nPyArray_ObjectType(PyObject *op, int minimum_type)\n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of\n CONTIGUOUS,\n FORTRAN,\n ALIGNED,\n WRITEABLE,\n NOTSWAPPED,\n ENSURECOPY,\n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should\n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or\n not it has such features.\n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well.\n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n\n FORTRAN can be set in the FLAGS to request a FORTRAN array.\n Fortran arrays are always behaved (aligned,\n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d).\n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array.\n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe.\n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,\n int max_depth, int requires, PyObject *context)\n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0,\n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place\n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op)) return op;\n\n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int\nPyArray_CanCastSafely(int fromtype, int totype)\n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype))\n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode\n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\n\t\t*/\n\t}\n\treturn ret;\n}\n\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n\n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd;\n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D)\n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic _int_or_ssize_t\niter_length(PyArrayIterObject *self)\n{\n return self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr,\n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1)\n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t 1, &n_steps,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail;\n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0,\n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n\t\t\t\t itemsize);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size)\n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size)\n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)\n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size)\n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0,\n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)iter_length,\t\t /*mp_length*/\n#else\n (inquiry)iter_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op)\n{\n\n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options:\n 1) underlying array is contiguous\n -- return 1-d wrapper around it\n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, it->ao->data,\n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r);\n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n\n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\",\n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &iter_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t\t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular\n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators\n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++)\n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already\n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1)\n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\n\t\t\t\t\t\t\t\"to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of\n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord,\n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t sizeof(intp));\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so,\n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size.\n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere.\n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well.\n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0\n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t/* But, be sure to do it with a true array.\n\t */\n\tif (PyArray_CheckExact(arr)) {\n\t\tsub = array_subscript(arr, mit->indexobj);\n\t}\n\telse {\n\t\tPy_INCREF(arr);\n\t\tobj = PyArray_EnsureArray((PyObject *)arr);\n\t\tif (obj == NULL) goto fail;\n\t\tsub = array_subscript((PyArrayObject *)obj, mit->indexobj);\n\t\tPy_DECREF(obj);\n\t}\n\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects\n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been\n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj))\n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj,\n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1;\n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) *indptr, (int) (dimsize-1),\n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0,\n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n\tmit->index = 0;\n\tmit->ait = NULL;\n\tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY\n#undef SOBJ_ISFANCY\n#undef SOBJ_BADARRAY\n#undef SOBJ_TOOMANY\n#undef SOBJ_LISTTUP\n\n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple\n\t (with at least 1 list or arrayobject or Bool object), */\n\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i,\n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing\n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n\n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work.\n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a);\n mapiter is equivalent to a[indexobj].flat but the latter gets to use\n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t\t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t\t /* tp_iter */\n (iternextfunc)0,\t /* tp_iternext */\n 0,\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\n\tint i, err=0;\n\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\n\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL)\n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i,\n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(multi->iters[i]);\n\t_pya_free(multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\",\n\t (getter)arraymultiter_size_get,\n\t NULL,\n\t \"total size of broadcasted result\"},\n {\"index\",\n\t (getter)arraymultiter_index_get,\n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter),\n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t\t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods,\t /* tp_methods */\n arraymultiter_members,\t\t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types.\n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these\n builtins will be attempted leading to problems.\n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically\n allocated).\n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless\n there is a reference-count problem\n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free(self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set.\n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base,\n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0)\n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\",\n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self)\n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\",\n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr)\n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr)\n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv))\n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\n\t/* Now return the state which is at least\n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize\n and alignment for EXTENDED arrays\n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\n\tif (PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are:\n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args)\n{\n\tchar endian=PyArray_SWAP;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS,\n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n\tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\ndescr_length(PyArray_Descr *self)\n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op)\n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError,\n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)descr_length,\t\t /*mp_length*/\n#else\n (inquiry)descr_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t\t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &descr_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t/* tp_iternext */\n arraydescr_methods,\t\t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "methods": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 76, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 65, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 99, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 134, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 207, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 241, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 291, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 319, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 344, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 387, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 427, + "end_line": 509, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 516, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 593, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Size", + "long_name": "PyArray_Size( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 33, + "parameters": [ + "op" + ], + "start_line": 614, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 638, + "end_line": 718, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyObject", + "long_name": "PyArray_CopyObject( PyArrayObject * dest , PyObject * src_object)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 722, + "end_line": 736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDimsAndDataAndDescr", + "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 137, + "parameters": [ + "nd", + "d", + "descr", + "data" + ], + "start_line": 749, + "end_line": 775, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDims", + "long_name": "PyArray_FromDims( int nd , int * d , int type)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "nd", + "d", + "type" + ], + "start_line": 781, + "end_line": 795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewCopy", + "long_name": "PyArray_NewCopy( PyArrayObject * m1 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 804, + "end_line": 824, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 17, + "token_count": 616, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 833, + "end_line": 949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 965, + "end_line": 968, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Return", + "long_name": "PyArray_Return( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 91, + "parameters": [ + "mp" + ], + "start_line": 978, + "end_line": 1000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDataType", + "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 9, + "token_count": 229, + "parameters": [ + "type" + ], + "start_line": 1014, + "end_line": 1054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDescrForType", + "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 214, + "parameters": [ + "typenum", + "descr" + ], + "start_line": 1069, + "end_line": 1110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToFile", + "long_name": "PyArray_ToFile( PyArrayObject * self , FILE * fp , char * sep , char * format)", + "filename": "arrayobject.c", + "nloc": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1117, + "end_line": 1208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToList", + "long_name": "PyArray_ToList( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self" + ], + "start_line": 1214, + "end_line": 1243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToString", + "long_name": "PyArray_ToString( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 170, + "parameters": [ + "self" + ], + "start_line": 1246, + "end_line": 1282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_dealloc", + "long_name": "array_dealloc( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 1291, + "end_line": 1328, + "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": 1335, + "end_line": 1343, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_big_item", + "long_name": "array_big_item( PyArrayObject * self , intp i)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 4, + "token_count": 151, + "parameters": [ + "self", + "i" + ], + "start_line": 1346, + "end_line": 1371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , _int_or_ssize_t i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1374, + "end_line": 1377, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_ass_big_item", + "long_name": "array_ass_big_item( PyArrayObject * self , intp i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1380, + "end_line": 1415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , _int_or_ssize_t i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1428, + "end_line": 1431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "slice_coerce_index", + "long_name": "slice_coerce_index( PyObject * o , intp * v)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "o", + "v" + ], + "start_line": 1437, + "end_line": 1445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "slice_GetIndices", + "long_name": "slice_GetIndices( PySliceObject * r , intp length , intp * start , intp * stop , intp * step , intp * slicelength)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 24, + "token_count": 376, + "parameters": [ + "r", + "length", + "start", + "stop", + "step", + "slicelength" + ], + "start_line": 1451, + "end_line": 1501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "parse_subindex", + "long_name": "parse_subindex( PyObject * op , intp * step_size , intp * n_steps , intp max)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "step_size", + "n_steps", + "max" + ], + "start_line": 1508, + "end_line": 1553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "parse_index", + "long_name": "parse_index( PyArrayObject * self , PyObject * op , intp * dimensions , intp * strides , intp * offset_ptr)", + "filename": "arrayobject.c", + "nloc": 88, + "complexity": 20, + "token_count": 539, + "parameters": [ + "self", + "op", + "dimensions", + "strides", + "offset_ptr" + ], + "start_line": 1557, + "end_line": 1651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "_swap_axes", + "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1654, + "end_line": 1691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1703, + "end_line": 1756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetMap", + "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 53, + "complexity": 12, + "token_count": 382, + "parameters": [ + "mit", + "op" + ], + "start_line": 1759, + "end_line": 1819, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 0 + }, + { + "name": "count_new_axes_0d", + "long_name": "count_new_axes_0d( PyObject * tuple)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 7, + "token_count": 124, + "parameters": [ + "tuple" + ], + "start_line": 1822, + "end_line": 1849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "add_new_axes_0d", + "long_name": "add_new_axes_0d( PyArrayObject * arr , int newaxis_count)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 121, + "parameters": [ + "arr", + "newaxis_count" + ], + "start_line": 1852, + "end_line": 1871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 1883, + "end_line": 1945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 107, + "complexity": 28, + "token_count": 674, + "parameters": [ + "self", + "op" + ], + "start_line": 1969, + "end_line": 2094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2109, + "end_line": 2214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 10, + "token_count": 182, + "parameters": [ + "self", + "op" + ], + "start_line": 2223, + "end_line": 2262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , _int_or_ssize_t * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2285, + "end_line": 2297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2300, + "end_line": 2315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2319, + "end_line": 2328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , _int_or_ssize_t segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2331, + "end_line": 2342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 1, + "token_count": 182, + "parameters": [ + "dict" + ], + "start_line": 2420, + "end_line": 2457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 2, + "token_count": 203, + "parameters": [], + "start_line": 2467, + "end_line": 2510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2513, + "end_line": 2536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericAccumulateFunction", + "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2540, + "end_line": 2563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericBinaryFunction", + "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 44, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2567, + "end_line": 2574, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericUnaryFunction", + "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 38, + "parameters": [ + "m1", + "op" + ], + "start_line": 2577, + "end_line": 2584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceBinaryFunction", + "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 46, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2587, + "end_line": 2595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceUnaryFunction", + "long_name": "PyArray_GenericInplaceUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 40, + "parameters": [ + "m1", + "op" + ], + "start_line": 2598, + "end_line": 2605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2608, + "end_line": 2611, + "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": 2614, + "end_line": 2617, + "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": 2620, + "end_line": 2623, + "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": 2626, + "end_line": 2629, + "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": 2632, + "end_line": 2635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power_is_scalar", + "long_name": "array_power_is_scalar( PyObject * o2 , double * exp)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 132, + "parameters": [ + "o2", + "exp" + ], + "start_line": 2642, + "end_line": 2665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "fast_scalar_power", + "long_name": "fast_scalar_power( PyArrayObject * a1 , PyObject * o2 , int inplace)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 12, + "token_count": 181, + "parameters": [ + "a1", + "o2", + "inplace" + ], + "start_line": 2669, + "end_line": 2703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2706, + "end_line": 2715, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2719, + "end_line": 2722, + "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": 2725, + "end_line": 2728, + "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": 2731, + "end_line": 2734, + "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": 2737, + "end_line": 2740, + "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": 2743, + "end_line": 2746, + "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": 2749, + "end_line": 2752, + "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": 2755, + "end_line": 2758, + "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": 2761, + "end_line": 2764, + "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": 2767, + "end_line": 2770, + "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": 2773, + "end_line": 2776, + "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": 2779, + "end_line": 2782, + "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": 2785, + "end_line": 2788, + "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": 2791, + "end_line": 2794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2797, + "end_line": 2806, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2809, + "end_line": 2812, + "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": 2815, + "end_line": 2818, + "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": 2821, + "end_line": 2824, + "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": 2827, + "end_line": 2830, + "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": 2833, + "end_line": 2836, + "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": 2839, + "end_line": 2842, + "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": 2845, + "end_line": 2848, + "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": 2851, + "end_line": 2855, + "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": 2858, + "end_line": 2862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_any_nonzero", + "long_name": "array_any_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 95, + "parameters": [ + "mp" + ], + "start_line": 2866, + "end_line": 2884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_array_nonzero", + "long_name": "_array_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 3, + "token_count": 72, + "parameters": [ + "mp" + ], + "start_line": 2887, + "end_line": 2904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_divmod", + "long_name": "array_divmod( PyArrayObject * op1 , PyObject * op2)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 89, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2909, + "end_line": 2924, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_int", + "long_name": "array_int( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2928, + "end_line": 2954, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_float", + "long_name": "array_float( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2957, + "end_line": 2982, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_long", + "long_name": "array_long( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 2985, + "end_line": 3007, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_oct", + "long_name": "array_oct( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3010, + "end_line": 3032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_hex", + "long_name": "array_hex( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3035, + "end_line": 3057, + "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": 3060, + "end_line": 3064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 12, + "token_count": 268, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 3125, + "end_line": 3166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 3170, + "end_line": 3192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 3195, + "end_line": 3207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dump_data", + "long_name": "dump_data( char ** string , int * n , int * max_n , char * data , int nd , intp * dimensions , intp * strides , PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 7, + "token_count": 310, + "parameters": [ + "string", + "n", + "max_n", + "data", + "nd", + "dimensions", + "strides", + "self" + ], + "start_line": 3240, + "end_line": 3287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_repr_builtin", + "long_name": "array_repr_builtin( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 4, + "token_count": 224, + "parameters": [ + "self" + ], + "start_line": 3290, + "end_line": 3326, + "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": 3335, + "end_line": 3352, + "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": 3355, + "end_line": 3367, + "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": 3370, + "end_line": 3382, + "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": 90, + "complexity": 19, + "token_count": 392, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3385, + "end_line": 3491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 171, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3494, + "end_line": 3523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntTupleFromIntp", + "long_name": "PyArray_IntTupleFromIntp( int len , intp * vals)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 109, + "parameters": [ + "len", + "vals" + ], + "start_line": 3529, + "end_line": 3549, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3557, + "end_line": 3592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3598, + "end_line": 3617, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 3621, + "end_line": 3639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 3642, + "end_line": 3659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_IsWriteable", + "long_name": "_IsWriteable( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 107, + "parameters": [ + "ap" + ], + "start_line": 3662, + "end_line": 3695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_UpdateFlags", + "long_name": "PyArray_UpdateFlags( PyArrayObject * ret , int flagmask)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 11, + "token_count": 157, + "parameters": [ + "ret", + "flagmask" + ], + "start_line": 3702, + "end_line": 3729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 117, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 3749, + "end_line": 3769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 3789, + "end_line": 3813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_New", + "long_name": "PyArray_New( PyTypeObject * subtype , int nd , intp * dims , int type_num , intp * strides , * data , int itemsize , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 4, + "token_count": 128, + "parameters": [ + "subtype", + "nd", + "dims", + "type_num", + "strides", + "data", + "itemsize", + "flags", + "obj" + ], + "start_line": 3819, + "end_line": 3841, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd , int isfortran)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 10, + "token_count": 311, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd", + "isfortran" + ], + "start_line": 3852, + "end_line": 3914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 132, + "complexity": 29, + "token_count": 785, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3922, + "end_line": 4088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 167, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape , int refcheck)", + "filename": "arrayobject.c", + "nloc": 83, + "complexity": 16, + "token_count": 511, + "parameters": [ + "self", + "newshape", + "refcheck" + ], + "start_line": 4101, + "end_line": 4200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 100, + "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": 4206, + "end_line": 4223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 8, + "token_count": 279, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4227, + "end_line": 4277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 21, + "token_count": 620, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4280, + "end_line": 4411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 132, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4415, + "end_line": 4423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ndim_get", + "long_name": "array_ndim_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4429, + "end_line": 4432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flags_get", + "long_name": "array_flags_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 4435, + "end_line": 4438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_get", + "long_name": "array_shape_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4441, + "end_line": 4444, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_set", + "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4448, + "end_line": 4477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "array_strides_get", + "long_name": "array_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4481, + "end_line": 4484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 9, + "token_count": 304, + "parameters": [ + "self", + "obj" + ], + "start_line": 4487, + "end_line": 4541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4545, + "end_line": 4552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4555, + "end_line": 4561, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4565, + "end_line": 4571, + "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": 4574, + "end_line": 4588, + "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": 4591, + "end_line": 4635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_itemsize_get", + "long_name": "array_itemsize_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 4639, + "end_line": 4642, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_size_get", + "long_name": "array_size_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4645, + "end_line": 4656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nbytes_get", + "long_name": "array_nbytes_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4659, + "end_line": 4670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4676, + "end_line": 4679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_descr_get", + "long_name": "array_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 4682, + "end_line": 4686, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "arg" + ], + "start_line": 4700, + "end_line": 4787, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 4790, + "end_line": 4808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_struct_get", + "long_name": "array_struct_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 2, + "token_count": 130, + "parameters": [ + "self" + ], + "start_line": 4811, + "end_line": 4829, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 4832, + "end_line": 4842, + "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": 4846, + "end_line": 4871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_real_set", + "long_name": "array_real_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 4, + "token_count": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 4875, + "end_line": 4908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_get", + "long_name": "array_imag_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self" + ], + "start_line": 4911, + "end_line": 4944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 4947, + "end_line": 4984, + "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": 4987, + "end_line": 4990, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flat_set", + "long_name": "array_flat_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 9, + "token_count": 348, + "parameters": [ + "self", + "val" + ], + "start_line": 4993, + "end_line": 5043, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_alloc", + "long_name": "array_alloc( PyTypeObject * type , int nitems)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 1, + "token_count": 39, + "parameters": [ + "type", + "nitems" + ], + "start_line": 5133, + "end_line": 5140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "discover_depth", + "long_name": "discover_depth( PyObject * s , int max , int stop_at_string , int stop_at_tuple)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 19, + "token_count": 243, + "parameters": [ + "s", + "max", + "stop_at_string", + "stop_at_tuple" + ], + "start_line": 5228, + "end_line": 5261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5264, + "end_line": 5286, + "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": 5293, + "end_line": 5319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_array_small_type", + "long_name": "_array_small_type( PyArray_Descr * chktype , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 169, + "parameters": [ + "chktype", + "mintype" + ], + "start_line": 5325, + "end_line": 5357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_python_scalar_type", + "long_name": "_array_find_python_scalar_type( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 8, + "token_count": 120, + "parameters": [ + "op" + ], + "start_line": 5360, + "end_line": 5383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 28, + "token_count": 634, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5395, + "end_line": 5525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "Assign_Array", + "long_name": "Assign_Array( PyArrayObject * self , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 121, + "parameters": [ + "self", + "v" + ], + "start_line": 5528, + "end_line": 5551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 189, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5556, + "end_line": 5594, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 24, + "token_count": 373, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5599, + "end_line": 5666, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 68, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 5673, + "end_line": 5682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_bufferedcast", + "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 18, + "token_count": 525, + "parameters": [ + "out", + "in" + ], + "start_line": 5688, + "end_line": 5781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5791, + "end_line": 5837, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastTo", + "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 241, + "parameters": [ + "out", + "mp" + ], + "start_line": 5847, + "end_line": 5900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 31, + "token_count": 658, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5905, + "end_line": 6031, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 501, + "parameters": [ + "str" + ], + "start_line": 6035, + "end_line": 6143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 6147, + "end_line": 6187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 6191, + "end_line": 6329, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6333, + "end_line": 6376, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 21, + "token_count": 410, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6382, + "end_line": 6466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6471, + "end_line": 6474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ObjectType", + "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 69, + "parameters": [ + "op", + "minimum_type" + ], + "start_line": 6481, + "end_line": 6494, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6540, + "end_line": 6556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 84, + "parameters": [ + "op" + ], + "start_line": 6569, + "end_line": 6585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastSafely", + "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 39, + "token_count": 444, + "parameters": [ + "fromtype", + "totype" + ], + "start_line": 6591, + "end_line": 6679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 6684, + "end_line": 6712, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterNew", + "long_name": "PyArray_IterNew( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 269, + "parameters": [ + "obj" + ], + "start_line": 6725, + "end_line": 6763, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterAllButAxis", + "long_name": "PyArray_IterAllButAxis( PyObject * obj , int axis)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 88, + "parameters": [ + "obj", + "axis" + ], + "start_line": 6771, + "end_line": 6788, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_next", + "long_name": "arrayiter_next( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 48, + "parameters": [ + "it" + ], + "start_line": 6793, + "end_line": 6803, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_dealloc", + "long_name": "arrayiter_dealloc( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "it" + ], + "start_line": 6806, + "end_line": 6810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 6813, + "end_line": 6816, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_Bool", + "long_name": "iter_subscript_Bool( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 7, + "token_count": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6820, + "end_line": 6870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_int", + "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 52, + "complexity": 8, + "token_count": 352, + "parameters": [ + "self", + "ind" + ], + "start_line": 6873, + "end_line": 6927, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 6931, + "end_line": 7064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 134, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_Bool", + "long_name": "iter_ass_sub_Bool( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7068, + "end_line": 7100, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_int", + "long_name": "iter_ass_sub_int( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 8, + "token_count": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7103, + "end_line": 7145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 7148, + "end_line": 7282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "iter_array", + "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 214, + "parameters": [ + "it", + "op" + ], + "start_line": 7299, + "end_line": 7344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "iter_copy", + "long_name": "iter_copy( PyArrayIterObject * it , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "it", + "args" + ], + "start_line": 7349, + "end_line": 7353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7369, + "end_line": 7384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7449, + "end_line": 7465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Broadcast", + "long_name": "PyArray_Broadcast( PyArrayMultiIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 13, + "token_count": 464, + "parameters": [ + "mit" + ], + "start_line": 7472, + "end_line": 7541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterReset", + "long_name": "PyArray_MapIterReset( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7545, + "end_line": 7582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7588, + "end_line": 7632, + "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": 107, + "complexity": 23, + "token_count": 715, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7650, + "end_line": 7789, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 140, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7795, + "end_line": 7867, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 7870, + "end_line": 7996, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 8000, + "end_line": 8009, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiIterNew", + "long_name": "PyArray_MultiIterNew( int n , ...)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 10, + "token_count": 231, + "parameters": [ + "n" + ], + "start_line": 8080, + "end_line": 8129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_new", + "long_name": "arraymultiter_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 11, + "token_count": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8132, + "end_line": 8177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_next", + "long_name": "arraymultiter_next( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 111, + "parameters": [ + "multi" + ], + "start_line": 8180, + "end_line": 8199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_dealloc", + "long_name": "arraymultiter_dealloc( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 41, + "parameters": [ + "multi" + ], + "start_line": 8202, + "end_line": 8209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_size_get", + "long_name": "arraymultiter_size_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8212, + "end_line": 8222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_index_get", + "long_name": "arraymultiter_index_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8225, + "end_line": 8235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_shape_get", + "long_name": "arraymultiter_shape_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 8238, + "end_line": 8241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_iters_get", + "long_name": "arraymultiter_iters_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 8244, + "end_line": 8256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_reset", + "long_name": "arraymultiter_reset( PyArrayMultiIterObject * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 38, + "parameters": [ + "self", + "args" + ], + "start_line": 8286, + "end_line": 8293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewFromType", + "long_name": "PyArray_DescrNewFromType( int type_num)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 1, + "token_count": 37, + "parameters": [ + "type_num" + ], + "start_line": 8352, + "end_line": 8361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNew", + "long_name": "PyArray_DescrNew( PyArray_Descr * base)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 151, + "parameters": [ + "base" + ], + "start_line": 8379, + "end_line": 8401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_dealloc", + "long_name": "arraydescr_dealloc( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 8407, + "end_line": 8417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_subdescr_get", + "long_name": "arraydescr_subdescr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 8436, + "end_line": 8444, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8447, + "end_line": 8462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8465, + "end_line": 8487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8490, + "end_line": 8498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8501, + "end_line": 8508, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 8511, + "end_line": 8530, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isbuiltin_get", + "long_name": "arraydescr_isbuiltin_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 8537, + "end_line": 8544, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isnative_get", + "long_name": "arraydescr_isnative_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 8547, + "end_line": 8554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_fields_get", + "long_name": "arraydescr_fields_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 8557, + "end_line": 8564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_new", + "long_name": "arraydescr_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 272, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8612, + "end_line": 8664, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 8670, + "end_line": 8731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8739, + "end_line": 8781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewByteorder", + "long_name": "PyArray_DescrNewByteorder( PyArray_Descr * self , char newendian)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 386, + "parameters": [ + "self", + "newendian" + ], + "start_line": 8801, + "end_line": 8867, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_newbyteorder", + "long_name": "arraydescr_newbyteorder( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 47, + "parameters": [ + "self", + "args" + ], + "start_line": 8878, + "end_line": 8886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_str", + "long_name": "arraydescr_str( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 6, + "token_count": 287, + "parameters": [ + "self" + ], + "start_line": 8901, + "end_line": 8946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_repr", + "long_name": "arraydescr_repr( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 8949, + "end_line": 8958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_compare", + "long_name": "arraydescr_compare( PyArray_Descr * self , PyObject * other)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "other" + ], + "start_line": 8961, + "end_line": 8971, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 8978, + "end_line": 8985, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 8988, + "end_line": 9019, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFlagsObject", + "long_name": "PyArray_NewFlagsObject( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 3, + "token_count": 96, + "parameters": [ + "obj" + ], + "start_line": 9097, + "end_line": 9114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_dealloc", + "long_name": "arrayflags_dealloc( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 9117, + "end_line": 9121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_forc_get", + "long_name": "arrayflags_forc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 9145, + "end_line": 9157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_fnc_get", + "long_name": "arrayflags_fnc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9160, + "end_line": 9172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_farray_get", + "long_name": "arrayflags_farray_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 9175, + "end_line": 9188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_num_get", + "long_name": "arrayflags_num_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 9191, + "end_line": 9194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_updateifcopy_set", + "long_name": "arrayflags_updateifcopy_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9198, + "end_line": 9210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_aligned_set", + "long_name": "arrayflags_aligned_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9213, + "end_line": 9226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_writeable_set", + "long_name": "arrayflags_writeable_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9229, + "end_line": 9242, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_getitem", + "long_name": "arrayflags_getitem( PyArrayFlagsObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 22, + "token_count": 416, + "parameters": [ + "self", + "ind" + ], + "start_line": 9298, + "end_line": 9341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_setitem", + "long_name": "arrayflags_setitem( PyArrayFlagsObject * self , PyObject * ind , PyObject * item)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 8, + "token_count": 178, + "parameters": [ + "self", + "ind", + "item" + ], + "start_line": 9344, + "end_line": 9366, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_torf_", + "long_name": "_torf_( int flags , int val)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 27, + "parameters": [ + "flags", + "val" + ], + "start_line": 9369, + "end_line": 9373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_print", + "long_name": "arrayflags_print( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 1, + "token_count": 77, + "parameters": [ + "self" + ], + "start_line": 9376, + "end_line": 9388, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_new", + "long_name": "arrayflags_new( PyTypeObject * self , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9403, + "end_line": 9415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 76, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 65, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 99, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 134, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 207, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 241, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 291, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 319, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 344, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 387, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 427, + "end_line": 509, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 516, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 593, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Size", + "long_name": "PyArray_Size( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 33, + "parameters": [ + "op" + ], + "start_line": 614, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 638, + "end_line": 718, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyObject", + "long_name": "PyArray_CopyObject( PyArrayObject * dest , PyObject * src_object)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 722, + "end_line": 736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDimsAndDataAndDescr", + "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 137, + "parameters": [ + "nd", + "d", + "descr", + "data" + ], + "start_line": 749, + "end_line": 775, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDims", + "long_name": "PyArray_FromDims( int nd , int * d , int type)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "nd", + "d", + "type" + ], + "start_line": 781, + "end_line": 795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewCopy", + "long_name": "PyArray_NewCopy( PyArrayObject * m1 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 804, + "end_line": 824, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 17, + "token_count": 616, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 833, + "end_line": 949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 965, + "end_line": 968, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Return", + "long_name": "PyArray_Return( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 91, + "parameters": [ + "mp" + ], + "start_line": 978, + "end_line": 1000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDataType", + "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 9, + "token_count": 229, + "parameters": [ + "type" + ], + "start_line": 1014, + "end_line": 1054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDescrForType", + "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 214, + "parameters": [ + "typenum", + "descr" + ], + "start_line": 1069, + "end_line": 1110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToFile", + "long_name": "PyArray_ToFile( PyArrayObject * self , FILE * fp , char * sep , char * format)", + "filename": "arrayobject.c", + "nloc": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1117, + "end_line": 1208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToList", + "long_name": "PyArray_ToList( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self" + ], + "start_line": 1214, + "end_line": 1243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToString", + "long_name": "PyArray_ToString( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 170, + "parameters": [ + "self" + ], + "start_line": 1246, + "end_line": 1282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_dealloc", + "long_name": "array_dealloc( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 1291, + "end_line": 1328, + "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": 1335, + "end_line": 1343, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_big_item", + "long_name": "array_big_item( PyArrayObject * self , intp i)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 4, + "token_count": 151, + "parameters": [ + "self", + "i" + ], + "start_line": 1346, + "end_line": 1371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , _int_or_ssize_t i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1374, + "end_line": 1377, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_ass_big_item", + "long_name": "array_ass_big_item( PyArrayObject * self , intp i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1380, + "end_line": 1415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , _int_or_ssize_t i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1428, + "end_line": 1431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "slice_coerce_index", + "long_name": "slice_coerce_index( PyObject * o , intp * v)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "o", + "v" + ], + "start_line": 1437, + "end_line": 1445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "slice_GetIndices", + "long_name": "slice_GetIndices( PySliceObject * r , intp length , intp * start , intp * stop , intp * step , intp * slicelength)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 24, + "token_count": 376, + "parameters": [ + "r", + "length", + "start", + "stop", + "step", + "slicelength" + ], + "start_line": 1451, + "end_line": 1501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "parse_subindex", + "long_name": "parse_subindex( PyObject * op , intp * step_size , intp * n_steps , intp max)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "step_size", + "n_steps", + "max" + ], + "start_line": 1508, + "end_line": 1553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "parse_index", + "long_name": "parse_index( PyArrayObject * self , PyObject * op , intp * dimensions , intp * strides , intp * offset_ptr)", + "filename": "arrayobject.c", + "nloc": 88, + "complexity": 20, + "token_count": 539, + "parameters": [ + "self", + "op", + "dimensions", + "strides", + "offset_ptr" + ], + "start_line": 1557, + "end_line": 1651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "_swap_axes", + "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1654, + "end_line": 1691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1703, + "end_line": 1756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetMap", + "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 53, + "complexity": 12, + "token_count": 382, + "parameters": [ + "mit", + "op" + ], + "start_line": 1759, + "end_line": 1819, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 0 + }, + { + "name": "count_new_axes_0d", + "long_name": "count_new_axes_0d( PyObject * tuple)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 7, + "token_count": 124, + "parameters": [ + "tuple" + ], + "start_line": 1822, + "end_line": 1849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "add_new_axes_0d", + "long_name": "add_new_axes_0d( PyArrayObject * arr , int newaxis_count)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 121, + "parameters": [ + "arr", + "newaxis_count" + ], + "start_line": 1852, + "end_line": 1871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 1883, + "end_line": 1945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 107, + "complexity": 28, + "token_count": 674, + "parameters": [ + "self", + "op" + ], + "start_line": 1969, + "end_line": 2094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2109, + "end_line": 2214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 10, + "token_count": 182, + "parameters": [ + "self", + "op" + ], + "start_line": 2223, + "end_line": 2262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , _int_or_ssize_t * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2285, + "end_line": 2297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2300, + "end_line": 2315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2319, + "end_line": 2328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , _int_or_ssize_t segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2331, + "end_line": 2342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 1, + "token_count": 182, + "parameters": [ + "dict" + ], + "start_line": 2420, + "end_line": 2457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 2, + "token_count": 203, + "parameters": [], + "start_line": 2467, + "end_line": 2510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2513, + "end_line": 2536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericAccumulateFunction", + "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2540, + "end_line": 2563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericBinaryFunction", + "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 44, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2567, + "end_line": 2574, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericUnaryFunction", + "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 38, + "parameters": [ + "m1", + "op" + ], + "start_line": 2577, + "end_line": 2584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceBinaryFunction", + "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 46, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2587, + "end_line": 2595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceUnaryFunction", + "long_name": "PyArray_GenericInplaceUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 40, + "parameters": [ + "m1", + "op" + ], + "start_line": 2598, + "end_line": 2605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2608, + "end_line": 2611, + "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": 2614, + "end_line": 2617, + "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": 2620, + "end_line": 2623, + "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": 2626, + "end_line": 2629, + "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": 2632, + "end_line": 2635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power_is_scalar", + "long_name": "array_power_is_scalar( PyObject * o2 , double * exp)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 132, + "parameters": [ + "o2", + "exp" + ], + "start_line": 2642, + "end_line": 2665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "fast_scalar_power", + "long_name": "fast_scalar_power( PyArrayObject * a1 , PyObject * o2 , int inplace)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 12, + "token_count": 181, + "parameters": [ + "a1", + "o2", + "inplace" + ], + "start_line": 2669, + "end_line": 2703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2706, + "end_line": 2715, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2719, + "end_line": 2722, + "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": 2725, + "end_line": 2728, + "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": 2731, + "end_line": 2734, + "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": 2737, + "end_line": 2740, + "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": 2743, + "end_line": 2746, + "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": 2749, + "end_line": 2752, + "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": 2755, + "end_line": 2758, + "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": 2761, + "end_line": 2764, + "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": 2767, + "end_line": 2770, + "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": 2773, + "end_line": 2776, + "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": 2779, + "end_line": 2782, + "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": 2785, + "end_line": 2788, + "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": 2791, + "end_line": 2794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2797, + "end_line": 2806, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2809, + "end_line": 2812, + "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": 2815, + "end_line": 2818, + "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": 2821, + "end_line": 2824, + "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": 2827, + "end_line": 2830, + "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": 2833, + "end_line": 2836, + "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": 2839, + "end_line": 2842, + "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": 2845, + "end_line": 2848, + "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": 2851, + "end_line": 2855, + "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": 2858, + "end_line": 2862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_any_nonzero", + "long_name": "array_any_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 95, + "parameters": [ + "mp" + ], + "start_line": 2866, + "end_line": 2884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_array_nonzero", + "long_name": "_array_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 3, + "token_count": 72, + "parameters": [ + "mp" + ], + "start_line": 2887, + "end_line": 2904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_divmod", + "long_name": "array_divmod( PyArrayObject * op1 , PyObject * op2)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 89, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2909, + "end_line": 2924, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_int", + "long_name": "array_int( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2928, + "end_line": 2954, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_float", + "long_name": "array_float( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2957, + "end_line": 2982, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_long", + "long_name": "array_long( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 2985, + "end_line": 3007, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_oct", + "long_name": "array_oct( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3010, + "end_line": 3032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_hex", + "long_name": "array_hex( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3035, + "end_line": 3057, + "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": 3060, + "end_line": 3064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 12, + "token_count": 268, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 3125, + "end_line": 3166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 3170, + "end_line": 3192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 3195, + "end_line": 3207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dump_data", + "long_name": "dump_data( char ** string , int * n , int * max_n , char * data , int nd , intp * dimensions , intp * strides , PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 7, + "token_count": 310, + "parameters": [ + "string", + "n", + "max_n", + "data", + "nd", + "dimensions", + "strides", + "self" + ], + "start_line": 3240, + "end_line": 3287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_repr_builtin", + "long_name": "array_repr_builtin( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 4, + "token_count": 224, + "parameters": [ + "self" + ], + "start_line": 3290, + "end_line": 3326, + "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": 3335, + "end_line": 3352, + "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": 3355, + "end_line": 3367, + "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": 3370, + "end_line": 3382, + "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": 90, + "complexity": 19, + "token_count": 392, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3385, + "end_line": 3491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 171, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3494, + "end_line": 3523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntTupleFromIntp", + "long_name": "PyArray_IntTupleFromIntp( int len , intp * vals)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 109, + "parameters": [ + "len", + "vals" + ], + "start_line": 3529, + "end_line": 3549, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3557, + "end_line": 3592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3598, + "end_line": 3617, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 3621, + "end_line": 3639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 3642, + "end_line": 3659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_IsWriteable", + "long_name": "_IsWriteable( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 107, + "parameters": [ + "ap" + ], + "start_line": 3662, + "end_line": 3695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_UpdateFlags", + "long_name": "PyArray_UpdateFlags( PyArrayObject * ret , int flagmask)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 11, + "token_count": 157, + "parameters": [ + "ret", + "flagmask" + ], + "start_line": 3702, + "end_line": 3729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 117, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 3749, + "end_line": 3769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 3789, + "end_line": 3813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_New", + "long_name": "PyArray_New( PyTypeObject * subtype , int nd , intp * dims , int type_num , intp * strides , * data , int itemsize , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 4, + "token_count": 128, + "parameters": [ + "subtype", + "nd", + "dims", + "type_num", + "strides", + "data", + "itemsize", + "flags", + "obj" + ], + "start_line": 3819, + "end_line": 3841, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd , int isfortran)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 10, + "token_count": 311, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd", + "isfortran" + ], + "start_line": 3852, + "end_line": 3914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 132, + "complexity": 29, + "token_count": 785, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3922, + "end_line": 4088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 167, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape , int refcheck)", + "filename": "arrayobject.c", + "nloc": 83, + "complexity": 16, + "token_count": 511, + "parameters": [ + "self", + "newshape", + "refcheck" + ], + "start_line": 4101, + "end_line": 4200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 100, + "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": 4206, + "end_line": 4223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 8, + "token_count": 279, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4227, + "end_line": 4277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 21, + "token_count": 620, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4280, + "end_line": 4411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 132, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4415, + "end_line": 4423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ndim_get", + "long_name": "array_ndim_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4429, + "end_line": 4432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flags_get", + "long_name": "array_flags_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 4435, + "end_line": 4439, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_shape_get", + "long_name": "array_shape_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4442, + "end_line": 4445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_set", + "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4449, + "end_line": 4478, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "array_strides_get", + "long_name": "array_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4482, + "end_line": 4485, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 9, + "token_count": 304, + "parameters": [ + "self", + "obj" + ], + "start_line": 4488, + "end_line": 4542, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4546, + "end_line": 4553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4556, + "end_line": 4562, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4566, + "end_line": 4572, + "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": 4575, + "end_line": 4589, + "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": 4592, + "end_line": 4636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_itemsize_get", + "long_name": "array_itemsize_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 4640, + "end_line": 4643, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_size_get", + "long_name": "array_size_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4646, + "end_line": 4657, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nbytes_get", + "long_name": "array_nbytes_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4660, + "end_line": 4671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4677, + "end_line": 4680, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_descr_get", + "long_name": "array_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 4683, + "end_line": 4687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "arg" + ], + "start_line": 4701, + "end_line": 4788, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 4791, + "end_line": 4809, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_struct_get", + "long_name": "array_struct_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 2, + "token_count": 130, + "parameters": [ + "self" + ], + "start_line": 4812, + "end_line": 4830, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 4833, + "end_line": 4843, + "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": 4847, + "end_line": 4872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_real_set", + "long_name": "array_real_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 4, + "token_count": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 4876, + "end_line": 4909, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_get", + "long_name": "array_imag_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self" + ], + "start_line": 4912, + "end_line": 4945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 4948, + "end_line": 4985, + "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": 4988, + "end_line": 4991, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flat_set", + "long_name": "array_flat_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 9, + "token_count": 348, + "parameters": [ + "self", + "val" + ], + "start_line": 4994, + "end_line": 5044, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_alloc", + "long_name": "array_alloc( PyTypeObject * type , int nitems)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 1, + "token_count": 39, + "parameters": [ + "type", + "nitems" + ], + "start_line": 5134, + "end_line": 5141, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "discover_depth", + "long_name": "discover_depth( PyObject * s , int max , int stop_at_string , int stop_at_tuple)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 19, + "token_count": 243, + "parameters": [ + "s", + "max", + "stop_at_string", + "stop_at_tuple" + ], + "start_line": 5229, + "end_line": 5262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5265, + "end_line": 5287, + "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": 5294, + "end_line": 5320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_array_small_type", + "long_name": "_array_small_type( PyArray_Descr * chktype , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 169, + "parameters": [ + "chktype", + "mintype" + ], + "start_line": 5326, + "end_line": 5358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_python_scalar_type", + "long_name": "_array_find_python_scalar_type( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 8, + "token_count": 120, + "parameters": [ + "op" + ], + "start_line": 5361, + "end_line": 5384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 28, + "token_count": 634, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5396, + "end_line": 5526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "Assign_Array", + "long_name": "Assign_Array( PyArrayObject * self , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 121, + "parameters": [ + "self", + "v" + ], + "start_line": 5529, + "end_line": 5552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 189, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5557, + "end_line": 5595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 24, + "token_count": 373, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5600, + "end_line": 5667, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 68, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 5674, + "end_line": 5683, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_bufferedcast", + "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 18, + "token_count": 525, + "parameters": [ + "out", + "in" + ], + "start_line": 5689, + "end_line": 5782, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5792, + "end_line": 5838, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastTo", + "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 241, + "parameters": [ + "out", + "mp" + ], + "start_line": 5848, + "end_line": 5901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 31, + "token_count": 658, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5906, + "end_line": 6032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 501, + "parameters": [ + "str" + ], + "start_line": 6036, + "end_line": 6144, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 6148, + "end_line": 6188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 6192, + "end_line": 6330, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6334, + "end_line": 6377, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 21, + "token_count": 410, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6383, + "end_line": 6467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6472, + "end_line": 6475, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ObjectType", + "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 69, + "parameters": [ + "op", + "minimum_type" + ], + "start_line": 6482, + "end_line": 6495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6541, + "end_line": 6557, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 84, + "parameters": [ + "op" + ], + "start_line": 6570, + "end_line": 6586, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastSafely", + "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 39, + "token_count": 444, + "parameters": [ + "fromtype", + "totype" + ], + "start_line": 6592, + "end_line": 6680, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 6685, + "end_line": 6713, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterNew", + "long_name": "PyArray_IterNew( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 269, + "parameters": [ + "obj" + ], + "start_line": 6726, + "end_line": 6764, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterAllButAxis", + "long_name": "PyArray_IterAllButAxis( PyObject * obj , int axis)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 88, + "parameters": [ + "obj", + "axis" + ], + "start_line": 6772, + "end_line": 6789, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_next", + "long_name": "arrayiter_next( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 48, + "parameters": [ + "it" + ], + "start_line": 6794, + "end_line": 6804, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_dealloc", + "long_name": "arrayiter_dealloc( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "it" + ], + "start_line": 6807, + "end_line": 6811, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 6814, + "end_line": 6817, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_Bool", + "long_name": "iter_subscript_Bool( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 7, + "token_count": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6821, + "end_line": 6871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_int", + "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 52, + "complexity": 8, + "token_count": 352, + "parameters": [ + "self", + "ind" + ], + "start_line": 6874, + "end_line": 6928, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 6932, + "end_line": 7065, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 134, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_Bool", + "long_name": "iter_ass_sub_Bool( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7069, + "end_line": 7101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_int", + "long_name": "iter_ass_sub_int( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 8, + "token_count": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7104, + "end_line": 7146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 7149, + "end_line": 7283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "iter_array", + "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 214, + "parameters": [ + "it", + "op" + ], + "start_line": 7300, + "end_line": 7345, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "iter_copy", + "long_name": "iter_copy( PyArrayIterObject * it , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "it", + "args" + ], + "start_line": 7350, + "end_line": 7354, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7370, + "end_line": 7385, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7450, + "end_line": 7466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Broadcast", + "long_name": "PyArray_Broadcast( PyArrayMultiIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 13, + "token_count": 464, + "parameters": [ + "mit" + ], + "start_line": 7473, + "end_line": 7542, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterReset", + "long_name": "PyArray_MapIterReset( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7546, + "end_line": 7583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7589, + "end_line": 7633, + "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": 107, + "complexity": 23, + "token_count": 715, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7651, + "end_line": 7790, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 140, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7796, + "end_line": 7868, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 7871, + "end_line": 7997, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 8001, + "end_line": 8010, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiIterNew", + "long_name": "PyArray_MultiIterNew( int n , ...)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 10, + "token_count": 231, + "parameters": [ + "n" + ], + "start_line": 8081, + "end_line": 8130, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_new", + "long_name": "arraymultiter_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 11, + "token_count": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8133, + "end_line": 8178, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_next", + "long_name": "arraymultiter_next( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 111, + "parameters": [ + "multi" + ], + "start_line": 8181, + "end_line": 8200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_dealloc", + "long_name": "arraymultiter_dealloc( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 41, + "parameters": [ + "multi" + ], + "start_line": 8203, + "end_line": 8210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_size_get", + "long_name": "arraymultiter_size_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8213, + "end_line": 8223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_index_get", + "long_name": "arraymultiter_index_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8226, + "end_line": 8236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_shape_get", + "long_name": "arraymultiter_shape_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 8239, + "end_line": 8242, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_iters_get", + "long_name": "arraymultiter_iters_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 8245, + "end_line": 8257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_reset", + "long_name": "arraymultiter_reset( PyArrayMultiIterObject * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 38, + "parameters": [ + "self", + "args" + ], + "start_line": 8287, + "end_line": 8294, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewFromType", + "long_name": "PyArray_DescrNewFromType( int type_num)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 1, + "token_count": 37, + "parameters": [ + "type_num" + ], + "start_line": 8353, + "end_line": 8362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNew", + "long_name": "PyArray_DescrNew( PyArray_Descr * base)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 151, + "parameters": [ + "base" + ], + "start_line": 8380, + "end_line": 8402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_dealloc", + "long_name": "arraydescr_dealloc( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self" + ], + "start_line": 8408, + "end_line": 8418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_subdescr_get", + "long_name": "arraydescr_subdescr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 8437, + "end_line": 8445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8448, + "end_line": 8463, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8466, + "end_line": 8488, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8491, + "end_line": 8499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8502, + "end_line": 8509, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 8512, + "end_line": 8531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isbuiltin_get", + "long_name": "arraydescr_isbuiltin_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 8538, + "end_line": 8545, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isnative_get", + "long_name": "arraydescr_isnative_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 8548, + "end_line": 8555, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_fields_get", + "long_name": "arraydescr_fields_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 8558, + "end_line": 8565, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_new", + "long_name": "arraydescr_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 272, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8613, + "end_line": 8665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 8671, + "end_line": 8732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8740, + "end_line": 8782, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewByteorder", + "long_name": "PyArray_DescrNewByteorder( PyArray_Descr * self , char newendian)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 386, + "parameters": [ + "self", + "newendian" + ], + "start_line": 8802, + "end_line": 8868, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_newbyteorder", + "long_name": "arraydescr_newbyteorder( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 47, + "parameters": [ + "self", + "args" + ], + "start_line": 8879, + "end_line": 8887, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_str", + "long_name": "arraydescr_str( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 6, + "token_count": 287, + "parameters": [ + "self" + ], + "start_line": 8902, + "end_line": 8947, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_repr", + "long_name": "arraydescr_repr( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 8950, + "end_line": 8959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_compare", + "long_name": "arraydescr_compare( PyArray_Descr * self , PyObject * other)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "other" + ], + "start_line": 8962, + "end_line": 8972, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 8979, + "end_line": 8986, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 8989, + "end_line": 9020, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "arrayflags_num_get", + "long_name": "arrayflags_num_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 9191, + "end_line": 9194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_print", + "long_name": "arrayflags_print( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 1, + "token_count": 77, + "parameters": [ + "self" + ], + "start_line": 9376, + "end_line": 9388, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_new", + "long_name": "arrayflags_new( PyTypeObject * self , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9403, + "end_line": 9415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_flags_get", + "long_name": "array_flags_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 4435, + "end_line": 4438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFlagsObject", + "long_name": "PyArray_NewFlagsObject( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 3, + "token_count": 96, + "parameters": [ + "obj" + ], + "start_line": 9097, + "end_line": 9114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_getitem", + "long_name": "arrayflags_getitem( PyArrayFlagsObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 22, + "token_count": 416, + "parameters": [ + "self", + "ind" + ], + "start_line": 9298, + "end_line": 9341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "_torf_", + "long_name": "_torf_( int flags , int val)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 27, + "parameters": [ + "flags", + "val" + ], + "start_line": 9369, + "end_line": 9373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_dealloc", + "long_name": "arrayflags_dealloc( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 9117, + "end_line": 9121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_dealloc", + "long_name": "arraydescr_dealloc( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 8407, + "end_line": 8417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_updateifcopy_set", + "long_name": "arrayflags_updateifcopy_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9198, + "end_line": 9210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_forc_get", + "long_name": "arrayflags_forc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 9145, + "end_line": 9157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_writeable_set", + "long_name": "arrayflags_writeable_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9229, + "end_line": 9242, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_farray_get", + "long_name": "arrayflags_farray_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 9175, + "end_line": 9188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_fnc_get", + "long_name": "arrayflags_fnc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9160, + "end_line": 9172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_aligned_set", + "long_name": "arrayflags_aligned_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9213, + "end_line": 9226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_setitem", + "long_name": "arrayflags_setitem( PyArrayFlagsObject * self , PyObject * ind , PyObject * item)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 8, + "token_count": 178, + "parameters": [ + "self", + "ind", + "item" + ], + "start_line": 9344, + "end_line": 9366, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + } + ], + "nloc": 7510, + "complexity": 1611, + "token_count": 43709, + "diff_parsed": { + "added": [ + " return PyArray_NewFlagsObject((PyObject *)self);", + "\tself->ob_type->tp_free((PyObject *)self);", + "", + "", + "/** Array Flags Object **/", + "", + "typedef struct PyArrayFlagsObject {", + " PyObject_HEAD", + " PyObject *arr;", + " int flags;", + "} PyArrayFlagsObject;", + "", + "/*OBJECT_API", + " Get New ArrayFlagsObject", + "*/", + "static PyObject *", + "PyArray_NewFlagsObject(PyObject *obj)", + "{", + " PyObject *flagobj;", + " int flags;", + " if (obj == NULL) {", + " flags = CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;", + " }", + " else {", + " flags = PyArray_FLAGS(obj);", + " }", + " flagobj = PyArrayFlags_Type.tp_alloc(&PyArrayFlags_Type, 0);", + " if (flagobj == NULL) return NULL;", + " Py_XINCREF(obj);", + " ((PyArrayFlagsObject *)flagobj)->arr = obj;", + " ((PyArrayFlagsObject *)flagobj)->flags = flags;", + "", + " return flagobj;", + "}", + "", + "static void", + "arrayflags_dealloc(PyArrayFlagsObject *self)", + "{", + "\tPy_XDECREF(self->arr);", + "\tself->ob_type->tp_free((PyObject *)self);", + "}", + "", + "", + "#define _define_get(UPPER, lower) \\", + "static PyObject * \\", + "arrayflags_ ## lower ## _get(PyArrayFlagsObject *self) \\", + "{ \\", + " PyObject *item; \\", + " item = ((self->flags & (UPPER)) == (UPPER)) ? Py_True : Py_False; \\", + " Py_INCREF(item); \\", + " return item; \\", + "}", + "", + "_define_get(CONTIGUOUS, contiguous)", + "_define_get(FORTRAN, fortran)", + "_define_get(UPDATEIFCOPY, updateifcopy)", + "_define_get(OWNDATA, owndata)", + "_define_get(ALIGNED, aligned)", + "_define_get(WRITEABLE, writeable)", + "", + "_define_get(ALIGNED|WRITEABLE, behaved)", + "_define_get(ALIGNED|WRITEABLE|CONTIGUOUS, carray)", + "", + "static PyObject *", + "arrayflags_forc_get(PyArrayFlagsObject *self)", + "{", + " PyObject *item;", + "", + " if (((self->flags & FORTRAN) == FORTRAN) ||", + " ((self->flags & CONTIGUOUS) == CONTIGUOUS))", + " item = Py_True;", + " else", + " item = Py_False;", + "", + " Py_INCREF(item);", + " return item;", + "}", + "", + "static PyObject *", + "arrayflags_fnc_get(PyArrayFlagsObject *self)", + "{", + " PyObject *item;", + "", + " if (((self->flags & FORTRAN) == FORTRAN) &&", + " !((self->flags & CONTIGUOUS) == CONTIGUOUS))", + " item = Py_True;", + " else", + " item = Py_False;", + "", + " Py_INCREF(item);", + " return item;", + "}", + "", + "static PyObject *", + "arrayflags_farray_get(PyArrayFlagsObject *self)", + "{", + " PyObject *item;", + "", + " if (((self->flags & (ALIGNED|WRITEABLE|FORTRAN)) == \\", + " (ALIGNED|WRITEABLE|FORTRAN)) &&", + " !((self->flags & CONTIGUOUS) == CONTIGUOUS))", + " item = Py_True;", + " else", + " item = Py_False;", + "", + " Py_INCREF(item);", + " return item;", + "}", + "", + "static PyObject *", + "arrayflags_num_get(PyArrayFlagsObject *self)", + "{", + " return PyInt_FromLong(self->flags);", + "}", + "", + "/* relies on setflags order being write, align, uic */", + "static int", + "arrayflags_updateifcopy_set(PyArrayFlagsObject *self, PyObject *obj)", + "{", + " PyObject *res;", + " if (self->arr == NULL) {", + " PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");", + " return -1;", + " }", + " res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, Py_None,", + " (PyObject_IsTrue(obj) ? Py_True : Py_False));", + " if (res == NULL) return -1;", + " Py_DECREF(res);", + " return 0;", + "}", + "", + "static int", + "arrayflags_aligned_set(PyArrayFlagsObject *self, PyObject *obj)", + "{", + " PyObject *res;", + " if (self->arr == NULL) {", + " PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");", + " return -1;", + " }", + " res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None,", + " (PyObject_IsTrue(obj) ? Py_True : Py_False),", + " Py_None);", + " if (res == NULL) return -1;", + " Py_DECREF(res);", + " return 0;", + "}", + "", + "static int", + "arrayflags_writeable_set(PyArrayFlagsObject *self, PyObject *obj)", + "{", + " PyObject *res;", + " if (self->arr == NULL) {", + " PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");", + " return -1;", + " }", + " res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\",", + " (PyObject_IsTrue(obj) ? Py_True : Py_False),", + " Py_None, Py_None);", + " if (res == NULL) return -1;", + " Py_DECREF(res);", + " return 0;", + "}", + "", + "", + "static PyGetSetDef arrayflags_getsets[] = {", + "\t{\"contiguous\",", + "\t (getter)arrayflags_contiguous_get,", + "\t NULL,", + "\t \"\"},", + " {\"fortran\",", + " (getter)arrayflags_fortran_get,", + " NULL,", + " \"\"},", + " {\"updateifcopy\",", + " (getter)arrayflags_updateifcopy_get,", + " (setter)arrayflags_updateifcopy_set,", + " \"\"},", + " {\"owndata\",", + " (getter)arrayflags_owndata_get,", + " NULL,", + " \"\"},", + " {\"aligned\",", + " (getter)arrayflags_aligned_get,", + " (setter)arrayflags_aligned_set,", + " \"\"},", + " {\"writeable\",", + " (getter)arrayflags_writeable_get,", + " (setter)arrayflags_writeable_set,", + " \"\"},", + " {\"fnc\",", + " (getter)arrayflags_fnc_get,", + " NULL,", + " \"\"},", + " {\"forc\",", + " (getter)arrayflags_forc_get,", + " NULL,", + " \"\"},", + " {\"behaved\",", + " (getter)arrayflags_behaved_get,", + " NULL,", + " \"\"},", + " {\"carray\",", + " (getter)arrayflags_carray_get,", + " NULL,", + " \"\"},", + " {\"farray\",", + " (getter)arrayflags_farray_get,", + " NULL,", + " \"\"},", + " {\"num\",", + " (getter)arrayflags_num_get,", + " NULL,", + " \"\"},", + "\t{NULL, NULL, NULL, NULL},", + "};", + "", + "static PyObject *", + "arrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)", + "{", + " char *key;", + " int n;", + " if (!PyString_Check(ind)) goto fail;", + " key = PyString_AS_STRING(ind);", + " n = PyString_GET_SIZE(ind);", + " if ((strncmp(key,\"CONTIGUOUS\",n)==0) ||", + " (strncmp(key,\"C\",n)))", + " return arrayflags_contiguous_get(self);", + " else if ((strncmp(key, \"FORTRAN\", n)==0) ||", + " (strncmp(key, \"F\", n)==0))", + " return arrayflags_fortran_get(self);", + " else if ((strncmp(key, \"WRITEABLE\", n)==0) ||", + " (strncmp(key, \"W\", n)==0))", + " return arrayflags_writeable_get(self);", + " else if ((strncmp(key, \"BEHAVED\", n)==0) ||", + " (strncmp(key, \"B\", n)==0))", + " return arrayflags_behaved_get(self);", + " else if ((strncmp(key, \"OWNDATA\", n)==0) ||", + " (strncmp(key, \"O\", n)==0))", + " return arrayflags_owndata_get(self);", + " else if ((strncmp(key, \"ALIGNED\", n)==0) ||", + " (strncmp(key, \"A\", n)==0))", + " return arrayflags_aligned_get(self);", + " else if ((strncmp(key, \"UPDATEIFCOPY\", n)==0) ||", + " (strncmp(key, \"U\", n)==0))", + " return arrayflags_updateifcopy_get(self);", + " else if ((strncmp(key, \"FNC\", n)==0))", + " return arrayflags_fnc_get(self);", + " else if ((strncmp(key, \"FORC\", n)==0))", + " return arrayflags_forc_get(self);", + " else if ((strncmp(key, \"CARRAY\", n)==0) ||", + " (strncmp(key, \"CA\", n)==0))", + " return arrayflags_carray_get(self);", + " else if ((strncmp(key, \"FARRAY\", n)==0) ||", + " (strncmp(key, \"FA\", n)==0))", + " return arrayflags_farray_get(self);", + " else goto fail;", + "", + " fail:", + " PyErr_SetString(PyExc_KeyError, \"Unknown flag\");", + " return NULL;", + "}", + "", + "static int", + "arrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)", + "{", + " char *key;", + " int n;", + " if (!PyString_Check(ind)) goto fail;", + " key = PyString_AS_STRING(ind);", + " n = PyString_GET_SIZE(ind);", + " if ((strncmp(key, \"WRITEABLE\", n)==0) ||", + " (strncmp(key, \"W\", n)==0))", + " return arrayflags_writeable_set(self, item);", + " else if ((strncmp(key, \"ALIGNED\", n)==0) ||", + " (strncmp(key, \"A\", n)==0))", + " return arrayflags_aligned_set(self, item);", + " else if ((strncmp(key, \"UPDATEIFCOPY\", n)==0) ||", + " (strncmp(key, \"U\", n)==0))", + " return arrayflags_updateifcopy_set(self, item);", + " else goto fail;", + " return 0;", + "", + "fail:", + " PyErr_SetString(PyExc_KeyError, \"Unknown flag\");", + " return -1;", + "}", + "", + "static char *", + "_torf_(int flags, int val)", + "{", + " if ((flags & val) == val) return \"True\";", + " else return \"False\";", + "}", + "", + "static PyObject *", + "arrayflags_print(PyArrayFlagsObject *self)", + "{", + " int fl = self->flags;", + "", + " return PyString_FromFormat(\" %s : %s\\n %s : %s\\n %s : %s\\n\"\\", + " \" %s : %s\\n %s : %s\\n %s : %s\",", + " \"CONTIGUOUS\", _torf_(fl, CONTIGUOUS),", + " \"FORTRAN\", _torf_(fl, FORTRAN),", + " \"OWNDATA\", _torf_(fl, OWNDATA),", + " \"WRITEABLE\", _torf_(fl, WRITEABLE),", + " \"ALIGNED\", _torf_(fl, ALIGNED),", + " \"UPDATEIFCOPY\", _torf_(fl, UPDATEIFCOPY));", + "}", + "", + "", + "static PyMappingMethods arrayflags_as_mapping = {", + "#if PY_VERSION_HEX >= 0x02050000", + " (lenfunc)NULL, \t\t /*mp_length*/", + "#else", + " (inquiry)NULL, \t\t /*mp_length*/", + "#endif", + " (binaryfunc)arrayflags_getitem,\t /*mp_subscript*/", + " (objobjargproc)arrayflags_setitem, /*mp_ass_subscript*/", + "};", + "", + "", + "static PyObject *", + "arrayflags_new(PyTypeObject *self, PyObject *args, PyObject *kwds)", + "{", + " PyObject *arg=NULL;", + " if (!PyArg_UnpackTuple(args, \"flagsobj\", 0, 1, &arg))", + " return NULL;", + "", + " if ((arg != NULL) && PyArray_Check(arg)) {", + " return PyArray_NewFlagsObject(arg);", + " }", + " else {", + " return PyArray_NewFlagsObject(NULL);", + " }", + "}", + "", + "static PyTypeObject PyArrayFlags_Type = {", + " PyObject_HEAD_INIT(NULL)", + " 0,", + " \"numpy.flagsobj\",", + " sizeof(PyArrayFlagsObject),", + " 0,\t\t\t\t\t /* tp_itemsize */", + " /* methods */", + " (destructor)arrayflags_dealloc,\t\t/* tp_dealloc */", + " 0,\t\t\t\t\t/* tp_print */", + " 0,\t\t\t\t\t/* tp_getattr */", + " 0,\t\t\t\t\t/* tp_setattr */", + "\t0,\t\t /* tp_compare */", + " (reprfunc)arrayflags_print, /* tp_repr */", + " 0,\t\t\t\t\t/* tp_as_number */", + " 0,\t\t\t /* tp_as_sequence */", + " &arrayflags_as_mapping,\t /* tp_as_mapping */", + " 0,\t\t\t\t\t/* tp_hash */", + " 0,\t\t\t\t\t/* tp_call */", + " (reprfunc)arrayflags_print, /* tp_str */", + " 0,\t \t /* tp_getattro */", + " 0,\t\t\t\t\t/* tp_setattro */", + " 0,\t\t\t\t\t/* tp_as_buffer */", + " Py_TPFLAGS_DEFAULT, /* tp_flags */", + " 0,\t\t\t\t\t/* tp_doc */", + " 0,\t /* tp_traverse */", + " 0,\t\t\t\t\t/* tp_clear */", + " 0,\t\t\t\t\t/* tp_richcompare */", + " 0,\t\t\t\t\t/* tp_weaklistoffset */", + " 0,\t /* tp_iter */", + " 0,\t\t /* tp_iternext */", + " 0,\t \t /* tp_methods */", + " 0,\t /* tp_members */", + " arrayflags_getsets, /* tp_getset */", + " 0,\t\t\t\t /* tp_base */", + " 0,\t\t\t\t\t /* tp_dict */", + " 0,\t\t\t\t\t /* tp_descr_get */", + " 0,\t\t\t\t\t /* tp_descr_set */", + " 0,\t\t\t\t\t /* tp_dictoffset */", + " 0, \t /* tp_init */", + " 0,\t /* tp_alloc */", + " arrayflags_new,\t /* tp_new */", + " 0,\t /* tp_free */", + " 0,\t\t\t\t\t /* tp_is_gc */", + " 0,\t\t\t\t\t /* tp_bases */", + " 0,\t\t\t\t\t /* tp_mro */", + " 0,\t\t\t\t\t /* tp_cache */", + " 0,\t\t\t\t\t /* tp_subclasses */", + " 0\t\t\t\t\t /* tp_weaklist */", + "};" + ], + "deleted": [ + " return PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\",", + " self, self->flags, 0);", + "\tself->ob_type->tp_free(self);" + ] + } + }, + { + "old_path": "numpy/core/src/multiarraymodule.c", + "new_path": "numpy/core/src/multiarraymodule.c", + "filename": "multiarraymodule.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -5908,6 +5908,9 @@ DL_EXPORT(void) initmultiarray(void) {\n \tif (PyType_Ready(&PyArrayDescr_Type) < 0)\n \t\treturn;\n \n+\tif (PyType_Ready(&PyArrayFlags_Type) < 0)\n+\t\treturn;\n+\n \tc_api = PyCObject_FromVoidPtr((void *)PyArray_API, NULL);\n \tif (PyErr_Occurred()) goto err;\n \tPyDict_SetItemString(d, \"_ARRAY_API\", c_api);\n@@ -5930,6 +5933,9 @@ DL_EXPORT(void) initmultiarray(void) {\n \tPy_INCREF(&PyArrayDescr_Type);\n \tPyDict_SetItemString(d, \"dtype\", (PyObject *)&PyArrayDescr_Type);\n \n+\tPy_INCREF(&PyArrayFlags_Type);\n+\tPyDict_SetItemString(d, \"flagsobj\", (PyObject *)&PyArrayFlags_Type);\n+\n set_flaginfo(d);\n \n \tif (set_typeinfo(d) != 0) goto err;\n", + "added_lines": 6, + "deleted_lines": 0, + "source_code": "/*\n Python Multiarray Module -- A useful collection of functions for creating and\n using ndarrays\n\n Original file \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n Modified extensively for numpy in 2005 \n\n Travis E. Oliphant\n Assistant Professor at\n Brigham Young University\n \n*/\n\n/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */\n\n#include \"Python.h\"\n#include \"structmember.h\"\n/*#include \n#include \n*/\n\n#define _MULTIARRAYMODULE\n#include \"numpy/arrayobject.h\"\n\n#define PyAO PyArrayObject\n\nstatic PyObject *typeDict=NULL; /* Must be explicitly loaded */\nstatic PyObject *_numpy_internal=NULL; /* A Python module for callbacks */\nstatic int _multiarray_module_loaded=0;\n\nstatic PyArray_Descr *\n_arraydescr_fromobj(PyObject *obj)\n{\n\tPyObject *dtypedescr;\n\tPyArray_Descr *new;\n\tint ret;\n\t\n\tdtypedescr = PyObject_GetAttrString(obj, \"dtype\");\n\tPyErr_Clear();\n\tif (dtypedescr) {\n\t\tret = PyArray_DescrConverter(dtypedescr, &new);\n\t\tPy_DECREF(dtypedescr);\n\t\tif (ret) return new;\n\t\tPyErr_Clear();\n\t}\n\treturn NULL;\n}\n\n\n/* Including this file is the only way I know how to declare functions\n static in each file, and store the pointers from functions in both\n arrayobject.c and multiarraymodule.c for the C-API \n\n Declarying an external pointer-containing variable in arrayobject.c\n and trying to copy it to PyArray_API, did not work.\n\n Think about two modules with a common api that import each other...\n\n This file would just be the module calls. \n*/\n\n#include \"arrayobject.c\"\n\n\n/* An Error object -- rarely used? */\nstatic PyObject *MultiArrayError;\n\n/*MULTIARRAY_API\n Multiply a List of ints\n*/\nstatic int\nPyArray_MultiplyIntList(register int *l1, register int n) \n{\n\tregister int s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Multiply a List\n*/\nstatic intp \nPyArray_MultiplyList(register intp *l1, register int n) \n{\n\tregister intp s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Produce a pointer into array\n*/\nstatic void *\nPyArray_GetPtr(PyArrayObject *obj, register intp* ind)\n{\n\tregister int n = obj->nd;\n\tregister intp *strides = obj->strides;\n\tregister char *dptr = obj->data;\n\t\n\twhile (n--) dptr += (*strides++) * (*ind++);\n\treturn (void *)dptr;\n}\n\n/*MULTIARRAY_API\n Get axis from an object (possibly None) -- a converter function,\n*/\nstatic int \nPyArray_AxisConverter(PyObject *obj, int *axis)\n{\n\tif (obj == Py_None) {\n\t\t*axis = MAX_DIMS;\n\t}\n\telse {\n\t\t*axis = (int) PyInt_AsLong(obj);\n\t\tif (PyErr_Occurred()) {\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Compare Lists\n*/\nstatic int \nPyArray_CompareLists(intp *l1, intp *l2, int n) \n{\n int i;\n for(i=0;iob_type;\n\t\n\tPy_INCREF(self->descr);\n\tnew = PyArray_NewFromDescr(subtype,\n\t\t\t\t self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides,\n\t\t\t\t self->data,\n\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (new==NULL) return NULL;\n\tPy_INCREF(self);\n PyArray_BASE(new) = (PyObject *)self;\n\t\n\tif (type != NULL) {\n\t\tif (PyObject_SetAttrString(new, \"dtype\",\n\t\t\t\t\t (PyObject *)type) < 0) {\n\t\t\tPy_DECREF(new);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tPy_DECREF(type);\n\t}\n\treturn new;\t\n}\n\n/*MULTIARRAY_API\n Ravel\n*/\nstatic PyObject *\nPyArray_Ravel(PyArrayObject *a, int fortran)\n{\n\tPyArray_Dims newdim = {NULL,1};\n\tintp val[1] = {-1};\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tnewdim.ptr = val;\n\tif (!fortran && PyArray_ISCONTIGUOUS(a)) {\n\t\tif (a->nd == 1) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\treturn PyArray_Newshape(a, &newdim);\n\t}\n\telse\n\t return PyArray_Flatten(a, fortran);\n}\n\nstatic double\npower_of_ten(int n)\n{\n\tstatic const double p10[] = {1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8};\n\tdouble ret;\n\tif (n < 9)\n\t\tret = p10[n];\n\telse {\n\t\tret = 1e9;\n\t\twhile (n-- > 9)\n\t\t\tret *= 10.;\n\t}\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Round\n*/\nstatic PyObject *\nPyArray_Round(PyArrayObject *a, int decimals)\n{\n\tif (PyArray_ISCOMPLEX(a)) {\n\t\tPyObject *part;\n\t\tPyObject *round_part;\n\t\tPyObject *new;\n\t\tint res;\n\t\tnew = PyArray_Copy(a);\n\t\tif (new == NULL) return NULL;\n\n\t\t/* new.real = a.real.round(decimals) */\n\t\tpart = PyObject_GetAttrString(new, \"real\");\n\t\tif (part == NULL) {Py_DECREF(new); return NULL;}\n\t\tround_part = PyArray_Round\\\n\t\t\t((PyArrayObject *)PyArray_EnsureAnyArray(part), \n\t\t\t decimals);\n\t\tPy_DECREF(part);\n\t\tif (round_part == NULL) {Py_DECREF(new); return NULL;}\n\t\tres = PyObject_SetAttrString(new, \"real\", round_part);\n\t\tPy_DECREF(round_part);\n\t\tif (res < 0) {Py_DECREF(new); return NULL;}\n\n\t\t/* new.imag = a.imag.round(decimals) */\n\t\tpart = PyObject_GetAttrString(new, \"imag\");\n\t\tif (part == NULL) {Py_DECREF(new); return NULL;}\n\t\tround_part = PyArray_Round\\\n\t\t\t((PyArrayObject *)PyArray_EnsureAnyArray(part), \n\t\t\t decimals);\n\t\tPy_DECREF(part);\n\t\tif (round_part == NULL) {Py_DECREF(new); return NULL;}\n\t\tres = PyObject_SetAttrString(new, \"imag\", round_part);\n\t\tPy_DECREF(round_part);\n\t\tif (res < 0) {Py_DECREF(new); return NULL;}\n\t\treturn new;\n\t}\n\t/* do the most common case first */\n\tif (decimals == 0) {\n\t\tif (PyArray_ISINTEGER(a)) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\treturn PyArray_GenericUnaryFunction((PyAO *)a, n_ops.rint);\n\t}\n\tif (decimals > 0) {\n\t\tPyObject *f, *ret;\n\t\tif (PyArray_ISINTEGER(a)) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\tf = PyFloat_FromDouble(power_of_ten(decimals));\n\t\tif (f==NULL) return NULL;\n\t\tret = PyNumber_Multiply((PyObject *)a, f);\n\t\tif (ret==NULL) {Py_DECREF(f); return NULL;}\n\t\tif (PyArray_IsScalar(ret, Generic)) {\n\t\t\t/* array scalars cannot be modified inplace */\n\t\t\tPyObject *tmp;\n\t\t\ttmp = PyObject_CallFunction(n_ops.rint, \"O\", ret);\n\t\t\tPy_DECREF(ret);\n\t\t\tret = PyObject_CallFunction(n_ops.divide, \"OO\", \n\t\t\t\t\t\t tmp, f);\n\t\t\tPy_DECREF(tmp);\n\t\t} else {\n\t\t\tPyObject_CallFunction(n_ops.rint, \"OO\", ret, ret);\n\t\t\tPyObject_CallFunction(n_ops.divide, \"OOO\", ret, \n\t\t\t\t\t f, ret);\n\t\t}\n\t\tPy_DECREF(f);\n\t\treturn ret;\n\t} \n\telse {\n\t\t/* remaining case: decimals < 0 */\n\t\tPyObject *f, *ret;\n\t\tf = PyFloat_FromDouble(power_of_ten(-decimals));\n\t\tif (f==NULL) return NULL;\n\t\tret = PyNumber_Divide((PyObject *)a, f);\n\t\tif (ret==NULL) {Py_DECREF(f); return NULL;}\n\t\tif (PyArray_IsScalar(ret, Generic)) {\n\t\t\t/* array scalars cannot be modified inplace */\n\t\t\tPyObject *tmp;\n\t\t\ttmp = PyObject_CallFunction(n_ops.rint, \"O\", ret);\n\t\t\tPy_DECREF(ret);\n\t\t\tret = PyObject_CallFunction(n_ops.multiply, \"OO\", \n\t\t\t\t\t\t tmp, f);\n\t\t\tPy_DECREF(tmp);\n\t\t} else {\n\t\t\tPyObject_CallFunction(n_ops.rint, \"OO\", ret, ret);\n\t\t\tPyObject_CallFunction(n_ops.multiply, \"OOO\", ret, \n\t\t\t\t\t f, ret);\n\t\t}\n\t\tPy_DECREF(f);\n\t\treturn ret;\n\t}\n}\n\n\n/*MULTIARRAY_API\n Flatten\n*/\nstatic PyObject *\nPyArray_Flatten(PyArrayObject *a, int fortran)\n{\n\tPyObject *ret, *new;\n\tintp size;\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tsize = PyArray_SIZE(a);\n\tPy_INCREF(a->descr);\n\tret = PyArray_NewFromDescr(a->ob_type,\n\t\t\t\t a->descr,\n\t\t\t\t 1, &size,\n\t\t\t\t NULL,\n\t\t\t\t NULL,\n\t\t\t\t 0, (PyObject *)a);\n\t\n\tif (ret== NULL) return NULL;\n\tif (fortran) {\n\t\tnew = PyArray_Transpose(a, NULL);\n\t\tif (new == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tPy_INCREF(a);\n\t\tnew = (PyObject *)a;\n\t}\n\tif (PyArray_CopyInto((PyArrayObject *)ret, (PyArrayObject *)new) < 0) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn NULL;\n\t}\n\tPy_DECREF(new);\n\treturn ret;\n}\n\n\n/* For back-ward compatability *\n\n/ * Not recommended */\n\n/*MULTIARRAY_API\n Reshape an array\n*/\nstatic PyObject *\nPyArray_Reshape(PyArrayObject *self, PyObject *shape) \n{\n PyObject *ret;\n PyArray_Dims newdims;\n\n if (!PyArray_IntpConverter(shape, &newdims)) return NULL;\n ret = PyArray_Newshape(self, &newdims);\n PyDimMem_FREE(newdims.ptr);\n return ret;\n}\n\nstatic int\n_check_ones(PyArrayObject *self, int newnd, intp* newdims, intp *strides)\n{\n\tint nd;\n\tintp *dims;\n\tBool done=FALSE;\n\tint j, k;\n\n\tnd = self->nd;\n\tdims = self->dimensions;\n\n\tfor (k=0, j=0; !done && (jstrides[j];\n\t\t\tj++; k++;\n\t\t}\n\t\telse if ((kptr;\n PyArrayObject *ret;\n\tchar msg[] = \"total size of new array must be unchanged\";\n\tint n = newdims->len;\n Bool same;\n\tintp *strides = NULL;\n\tintp newstrides[MAX_DIMS];\n\n /* Quick check to make sure anything needs to be done */\n if (n == self->nd) {\n same = TRUE;\n i=0;\n while(same && i= 0) {\n\t\t\tif ((s_known == 0) || (s_original % s_known != 0)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdimensions[i_unknown] = s_original/s_known;\n\t\t} else {\n\t\t\tif (s_original != s_known) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t}\n \n\tPy_INCREF(self->descr);\n\tret = (PyAO *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t self->descr,\n\t\t\t\t\t n, dimensions,\n\t\t\t\t\t strides,\n\t\t\t\t\t self->data,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (ret== NULL) return NULL;\n\t\n Py_INCREF(self);\n ret->base = (PyObject *)self;\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\n\t\n return (PyObject *)ret;\n}\n\n/* return a new view of the array object with all of its unit-length \n dimensions squeezed out if needed, otherwise\n return the same array.\n */\n\n/*MULTIARRAY_API*/\nstatic PyObject *\nPyArray_Squeeze(PyArrayObject *self)\n{\n\tint nd = self->nd;\n\tint newnd = nd;\n\tintp dimensions[MAX_DIMS];\n\tintp strides[MAX_DIMS];\n\tint i,j;\n\tPyObject *ret;\n\n\tif (nd == 0) {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\tfor (j=0, i=0; idimensions[i] == 1) {\n\t\t\tnewnd -= 1;\n\t\t}\n\t\telse {\n\t\t\tdimensions[j] = self->dimensions[i];\n\t\t\tstrides[j++] = self->strides[i];\n\t\t}\n\t}\n\t\n\tPy_INCREF(self->descr);\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t self->descr,\n\t\t\t\t newnd, dimensions, \n\t\t\t\t strides, self->data, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPyArray_FLAGS(ret) &= ~OWN_DATA;\n\tPyArray_BASE(ret) = (PyObject *)self;\n\tPy_INCREF(self);\n\treturn (PyObject *)ret;\n}\n\n\n/*MULTIARRAY_API\n Mean\n*/\nstatic PyObject *\nPyArray_Mean(PyArrayObject *self, int axis, int rtype)\n{\n\tPyObject *obj1=NULL, *obj2=NULL;\n\tPyObject *new, *ret;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\n\tobj1 = PyArray_GenericReduceFunction((PyAO *)new, n_ops.add, axis,\n\t\t\t\t\t rtype);\n\tobj2 = PyFloat_FromDouble((double) PyArray_DIM(new,axis));\n Py_DECREF(new);\n\tif (obj1 == NULL || obj2 == NULL) {\n\t\tPy_XDECREF(obj1);\n\t\tPy_XDECREF(obj2);\n\t\treturn NULL;\n\t}\n\n\tret = PyNumber_Divide(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n}\n\n/* Set variance to 1 to by-pass square-root calculation and return variance */\n/*MULTIARRAY_API\n Std\n*/\nstatic PyObject *\nPyArray_Std(PyArrayObject *self, int axis, int rtype, int variance)\n{\n\tPyObject *obj1=NULL, *obj2=NULL, *new=NULL;\n\tPyObject *ret=NULL, *newshape=NULL;\n\tint i, n;\n\tintp val;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\t\n\t/* Compute and reshape mean */\n\tobj1 = PyArray_EnsureArray(PyArray_Mean((PyAO *)new, axis, rtype));\n\tif (obj1 == NULL) {Py_DECREF(new); return NULL;} \n\tn = PyArray_NDIM(new);\n\tnewshape = PyTuple_New(n);\n\tif (newshape == NULL) {Py_DECREF(obj1); Py_DECREF(new); return NULL;}\n\tfor (i=0; ind != 1) {\n Py_DECREF(cond);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"condition must be 1-d array\");\n return NULL;\n }\n\n res = PyArray_Nonzero(cond);\n Py_DECREF(cond);\n\tret = PyArray_Take(self, res, axis);\n\tPy_DECREF(res);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Nonzero\n*/\nstatic PyObject *\nPyArray_Nonzero(PyArrayObject *self)\n{\n int n=self->nd, j;\n\tintp count=0, i, size;\n\tPyArrayIterObject *it=NULL;\n\tPyObject *ret=NULL, *item;\n\tintp *dptr[MAX_DIMS];\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (it==NULL) return NULL;\n\n\tsize = it->size;\n\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) count++;\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\n\tPyArray_ITER_RESET(it);\n\tif (n==1) {\n\t\tret = PyArray_New(self->ob_type, 1, &count, PyArray_INTP, \n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)self);\n\t\tif (ret == NULL) goto fail;\n\t\tdptr[0] = (intp *)PyArray_DATA(ret);\n\t\t\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\t*(dptr[0])++ = i;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\t\t\n\t}\n\telse {\n\t\tret = PyTuple_New(n);\n\t\tfor (j=0; job_type, 1, &count, \n\t\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0,\n\t\t\t\t\t (PyObject *)self);\n\t\t\tif (item == NULL) goto fail;\n\t\t\tPyTuple_SET_ITEM(ret, j, item);\n\t\t\tdptr[j] = (intp *)PyArray_DATA(item);\n\t\t}\n\t\t\n\t\t/* reset contiguous so that coordinates gets updated */\n\t\tit->contiguous = 0;\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\tfor (j=0; jcoordinates[j];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\n\n\tPy_DECREF(it);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(ret);\n\tPy_XDECREF(it);\n\treturn NULL;\n \n}\n\n/*MULTIARRAY_API\n Clip\n*/\nstatic PyObject *\nPyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max)\n{\n\tPyObject *selector=NULL, *newtup=NULL, *ret=NULL;\n\tPyObject *res1=NULL, *res2=NULL, *res3=NULL;\n\tPyObject *two;\n\n\ttwo = PyInt_FromLong((long)2);\n\tres1 = PyArray_GenericBinaryFunction(self, max, n_ops.greater);\n\tres2 = PyArray_GenericBinaryFunction(self, min, n_ops.less);\n\tif ((res1 == NULL) || (res2 == NULL)) {\n\t\tPy_DECREF(two);\n\t\tPy_XDECREF(res1);\n\t\tPy_XDECREF(res2);\n\t}\n\tres3 = PyNumber_Multiply(two, res1);\n\tPy_DECREF(two); \n\tPy_DECREF(res1); \n\tif (res3 == NULL) return NULL;\n\n\tselector = PyArray_EnsureArray(PyNumber_Add(res2, res3));\n\tPy_DECREF(res2);\n\tPy_DECREF(res3);\n\tif (selector == NULL) return NULL;\n\n\tnewtup = Py_BuildValue(\"(OOO)\", (PyObject *)self, min, max);\n\tif (newtup == NULL) {Py_DECREF(selector); return NULL;}\n\tret = PyArray_Choose((PyAO *)selector, newtup);\n\tPy_DECREF(selector);\n\tPy_DECREF(newtup);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Conjugate\n*/\nstatic PyObject *\nPyArray_Conjugate(PyArrayObject *self)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyObject *new;\n\t\tintp size, i;\n\t\t/* Make a copy */\n\t\tnew = PyArray_NewCopy(self, -1);\n\t\tif (new==NULL) return NULL;\n\t\tsize = PyArray_SIZE(new);\n\t\tif (self->descr->type_num == PyArray_CFLOAT) {\n\t\t\tcfloat *dptr = (cfloat *) PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CDOUBLE) {\n\t\t\tcdouble *dptr = (cdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CLONGDOUBLE) {\n\t\t\tclongdouble *dptr = (clongdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\t\t\t\n\t\t}\t\t\n\t\treturn new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *) self;\n\t}\n}\n\n/*MULTIARRAY_API\n Trace\n*/\nstatic PyObject *\nPyArray_Trace(PyArrayObject *self, int offset, int axis1, int axis2, \nint rtype)\n{\n\tPyObject *diag=NULL, *ret=NULL;\n\n\tdiag = PyArray_Diagonal(self, offset, axis1, axis2);\n\tif (diag == NULL) return NULL;\n\tret = PyArray_GenericReduceFunction((PyAO *)diag, n_ops.add, -1, rtype);\n\tPy_DECREF(diag);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Diagonal\n*/\nstatic PyObject *\nPyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)\n{\n\tint n = self->nd;\n\tPyObject *new;\n\tPyArray_Dims newaxes;\n\tintp dims[MAX_DIMS];\n\tint i, pos;\t\n\n\tnewaxes.ptr = dims;\n\tif (n < 2) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"array.ndim must be >= 2\");\n\t\treturn NULL;\n\t}\n\tif (axis1 < 0) axis1 += n;\n\tif (axis2 < 0) axis2 += n;\n\tif ((axis1 == axis2) || (axis1 < 0) || (axis1 >= n) ||\t\\\n\t (axis2 < 0) || (axis2 >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \"axis1(=%d) and axis2(=%d) \"\\\n\t\t\t \"must be different and within range (nd=%d)\",\n\t\t\t axis1, axis2, n);\n\t\treturn NULL;\n\t}\n \n\tnewaxes.len = n;\n\t/* insert at the end */\n\tnewaxes.ptr[n-2] = axis1;\n\tnewaxes.ptr[n-1] = axis2;\n\tpos = 0;\n\tfor (i=0; idimensions[0];\n\t\tn2 = self->dimensions[1];\n\t\tstep = n2+1;\n\t\tif (offset < 0) {\n\t\t\tstart = -n2 * offset;\n\t\t\tstop = MIN(n2, n1+offset)*(n2+1) - n2*offset;\n\t\t}\n\t\telse {\n\t\t\tstart = offset;\n\t\t\tstop = MIN(n1, n2-offset)*(n2+1) + offset;\n\t\t}\n\t\t\n\t\t/* count = ceil((stop-start)/step) */\n\t\tcount = ((stop-start) / step) + (((stop-start) % step) != 0);\n\t\t\t\n\t\tindices = PyArray_New(&PyArray_Type, 1, &count, \n\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0, NULL);\n\t\tif (indices == NULL) {\n\t\t\tPy_DECREF(self); return NULL;\n\t\t}\n\t\tdptr = (intp *)PyArray_DATA(indices);\n\t\tfor (n1=start; n1descr;\n\n\t\tmydiagonal = PyList_New(0);\n\t\tif (mydiagonal == NULL) {Py_DECREF(self); return NULL;}\n\t\tn1 = self->dimensions[0];\n\t\tfor (i=0; i 3)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"C arrays of only 1-3 dimensions available\");\n\t\tPy_XDECREF(typedescr);\n\t\treturn -1;\n\t}\n\tif ((ap = (PyArrayObject*)PyArray_FromAny(*op, typedescr, nd, nd,\n\t\t\t\t\t\t CARRAY_FLAGS, NULL)) == NULL)\n\t\treturn -1;\n\tswitch(nd) {\n\tcase 1:\n\t\t*((char **)ptr) = ap->data;\n\t\tbreak;\n\tcase 2:\n\t\tn = ap->dimensions[0];\n\t\tptr2 = (char **)_pya_malloc(n * sizeof(char *));\n\t\tif (!ptr2) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0];\n\t\t}\n\t\t*((char ***)ptr) = ptr2;\n\t\tbreak;\t\t\n\tcase 3:\n\t\tn = ap->dimensions[0];\n\t\tm = ap->dimensions[1];\n\t\tptr3 = (char ***)_pya_malloc(n*(m+1) * sizeof(char *));\n\t\tif (!ptr3) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0] + \\\n\t\t\t\t\tj*ap->strides[1];\n\t\t\t}\n\t\t}\n\t\t*((char ****)ptr) = ptr3;\n\t}\n\tmemcpy(dims, ap->dimensions, nd*sizeof(intp));\n\t*op = (PyObject *)ap;\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_MemoryError, \"no memory\");\n\treturn -1;\n}\n\n/* Deprecated --- Use PyArray_AsCArray instead */\n\n/*MULTIARRAY_API\n Convert to a 1D C-array\n*/\nstatic int \nPyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) \n{\n\tintp newd1;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, descr) == -1)\n\t\treturn -1;\t\n\t*d1 = (int) newd1;\n\treturn 0;\n}\n\n/*MULTIARRAY_API\n Convert to a 2D C-array\n*/\nstatic int \nPyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) \n{\n\tintp newdims[2];\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, newdims, 2, descr) == -1)\n\t\treturn -1;\n\n\t*d1 = (int ) newdims[0];\n\t*d2 = (int ) newdims[1];\n return 0;\n}\n\n/* End Deprecated */\n\n/*MULTIARRAY_API\n Free pointers created if As2D is called\n*/\nstatic int \nPyArray_Free(PyObject *op, void *ptr) \n{\n PyArrayObject *ap = (PyArrayObject *)op;\n\t\n if ((ap->nd < 1) || (ap->nd > 3)) \n\t\treturn -1;\n if (ap->nd >= 2) {\n\t\t_pya_free(ptr);\n }\n Py_DECREF(ap);\n return 0;\n}\n\n\nstatic PyObject *\n_swap_and_concat(PyObject *op, int axis, int n)\n{\n\tPyObject *newtup=NULL;\n\tPyObject *otmp, *arr;\n\tint i;\n\n\tnewtup = PyTuple_New(n);\n\tif (newtup==NULL) return NULL;\n\tfor (i=0; i= MAX_DIMS) {\n\t\t\totmp = PyArray_Ravel(mps[i],0);\n\t\t\tPy_DECREF(mps[i]);\n\t\t\tmps[i] = (PyArrayObject *)otmp;\n\t\t}\n\t\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\n\t\t}\n\t}\n\t\n\tnew_dim = 0;\n\tfor(i=0; ind;\n\t\telse {\n\t\t\tif (nd != mps[i]->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"arrays must have same \"\\\n\t\t\t\t\t\t\"number of dimensions\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CompareLists(mps[0]->dimensions+1, \n\t\t\t\t\t\t mps[i]->dimensions+1, \n\t\t\t\t\t\t nd-1)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"array dimensions must \"\\\n\t\t\t\t\t\t\"agree except for d_0\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (nd == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"0-d arrays can't be concatenated\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnew_dim += mps[i]->dimensions[0];\n\t}\n\t\n\ttmp = mps[0]->dimensions[0];\n\tmps[0]->dimensions[0] = new_dim;\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(subtype, \n\t\t\t\t\t\t mps[0]->descr, nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ret);\n\tmps[0]->dimensions[0] = tmp;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tdata = ret->data;\n\tfor(i=0; idata, numbytes);\n\t\tdata += numbytes;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; ind;\n\tif (n <= 1) {\n\t\tPy_INCREF(ap);\n\t\treturn (PyObject *)ap;\n\t}\n\n\tif (a1 < 0) a1 += n;\n\tif (a2 < 0) a2 += n;\n\tif ((a1 < 0) || (a1 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis1 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tif ((a2 < 0) || (a2 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis2 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tnew_axes.ptr = dims;\n\tnew_axes.len = n;\n\n\tfor (i=0; ind;\n\t\tfor(i=0; ilen;\n\t\taxes = permute->ptr;\n\t\tif (n > ap->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many axes for this array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tfor(i=0; ind+axis;\n\t\t\tif (axis < 0 || axis >= ap->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"invalid axis for this array\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tpermutation[i] = axis;\n\t\t}\n\t}\n\t\n\t/* this allocates memory for dimensions and strides (but fills them\n\t incorrectly), sets up descr, and points data at ap->data. */\n\tPy_INCREF(ap->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t ap->descr, \n\t\t\t\t n, permutation, \n\t\t\t\t NULL, ap->data, ap->flags,\n\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) return NULL;\n\t\n\t/* point at true owner of memory: */\n\tret->base = (PyObject *)ap;\n\tPy_INCREF(ap);\n\t\n\tfor(i=0; idimensions[i] = ap->dimensions[permutation[i]];\n\t\tret->strides[i] = ap->strides[permutation[i]];\n\t}\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\t\n\n\treturn (PyObject *)ret;\t\n}\n\n/*MULTIARRAY_API\n Repeat the array.\n*/\nstatic PyObject *\nPyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis)\n{\n\tintp *counts;\n\tintp n, n_outer, i, j, k, chunk, total;\n\tintp tmp;\n\tint nd;\n\tPyArrayObject *repeats=NULL;\n\tPyObject *ap=NULL;\n\tPyArrayObject *ret=NULL;\n\tchar *new_data, *old_data;\n\n\trepeats = (PyAO *)PyArray_ContiguousFromAny(op, PyArray_INTP, 0, 1);\n\tif (repeats == NULL) return NULL;\n\tnd = repeats->nd;\n\tcounts = (intp *)repeats->data;\n\n\tif ((ap=_check_axis(aop, &axis, CARRAY_FLAGS))==NULL) {\n\t\tPy_DECREF(repeats);\n\t\treturn NULL;\n\t}\n\n\taop = (PyAO *)ap;\n\n\tif (nd == 1)\n\t\tn = repeats->dimensions[0];\n\telse /* nd == 0 */\n\t\tn = aop->dimensions[axis];\n\n\tif (aop->dimensions[axis] != n) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"a.shape[axis] != len(repeats)\");\n\t\tgoto fail;\n\t}\n\n\t\n\tif (nd == 0) \n\t\ttotal = counts[0]*n;\n\telse {\n\t\t\n\t\ttotal = 0;\n\t\tfor(j=0; jdimensions[axis] = total;\n\tPy_INCREF(aop->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(aop->ob_type, \n\t\t\t\t\t\t aop->descr,\n\t\t\t\t\t\t aop->nd,\n\t\t\t\t\t\t aop->dimensions,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)aop);\n\taop->dimensions[axis] = n;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tnew_data = ret->data;\n\told_data = aop->data;\n\t\n\tchunk = aop->descr->elsize;\n\tfor(i=axis+1; ind; i++) {\n\t\tchunk *= aop->dimensions[i];\n\t}\n\t\n\tn_outer = 1;\n\tfor(i=0; idimensions[i];\n\n\tfor(i=0; idescr->elsize;\n\tbyteorder = arr->descr->byteorder;\n\tptr = arr->data;\n\tif (elsize > 1 && \\\n\t (byteorder == PyArray_LITTLE ||\t\\\n\t (byteorder == PyArray_NATIVE &&\n\t PyArray_ISNBO(PyArray_LITTLE))))\n\t\tptr += elsize-1;\n\t\n\treturn ((*ptr & bitmask) != 0);\t\n}\n\n\n/*OBJECT_API*/\nstatic PyArray_SCALARKIND\nPyArray_ScalarKind(int typenum, PyArrayObject **arr) \n{\n\tif (PyTypeNum_ISSIGNED(typenum)) {\n\t\tif (arr && _signbit_set(*arr)) return PyArray_INTNEG_SCALAR;\n\t\telse return PyArray_INTPOS_SCALAR;\n\t}\n\tif (PyTypeNum_ISFLOAT(typenum)) return PyArray_FLOAT_SCALAR;\n\tif (PyTypeNum_ISUNSIGNED(typenum)) return PyArray_INTPOS_SCALAR;\n\tif (PyTypeNum_ISCOMPLEX(typenum)) return PyArray_COMPLEX_SCALAR;\n\tif (PyTypeNum_ISBOOL(typenum)) return PyArray_BOOL_SCALAR;\n\n\treturn PyArray_OBJECT_SCALAR;\n}\n\n/*OBJECT_API*/\nstatic int \nPyArray_CanCoerceScalar(char thistype, char neededtype, \n\t\t\tPyArray_SCALARKIND scalar) \n{\n\n\tswitch(scalar) {\n\tcase PyArray_NOSCALAR:\n\tcase PyArray_BOOL_SCALAR:\n\tcase PyArray_OBJECT_SCALAR:\n\t\treturn PyArray_CanCastSafely(thistype, neededtype);\n\tcase PyArray_INTPOS_SCALAR:\n\t\treturn (neededtype >= PyArray_UBYTE);\n\tcase PyArray_INTNEG_SCALAR:\n\t\treturn (neededtype >= PyArray_BYTE) &&\t\t\\\n\t\t\t!(PyTypeNum_ISUNSIGNED(neededtype));\n\tcase PyArray_FLOAT_SCALAR:\n\t\treturn (neededtype >= PyArray_FLOAT);\n\tcase PyArray_COMPLEX_SCALAR:\n\t\treturn (neededtype >= PyArray_CFLOAT);\n\t}\n\tfprintf(stderr, \"\\n**Error** coerce fall through: %d %d %d\\n\\n\", \n\t\tthistype, neededtype, scalar);\n\treturn 1; /* should never get here... */ \n}\n\n\n/* This needs to change to allow scalars of a different \"kind\" to alter the input type\n */\n\n/*OBJECT_API*/\nstatic PyArrayObject **\nPyArray_ConvertToCommonType(PyObject *op, int *retn)\n{\n\tint i, n, allscalars=0; \n\tPyArrayObject **mps=NULL;\n\tPyObject *otmp;\n\tPyArray_Descr *intype=NULL, *stype=NULL;\n\tPyArray_Descr *newtype=NULL;\n\tchar scalarkind;\n\n\t\n\t*retn = n = PySequence_Length(op);\n\tif (PyErr_Occurred()) {*retn = 0; return NULL;}\n\t\n\tmps = (PyArrayObject **)PyDataMem_NEW(n*sizeof(PyArrayObject *));\n\tif (mps == NULL) {\n\t\t*retn = 0;\n\t\treturn (void*)PyErr_NoMemory();\n\t}\n\t\n\tfor(i=0; itype_num, NULL);\n\t\t\tif (intype && !PyArray_CanCoerceScalar(newtype->type_num,\n\t\t\t\t\t\t\t intype->type_num, \n\t\t\t\t\t\t\t scalarkind)) {\n\t\t\t\tPy_XDECREF(intype);\n\t\t\t\tintype = stype;\n\t\t\t}\n\t\t\tmps[i] = (PyArrayObject *)Py_None;\n\t\t\tPy_INCREF(Py_None);\n\t\t}\n\t\tPy_XDECREF(otmp);\n\t}\n\tif (intype==NULL) { /* all scalars */\n\t\tallscalars = 1;\n\t\tintype = stype;\n\t\tPy_INCREF(intype);\n\t\tfor (i=0; ind < mps[i]->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many dimensions\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (!PyArray_CompareLists(ap->dimensions+(ap->nd-mps[i]->nd),\n\t\t\t\t mps[i]->dimensions, mps[i]->nd)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"array dimensions must agree\");\n\t\t\tgoto fail;\n\t\t}\n\t\tsizes[i] = PyArray_NBYTES(mps[i]);\n\t}\n\t\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t\t\t mps[0]->descr,\n\t\t\t\t\t\t ap->nd,\n\t\t\t\t\t\t ap->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\telsize = ret->descr->elsize;\n\tm = PyArray_SIZE(ret);\n\tself_data = (intp *)ap->data;\n\tret_data = ret->data;\n\t\n\tfor (i=0; i= n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid entry in choice array\");\n\t\t\tgoto fail;\n\t\t}\n\t\toffset = i*elsize;\n\t\tif (offset >= sizes[mi]) {offset = offset % sizes[mi]; }\n\t\tmemmove(ret_data, mps[mi]->data+offset, elsize);\n\t\tret_data += elsize; self_data++;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; idescr->f->sort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize);\n\n\tif (needcopy) {\n\t\tchar *buffer;\n\t\tbuffer = PyDataMem_NEW(N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(buffer, (intp) elsize, it->dataptr, \n\t\t\t\t astride, N, elsize);\n\t\t\tif (sort(buffer, N, op) < 0) {\n\t\t\t\tPyDataMem_FREE(buffer); goto fail;\n\t\t\t}\n\t\t\t_strided_copy(it->dataptr, astride, buffer, \n\t\t\t\t (intp) elsize, N, elsize);\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyDataMem_FREE(buffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tif (sort(it->dataptr, N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\t\n\t\n\tEND_THREADS\n\t\n\tPy_DECREF(it);\n\treturn 0;\n\n fail:\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nstatic PyObject*\n_new_argsort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\n\tPyArrayIterObject *it=NULL;\n\tPyArrayIterObject *rit=NULL;\n\tPyObject *ret;\n\tint needcopy=0, i;\n\tintp N, size;\n\tint elsize;\n\tintp astride, rstride, *iptr;\n\tPyArray_ArgSortFunc *argsort;\n\tBEGIN_THREADS_DEF \n\n\tret = PyArray_New(op->ob_type, op->nd,\n\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) return NULL;\n\n\tit = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)op, axis);\n\trit = (PyArrayIterObject *)PyArray_IterAllButAxis(ret, axis);\n\tif (rit == NULL || it == NULL) goto fail;\n\n\tBEGIN_THREADS\n\n\targsort = op->descr->f->argsort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize) || \\\n\t\t(rstride != sizeof(intp));\n\t\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(elsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(valbuffer, (intp) elsize, it->dataptr,\n\t\t\t\t astride, N, elsize);\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idataptr, rstride, indbuffer, \n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idataptr, (intp *)rit->dataptr, \n\t\t\t\t N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\t\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\tPy_DECREF(rit);\n\treturn ret;\n\n fail:\n\n\tEND_THREADS\n\n\tPy_DECREF(ret);\n\tPy_XDECREF(it);\n\tPy_XDECREF(rit);\n\treturn NULL;\n}\n\n\n/* Be sure to save this global_compare when necessary */\n\nstatic PyArrayObject *global_obj;\n\nstatic int \nqsortCompare (const void *a, const void *b) \n{\n\treturn global_obj->descr->f->compare(a,b,global_obj);\n}\n\n/* Consumes reference to ap (op gets it)\n op contains a version of the array with axes swapped if\n local variable axis is not the last dimension.\n orign must be defined locally. \n*/\n\n#define SWAPAXES(op, ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* Consumes reference to ap (op gets it)\n origin must be previously defined locally. \n SWAPAXES must have been called previously. \n op contains the swapped version of the array. \n*/\n#define SWAPBACK(op, ap) {\t \\\n\t\tif (axis != orign) { \\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* These swap axes in-place if necessary */\n#define SWAPINTP(a,b) {intp c; c=(a); (a) = (b); (b) = c;}\n#define SWAPAXES2(ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN); \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define SWAPBACK2(ap) {\t\t \\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n/*MULTIARRAY_API\n Sort an array in-place\n*/\nstatic int\nPyArray_Sort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *store_arr=NULL;\n\tchar *ip;\n\tint i, n, m, elsize, orign;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) return 0;\n\n\tif (axis < 0) axis += n;\n\tif ((axis < 0) || (axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\treturn -1;\n\t}\n\tif (!PyArray_ISWRITEABLE(op)) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"attempted sort on unwriteable array.\");\n\t\treturn -1;\n\t}\n\n\t/* Determine if we should use type-specific algorithm or not */\n\tif (op->descr->f->sort[which] != NULL) {\n\t\treturn _new_sort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || \\\n\t op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"desired sort not supported for this type\");\n\t\treturn -1;\n\t}\n\n\tSWAPAXES2(op);\n\n ap = (PyArrayObject *)PyArray_FromAny((PyObject *)op, \n\t\t\t\t\t NULL, 1, 0, \n\t\t\t\t\t DEFAULT_FLAGS | UPDATEIFCOPY, NULL);\t\n\tif (ap == NULL) goto fail;\n\t\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(ap)/m;\n\n\t/* Store global -- allows re-entry -- restore before leaving*/\n\tstore_arr = global_obj; \n\tglobal_obj = ap;\n\t\n\tfor (ip=ap->data, i=0; idescr->elsize;\n\tconst intp *ipa = ip1;\n\tconst intp *ipb = ip2;\t\n\treturn global_obj->descr->f->compare(global_data + (isize * *ipa),\n global_data + (isize * *ipb), \n\t\t\t\t\t global_obj);\n}\n\n/*MULTIARRAY_API\n ArgSort an array\n*/\nstatic PyObject *\nPyArray_ArgSort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *ret=NULL, *store;\n\tintp *ip;\n\tintp i, j, n, m, orign;\n\tint argsort_elsize;\n\tchar *store_ptr;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t\t op->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, \n\t\t\t\t\t\t (PyObject *)op);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)ret->data) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += n;\n\tif ((axis < 0) || (axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\treturn NULL;\n\t}\n\n\t/* Determine if we should use new algorithm or not */\n\tif (op->descr->f->argsort[which] != NULL) {\n\t\treturn _new_argsort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"requested sort not available for type\");\n\t\tgoto fail;\n\t}\n\n\tSWAPAXES(ap, op);\n\n\top = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ap, \n\t\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t\t 1, 0);\n\n\tif (op == NULL) return NULL;\n\t\n\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) goto fail;\n\t\n\t\n\tip = (intp *)ret->data;\n\targsort_elsize = op->descr->elsize;\n\tm = op->dimensions[op->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(op)/m;\n\tstore_ptr = global_data;\n\tglobal_data = op->data;\n\tstore = global_obj;\n\tglobal_obj = op;\n\tfor (i=0; i 0 in lexsort\");\n\t\treturn NULL;\n\t}\n\tmps = (PyArrayObject **) _pya_malloc(n*sizeof(PyArrayObject));\n\tif (mps==NULL) return PyErr_NoMemory();\n\tits = (PyArrayIterObject **) _pya_malloc(n*sizeof(PyArrayIterObject));\n\tif (its == NULL) {_pya_free(mps); return PyErr_NoMemory();}\n\tfor (i=0; i0) {\n\t\t\tif ((mps[i]->nd != mps[0]->nd) ||\t\\\n\t\t\t (!PyArray_CompareLists(mps[i]->dimensions,\n\t\t\t\t\t\t mps[0]->dimensions,\n\t\t\t\t\t\t mps[0]->nd))) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"all keys need to be the same shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (!mps[i]->descr->f->argsort[PyArray_MERGESORT]) {\n\t\t\tPyErr_Format(PyExc_TypeError, \n\t\t\t\t \"merge sort not available for item %d\", i);\n\t\t\tgoto fail;\n\t\t}\n\t\tits[i] = (PyArrayIterObject *)PyArray_IterAllButAxis\t\\\n\t\t\t((PyObject *)mps[i], axis);\n\t\tif (its[i]==NULL) goto fail;\n\t}\n\n\t/* Now we can check the axis */\n\tnd = mps[0]->nd;\n\tif ((nd==0) || (PyArray_SIZE(mps[0])==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)(ret->data)) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += nd;\n\tif ((axis < 0) || (axis >= nd)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\tgoto fail;\n\t}\n\n\t/* Now do the sorting */\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t mps[0]->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (ret == NULL) goto fail;\n\n\trit = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ret, axis);\n\tif (rit == NULL) goto fail;\n\n\tsize = rit->size;\n\tN = mps[0]->dimensions[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n maxelsize = mps[0]->descr->elsize;\n\tneedcopy = (rstride != sizeof(intp));\n\tfor (j=0; jflags & ALIGNED) || \\\n\t\t\t(mps[j]->strides[axis] != (intp)mps[j]->descr->elsize);\n if (mps[j]->descr->elsize > maxelsize) \n maxelsize = mps[j]->descr->elsize;\n\t}\n\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(maxelsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*maxelsize);\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idescr->elsize;\n\t\t\t\tastride = mps[j]->strides[axis];\t\n\t\t\t\targsort = mps[j]->descr->f->argsort[PyArray_MERGESORT];\n\t\t\t\t_strided_copy(valbuffer, (intp) elsize, its[j]->dataptr,\n\t\t\t\t\t astride, N, elsize);\n\t\t\t\tif (argsort(valbuffer, (intp *)indbuffer, N, mps[j]) < 0) {\n\t\t\t\t\tPyDataMem_FREE(valbuffer); goto fail;\n\t\t\t\t}\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\t_strided_copy(rit->dataptr, rstride, indbuffer,\n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idescr->f->argsort[PyArray_MERGESORT];\n\t\t\t\tif (argsort(its[j]->dataptr, (intp *)rit->dataptr,\n\t\t\t\t\t N, mps[j]) < 0) goto fail;\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\n\tfor (i=0; idescr->f->compare;\n\tintp min_i, max_i, i, j;\n\tint location, elsize = ap1->descr->elsize;\n\tintp elements = ap1->dimensions[ap1->nd-1];\n\tintp n = PyArray_SIZE(ap2);\n\tintp *rp = (intp *)ret->data;\n\tchar *ip = ap2->data;\n\tchar *vp = ap1->data;\n\n\tfor (j=0; j 0) {\n\t\t\t\t\tif (compare(ip, vp+elsize*(--i), ap2) \\\n\t\t\t\t\t != 0) {\n\t\t\t\t\t\ti = i+1; break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmin_i = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (location < 0) {\n\t\t\t\tmax_i = i;\n\t\t\t} else {\n\t\t\t\tmin_i = i+1;\n\t\t\t}\n\t\t}\n\t\t*rp = min_i;\n\t}\n}\n\n/*MULTIARRAY_API\n Numeric.searchsorted(a,v)\n*/\nstatic PyObject *\nPyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n\tint typenum = 0;\n\n\t/* \n PyObject *args;\n args = Py_BuildValue(\"O\",op2);\n\tPy_DELEGATE_ARGS(((PyObject *)op1), searchsorted, args);\n Py_XDECREF(args);\n\t*/\n\n\ttypenum = PyArray_ObjectType((PyObject *)op1, 0);\n\ttypenum = PyArray_ObjectType(op2, typenum);\n\tret = NULL;\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op1, \n\t\t\t\t\t\t\t typenum, \n\t\t\t\t\t\t\t 1, 1);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tret = (PyArrayObject *)PyArray_New(ap2->ob_type, ap2->nd, \n\t\t\t\t\t ap2->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap2);\n\tif (ret == NULL) goto fail;\n\n\tif (ap2->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tgoto fail;\n\t}\n\t\n\tlocal_where(ap1, ap2, ret); \n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n/*\n Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\treturn ret;\n}\n\n/* Could perhaps be redone to not make contiguous arrays \n */\n\n/*MULTIARRAY_API\n Numeric.innerproduct(a,v)\n*/\nstatic PyObject *\nPyArray_InnerProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tPyArray_Descr *typec;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\tdot = (ret->descr->f->dotfunc);\n\t\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[ap1->nd-1]; \n\tis2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, ap2->nd-1);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\n\tif (PyErr_Occurred()) goto fail;\n\t\t\n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n\n/* just like inner product but does the swapaxes stuff on the fly */\n/*MULTIARRAY_API\n Numeric.matrixproduct(a,v)\n*/\nstatic PyObject *\nPyArray_MatrixProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tintp matchDim;\n\tPyArray_Descr *typec;\n\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\t\n\t\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t}\n\telse {\n\t\tmatchDim = 0;\n\t}\n\n\tif (ap2->dimensions[matchDim] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"objects are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-2; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\tif(ap2->nd > 1) {\n\t\tdimensions[j++] = ap2->dimensions[ap2->nd-1];\n\t}\n\t/*\n\tfprintf(stderr, \"nd=%d dimensions=\", nd);\n\t for(i=0; istrides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\n /* Choose which subtype to return */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\n\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\t\t\n\top = ret->data; os = ret->descr->elsize;\n\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, matchDim);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\tif (PyErr_Occurred()) goto fail; /* only for OBJECT arrays */\n\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n/*MULTIARRAY_API\n Fast Copy and Transpose\n*/\nstatic PyObject *\nPyArray_CopyAndTranspose(PyObject *op) \n{\n\tPyObject *ret, *arr;\n\tint nd;\n\tintp dims[2];\n\tintp i,j;\n\tint elsize, str2;\n\tchar *iptr;\n\tchar *optr;\n\n\t/* make sure it is well-behaved */\n\tarr = PyArray_FromAny(op, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\tnd = PyArray_NDIM(arr);\n\tif (nd == 1) { /* we will give in to old behavior */\n\t\tret = PyArray_Copy((PyArrayObject *)arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\t\t\n\t}\n\telse if (nd != 2) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"only 2-d arrays are allowed\");\n\t\treturn NULL;\n\t}\n\n\t/* Now construct output array */\n\tdims[0] = PyArray_DIM(arr,1);\n\tdims[1] = PyArray_DIM(arr,0);\n\telsize = PyArray_ITEMSIZE(arr);\n\t\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(arr->ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t 2, dims, \n\t\t\t\t NULL, NULL, 0, arr);\n\n\tif (ret == NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn NULL;\n\t}\n\t/* do 2-d loop */\n\toptr = PyArray_DATA(ret);\n\tstr2 = elsize*dims[0];\n\tfor (i=0; idimensions[0];\n\tn2 = ap2->dimensions[0];\n\n\tif (n1 < n2) { \n\t\tret = ap1; ap1 = ap2; ap2 = ret; \n\t\tret = NULL; i = n1;n1=n2;n2=i;\n\t}\n\tlength = n1;\n\tn = n2;\n\tswitch(mode) {\n\tcase 0:\t\n\t\tlength = length-n+1;\n\t\tn_left = n_right = 0;\n\t\tbreak;\n\tcase 1:\n\t\tn_left = (intp)(n/2);\n\t\tn_right = n-n_left-1;\n\t\tbreak;\n\tcase 2:\n\t\tn_right = n-1;\n\t\tn_left = n-1;\n\t\tlength = length+n-1;\n\t\tbreak;\n\tdefault:\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mode must be 0, 1, or 2\");\n\t\tgoto fail;\n\t}\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\n\tif (ret == NULL) goto fail;\n\t\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"function not available for this data type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[0]; is2 = ap2->strides[0];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data; ip2 = ap2->data+n_left*is2;\n\tn = n-n_left;\n\tfor(i=0; idescr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Min\n*/\nstatic PyObject *\nPyArray_Min(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tret = PyArray_GenericReduceFunction(arr, n_ops.minimum, axis,\n\t\t\t\t\t arr->descr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Ptp\n*/\nstatic PyObject *\nPyArray_Ptp(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\tPyObject *obj1=NULL, *obj2=NULL;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tobj1 = PyArray_Max(arr, axis);\n\tif (obj1 == NULL) goto fail;\n\tobj2 = PyArray_Min(arr, axis);\n\tif (obj2 == NULL) goto fail;\n\tPy_DECREF(arr);\n\tret = PyNumber_Subtract(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(obj1);\n\tPy_XDECREF(obj2);\n\treturn NULL;\n}\n\n\n/*MULTIARRAY_API\n ArgMax\n*/\nstatic PyObject *\nPyArray_ArgMax(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap=NULL, *rp=NULL;\n\tPyArray_ArgFunc* arg_func;\n\tchar *ip;\n\tintp *rptr;\n\tintp i, n, orign, m;\n\tint elsize;\n\t\n\tif ((ap=(PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny((PyObject *)op, \n\t\t\t\t\t PyArray_NOTYPE, 1, 0);\n\n\tPy_DECREF(op);\n\tif (ap == NULL) return NULL;\n\t\n\targ_func = ap->descr->f->argmax;\n\tif (arg_func == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"data type not ordered\");\n\t\tgoto fail;\n\t}\n\n\trp = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd-1,\n\t\t\t\t\t ap->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)ap);\n\tif (rp == NULL) goto fail;\n\n\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) {\n\t\tPyErr_SetString(MultiArrayError, \n\t\t\t\t\"attempt to get argmax/argmin \"\\\n\t\t\t\t\"of an empty sequence??\");\n\t\tgoto fail;\n\t}\n\tn = PyArray_SIZE(ap)/m;\n\trptr = (intp *)rp->data;\n\tfor (ip = ap->data, i=0; ind + indices->nd - 1;\n for (i=0; i< nd; i++) {\n if (i < axis) {\n shape[i] = self->dimensions[i];\n n *= shape[i];\n } else {\n if (i < axis+indices->nd) {\n shape[i] = indices->dimensions[i-axis];\n m *= shape[i];\n } else {\n shape[i] = self->dimensions[i-indices->nd+1];\n chunk *= shape[i];\n }\n }\n }\n\tPy_INCREF(self->descr);\n ret = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t nd, shape, \n\t\t\t\t\t\t NULL, NULL, 0, \n\t\t\t\t\t\t (PyObject *)self);\n\t\n if (ret == NULL) goto fail;\n\t\n max_item = self->dimensions[axis];\n chunk = chunk * ret->descr->elsize;\n src = self->data;\n dest = ret->data;\n\t\n for(i=0; idata))[j];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\t\"index out of range for \"\\\n\t\t\t\t\t\t\"array\");\n goto fail;\n }\n memmove(dest, src+tmp*chunk, chunk);\n dest += chunk;\n }\n src += chunk*max_item;\n }\n\t\n PyArray_INCREF(ret);\n\n Py_XDECREF(indices);\n Py_XDECREF(self);\n\n return (PyObject *)ret;\n\t\n\t\n fail:\n Py_XDECREF(ret);\n Py_XDECREF(indices);\n Py_XDECREF(self);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array\n*/\nstatic PyObject *\nPyArray_Put(PyArrayObject *self, PyObject* values0, PyObject *indices0) \n{\n PyArrayObject *indices, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype; \n char *src, *dest;\n\n indices = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \"put: first argument must be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \"put: first argument must be contiguous\");\n return NULL;\n }\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0);\n if (indices == NULL) goto fail;\n ni = PyArray_SIZE(indices);\n\n\tthistype = self->descr->type_num;\n Py_INCREF(self->descr); \n\tvalues = (PyArrayObject *)PyArray_FromAny(values0, self->descr, 0, 0, \n\t\t\t\t\t\t DEFAULT_FLAGS | FORCECAST, NULL); \n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\n if (thistype == PyArray_OBJECT) { \n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n Py_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+tmp*chunk)));\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n\n }\n\n Py_XDECREF(values);\n Py_XDECREF(indices);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(indices);\n Py_XDECREF(values);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array according to a mask.\n*/\nstatic PyObject *\nPyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) \n{\n PyArrayObject *mask, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype;\n char *src, *dest;\n\n mask = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"putmask: first argument must \"\\\n\t\t\t\t\"be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: first argument must be contiguous\");\n return NULL;\n }\n\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n mask = (PyArrayObject *)\\\n\t\tPyArray_FROM_OTF(mask0, PyArray_BOOL, CARRAY_FLAGS | FORCECAST);\n\tif (mask == NULL) goto fail;\n ni = PyArray_SIZE(mask);\n if (ni != max_item) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: mask and data must be \"\\\n\t\t\t\t\"the same size\");\n goto fail;\n }\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n\tif (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\t /* zero if null array */\n if (nv > 0) {\n if (thistype == PyArray_OBJECT) {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) {\n\t\t\t\t\tPy_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+i*chunk)));\n memmove(dest + i * chunk, src, chunk);\n }\n\t\t\t}\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) memmove(dest + i * chunk, src, chunk);\n\t\t\t}\n\t\t}\n }\n\n Py_XDECREF(values);\n Py_XDECREF(mask);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(mask);\n Py_XDECREF(values);\n return NULL;\n}\n\n\n/* This conversion function can be used with the \"O&\" argument for\n PyArg_ParseTuple. It will immediately return an object of array type\n or will convert to a CARRAY any other object. \n\n If you use PyArray_Converter, you must DECREF the array when finished\n as you get a new reference to it.\n*/\n \n/*MULTIARRAY_API\n Useful to pass as converter function for O& processing in\n PyArgs_ParseTuple.\n*/\nstatic int \nPyArray_Converter(PyObject *object, PyObject **address) \n{\n if (PyArray_Check(object)) {\n *address = object;\n\t\tPy_INCREF(object);\n return PY_SUCCEED;\n }\n else {\n\t\t*address = PyArray_FromAny(object, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\t\tif (*address == NULL) return PY_FAIL;\n\t\treturn PY_SUCCEED;\n }\n}\n\n/*MULTIARRAY_API\n Convert an object to true / false\n*/\nstatic int\nPyArray_BoolConverter(PyObject *object, Bool *val)\n{ \n if (PyObject_IsTrue(object))\n *val=TRUE;\n else *val=FALSE;\n if (PyErr_Occurred())\n return PY_FAIL;\n return PY_SUCCEED;\n}\n\n\n/*MULTIARRAY_API\n Typestr converter\n*/\nstatic int\nPyArray_TypestrConvert(int itemsize, int gentype)\n{\n\tregister int newtype = gentype;\n\t\n\tif (gentype == PyArray_GENBOOLLTR) {\n\t\tif (itemsize == 1)\n\t\t\tnewtype = PyArray_BOOL;\n\t\telse \n\t\t\tnewtype = PyArray_NOTYPE;\n\t}\n\telse if (gentype == PyArray_SIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_INT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_INT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_INT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_INT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_INT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\n\t}\n\n\telse if (gentype == PyArray_UNSIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_UINT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_UINT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_UINT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_UINT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_UINT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t\tbreak;\n\t\t}\n\t}\n\telse if (gentype == PyArray_FLOATINGLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 4:\n\t\t\tnewtype = PyArray_FLOAT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_FLOAT64;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 10:\n\t\t\tnewtype = PyArray_FLOAT80;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 12:\n\t\t\tnewtype = PyArray_FLOAT96;\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_FLOAT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\t\n\telse if (gentype == PyArray_COMPLEXLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 8:\n\t\t\tnewtype = PyArray_COMPLEX64;\n\t\t\tbreak;\n\t\tcase 16:\n\t\t\tnewtype = PyArray_COMPLEX128;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 20:\n\t\t\tnewtype = PyArray_COMPLEX160;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 24:\n\t\t\tnewtype = PyArray_COMPLEX192;\t\t\t\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 32:\n\t\t\tnewtype = PyArray_COMPLEX256;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\n\treturn newtype;\n}\n\n\n/* this function takes a Python object which exposes the (single-segment)\n buffer interface and returns a pointer to the data segment\n \n You should increment the reference count by one of buf->base\n if you will hang on to a reference\n\n You only get a borrowed reference to the object. Do not free the\n memory...\n*/\n\n\n/*MULTIARRAY_API\n Get buffer chunk from object\n*/\nstatic int\nPyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)\n{\n int buflen;\n\n buf->ptr = NULL;\n buf->flags = BEHAVED_FLAGS;\n buf->base = NULL;\n\n\tif (obj == Py_None)\n\t\treturn PY_SUCCEED;\n\n if (PyObject_AsWriteBuffer(obj, &(buf->ptr), &buflen) < 0) {\n PyErr_Clear();\n buf->flags &= ~WRITEABLE;\n if (PyObject_AsReadBuffer(obj, (const void **)&(buf->ptr), \n &buflen) < 0)\n return PY_FAIL;\n }\n buf->len = (intp) buflen;\n \n /* Point to the base of the buffer object if present */\n if (PyBuffer_Check(obj)) buf->base = ((PyArray_Chunk *)obj)->base;\n if (buf->base == NULL) buf->base = obj;\n \n return PY_SUCCEED; \n}\n\n\n\n/* This function takes a Python sequence object and allocates and\n fills in an intp array with the converted values.\n\n **Remember to free the pointer seq.ptr when done using\n PyDimMem_FREE(seq.ptr)**\n*/\n\n/*MULTIARRAY_API\n Get intp chunk from sequence\n*/\nstatic int\nPyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)\n{\n int len;\n int nd;\n\n seq->ptr = NULL;\n if (obj == Py_None) return PY_SUCCEED;\n len = PySequence_Size(obj);\n if (len == -1) { /* Check to see if it is a number */\n if (PyNumber_Check(obj)) len = 1;\n }\n if (len < 0) {\n PyErr_SetString(PyExc_TypeError, \n \"expected sequence object with len >= 0\");\n return PY_FAIL;\n }\n if (len > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError, \"sequence too large; \" \\\n \"must be smaller than %d\", MAX_DIMS);\n return PY_FAIL;\n }\n\tif (len > 0) {\n\t\tseq->ptr = PyDimMem_NEW(len);\n\t\tif (seq->ptr == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n seq->len = len;\n nd = PyArray_IntpFromSequence(obj, (intp *)seq->ptr, len);\n if (nd == -1 || nd != len) {\n\t\tPyDimMem_FREE(seq->ptr);\n\t\tseq->ptr=NULL;\n\t\treturn PY_FAIL;\n\t}\n return PY_SUCCEED;\n}\n\n\n/* A tuple type would be either (generic typeobject, typesize) \n or (fixed-length data-type, shape) \n\n or (inheriting data-type, new-data-type)\n The new data-type must have the same itemsize as the inheriting data-type\n unless the latter is 0 \n \n Thus (int32, {'real':(int16,0),'imag',(int16,2)})\n\n is one way to specify a descriptor that will give \n a['real'] and a['imag'] to an int32 array.\n*/\n\n/* leave type reference alone */\nstatic PyArray_Descr *\n_use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) \n{\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n\t\n\t*errflag = 0;\n\tif (!PyArray_DescrConverter(newobj, &conv)) {\n\t\treturn NULL;\n\t}\n\t*errflag = 1;\n\tif (type == &OBJECT_Descr) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"cannot base a new descriptor on an\"\\\n\t\t\t\t\" OBJECT descriptor.\");\n\t\tgoto fail;\n\t}\n\tnew = PyArray_DescrNew(type);\n\tif (new == NULL) goto fail;\n\n\tif (new->elsize && new->elsize != conv->elsize) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mismatch in size of old\"\\\n\t\t\t\t\"and new data-descriptor\");\n\t\tgoto fail;\n\t}\n\tnew->elsize = conv->elsize;\n\tif (conv->fields != Py_None) {\n\t\tnew->fields = conv->fields;\n\t\tPy_XINCREF(new->fields);\n\t}\n\tPy_DECREF(conv);\n\t*errflag = 0;\n\treturn new;\n\n fail:\n\tPy_DECREF(conv);\n\treturn NULL;\n\n}\n\nstatic PyArray_Descr *\n_convert_from_tuple(PyObject *obj) \n{\n\tPyArray_Descr *type, *res;\n\tPyObject *val;\n\tint errflag;\n\t\n\tif (PyTuple_GET_SIZE(obj) != 2) return NULL;\n\n\tif (!PyArray_DescrConverter(PyTuple_GET_ITEM(obj,0), &type)) \n\t\treturn NULL;\n\tval = PyTuple_GET_ITEM(obj,1);\n\t/* try to interpret next item as a type */\n\tres = _use_inherit(type, val, &errflag);\n\tif (res || errflag) {\n\t\tPy_DECREF(type);\n\t\tif (res) return res;\n\t\telse return NULL;\n\t}\n\tPyErr_Clear();\n\t/* We get here if res was NULL but errflag wasn't set\n\t --- i.e. the conversion to a data-descr failed in _use_inherit\n\t*/\n\n\tif (type->elsize == 0) { /* interpret next item as a typesize */\n\t\tint itemsize;\n\t\titemsize = PyArray_PyIntAsInt(PyTuple_GET_ITEM(obj,1));\n\t\tif (error_converting(itemsize)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid itemsize in generic type \"\\\n\t\t\t\t\t\"tuple\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(type);\n\t\tif (type->type_num == PyArray_UNICODE)\n\t\t\ttype->elsize = itemsize << 2; \n\t\telse\n\t\t\ttype->elsize = itemsize;\n\t}\n\telse {\n\t\t/* interpret next item as shape (if it's a tuple)\n\t\t and reset the type to PyArray_VOID with \n\t\t a new fields attribute. \n\t */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyArray_Descr *newdescr;\n\t\tif (!(PyArray_IntpConverter(val, &shape)) || \n\t\t (shape.len > MAX_DIMS)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n\t\t\tgoto fail;\n\t\t}\n\t\t/* If (type, 1) was given, it is equivalent to type... */\n\t\tif (shape.len == 1 && shape.ptr[0] == 1 && \\\n\t\t PyNumber_Check(val)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\treturn type;\n\t\t}\n\t\tnewdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tif (newdescr == NULL) {PyDimMem_FREE(shape.ptr); goto fail;}\n\t\tnewdescr->elsize = type->elsize;\n\t\tnewdescr->elsize *= PyArray_MultiplyList(shape.ptr, \n\t\t\t\t\t\t\t shape.len);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tnewdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tnewdescr->subarray->base = type;\n\t\tif (type->hasobject) newdescr->hasobject = 1;\n\t\tPy_INCREF(val);\n\t\tnewdescr->subarray->shape = val;\n\t\tPy_XDECREF(newdescr->fields);\n\t\tnewdescr->fields = NULL;\n\t\ttype = newdescr;\n\t}\n\treturn type;\n\n fail:\n\tPy_XDECREF(type);\n\treturn NULL;\n}\n\n/* obj is a list. Each item is a tuple with\n\n(field-name, data-type (either a list or a string), and an optional \n shape parameter).\n*/\nstatic PyArray_Descr *\n_convert_from_array_descr(PyObject *obj)\n{\n\tint n, i, totalsize;\n\tint ret;\n\tPyObject *fields, *item, *newobj;\n\tPyObject *name, *key, *tup, *title;\n\tPyObject *nameslist;\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n int hasobject=0;\n\t\n\tn = PyList_GET_SIZE(obj);\t\n\tnameslist = PyTuple_New(n);\n\tif (!nameslist) return NULL;\n\ttotalsize = 0;\n\tfields = PyDict_New();\n\tfor (i=0; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New((title == NULL ? 2 : 3));\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\tif (title != NULL) {\t\t\t\n\t\t\tPy_INCREF(title);\n\t\t\tPyTuple_SET_ITEM(tup, 2, title);\n\t\t\tPyDict_SetItem(fields, title, tup);\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\ttotalsize += conv->elsize;\n\t\tPy_DECREF(tup);\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n\tnew->elsize = totalsize;\n new->hasobject=hasobject;\n\treturn new;\n \n fail:\n\tPy_DECREF(fields);\n\tPy_DECREF(nameslist);\n\treturn NULL;\n\n}\n\n/* a list specifying a data-type can just be\n a list of formats. The names for the fields\n will default to f1, f2, f3, and so forth.\n\n or it can be an array_descr format string -- in which case\n align must be 0. \n*/\n\nstatic PyArray_Descr *\n_convert_from_list(PyObject *obj, int align, int try_descr)\n{\n\tint n, i;\n\tint totalsize;\n\tPyObject *fields;\n\tPyArray_Descr *conv=NULL;\n\tPyArray_Descr *new;\n\tPyObject *key, *tup;\n\tPyObject *nameslist=NULL;\n \tint ret;\n\tint maxalign=0;\n int hasobject=0;\n\t\n\tn = PyList_GET_SIZE(obj);\n\ttotalsize = 0;\n\tif (n==0) return NULL;\n\tnameslist = PyTuple_New(n);\n\tif (!nameslist) return NULL;\n\tfields = PyDict_New();\n\tfor (i=0; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tif (align) {\n\t\t\tint _align;\n\t\t\t_align = conv->alignment;\n\t\t\tif (_align > 1) totalsize =\t\t\t\\\n\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\tmaxalign = MAX(maxalign, _align);\n\t\t}\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\tPyDict_SetItem(fields, key, tup);\n\t\tPy_DECREF(tup);\n\t\tPyTuple_SET_ITEM(nameslist, i, key);\n\t\ttotalsize += conv->elsize;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n new->hasobject=hasobject;\n\tif (maxalign > 1) {\n\t\ttotalsize = ((totalsize+maxalign-1)/maxalign)*maxalign;\n\t}\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\treturn new;\n\n fail:\n\tPy_DECREF(nameslist);\n\tPy_DECREF(fields);\n\tif (!try_descr) return NULL;\n\tif (align) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"failed to convert from list of formats \"\\\n\t\t\t\t\"and align cannot be 1 for conversion from \"\\\n\t\t\t\t\"array_descr structure\");\n\t\treturn NULL;\n\t}\n\tPyErr_Clear();\n\treturn _convert_from_array_descr(obj);\n}\n\n\n/* comma-separated string */\n/* this is the format developed by the numarray records module */\n/* and implemented by the format parser in that module */\n/* this is an alternative implementation found in the _internal.py \n file patterned after that one -- the approach is to try to convert \n to a list (with tuples if any repeat information is present) \n and then call the _convert_from_list)\n*/\n\nstatic PyArray_Descr *\n_convert_from_commastring(PyObject *obj, int align)\n{\n\tPyObject *listobj;\n\tPyArray_Descr *res;\n\n\tif (!PyString_Check(obj)) return NULL;\n listobj = PyObject_CallMethod(_numpy_internal, \"_commastring\",\n\t\t\t\t \"O\", obj);\n\tif (!listobj) return NULL;\n\tres = _convert_from_list(listobj, align, 0);\n\tPy_DECREF(listobj);\n\tif (!res && !PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_ValueError, \"invalid data-type\");\n\t\treturn NULL;\n\t}\n\treturn res;\n}\n\n\n\n/* a dictionary specifying a data-type\n must have at least two and up to four\n keys These must all be sequences of the same length.\n\n \"names\" --- field names \n \"formats\" --- the data-type descriptors for the field.\n \n Optional:\n\n \"offsets\" --- integers indicating the offset into the \n record of the start of the field.\n\t\t if not given, then \"consecutive offsets\" \n\t\t will be assumed and placed in the dictionary.\n \n \"titles\" --- Allows the use of an additional key\n for the fields dictionary.\n \nAttribute-lookup-based field names merely has to query the fields \ndictionary of the data-descriptor. Any result present can be used\nto return the correct field.\n\nSo, the notion of what is a name and what is a title is really quite\narbitrary. \n\nWhat does distinguish a title, however, is that if it is not None, \nit will be placed at the end of the tuple inserted into the \nfields dictionary.\n\nIf the dictionary does not have \"names\" and \"formats\" entries,\nthen it will be checked for conformity and used directly. \n*/\n\nstatic PyArray_Descr *\n_use_fields_dict(PyObject *obj, int align)\n{\n return (PyArray_Descr *)PyObject_CallMethod(_numpy_internal, \n\t\t\t\t\t\t \"_usefields\", \n\t\t\t\t\t\t \"Oi\", obj, align);\n}\n\nstatic PyArray_Descr *\n_convert_from_dict(PyObject *obj, int align)\n{\n\tPyArray_Descr *new;\n\tPyObject *fields=NULL;\n\tPyObject *names, *offsets, *descrs, *titles, *key;\n\tint n, i;\n\tint totalsize;\n\tint maxalign=0;\n int hasobject=0;\n\t\n\tfields = PyDict_New();\n\tif (fields == NULL) return (PyArray_Descr *)PyErr_NoMemory();\n\t\n\tnames = PyDict_GetItemString(obj, \"names\");\n\tdescrs = PyDict_GetItemString(obj, \"formats\");\n\n\tif (!names || !descrs) {\n\t\tPy_DECREF(fields);\n\t\treturn _use_fields_dict(obj, align);\n\t}\n\tn = PyObject_Length(names);\n\toffsets = PyDict_GetItemString(obj, \"offsets\");\n\ttitles = PyDict_GetItemString(obj, \"titles\");\n\tif ((n > PyObject_Length(descrs)) ||\t\t\t\\\n\t (offsets && (n > PyObject_Length(offsets))) ||\t\\\n\t (titles && (n > PyObject_Length(titles)))) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"all items in the dictionary must have\" \\\n\t\t\t\t\" the same length.\");\n\t\tgoto fail;\n\t}\n\n\ttotalsize = 0;\n\tfor(i=0; i totalsize) totalsize = offset;\n\t\t}\n\t\telse {\n\t\t\tif (align) {\n\t\t\t\tint _align = newdescr->alignment;\n\t\t\t\tif (_align > 1) totalsize =\t\t\\\n\t\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\t\tmaxalign = MAX(maxalign,_align);\n\t\t\t}\n\t\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\n\t\t}\n\t\tif (len == 3) PyTuple_SET_ITEM(tup, 2, item);\n\t\tname = PyObject_GetItem(names, index);\n\t\tPy_DECREF(index);\n\n\t\t/* Insert into dictionary */\n\t\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"name already used as a name or title\");\n\t\t\tret = PY_FAIL;\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) {\n\t\t\tif (PyDict_GetItem(fields, item) != NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"title already used as a name or \" \\\n\t\t\t\t\t\t\" title.\");\n\t\t\t\tret=PY_FAIL;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyDict_SetItem(fields, item, tup);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n if (!hasobject && newdescr->hasobject)\n hasobject = 1;\n\t\ttotalsize += newdescr->elsize;\n\t}\n\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tif (new == NULL) goto fail;\n\tif (maxalign > 1)\n\t\ttotalsize = ((totalsize + maxalign - 1)/maxalign)*maxalign;\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\tkey = PyInt_FromLong(-1);\n if (!PyTuple_Check(names)) {\n names = PySequence_Tuple(names);\n PyDict_SetItem(fields, key, names);\n Py_DECREF(names);\n }\n else PyDict_SetItem(fields, key, names);\n\tPy_DECREF(key);\n\tnew->fields = fields;\n new->hasobject=hasobject;\n\treturn new;\n\n fail:\n\tPy_XDECREF(fields);\n\treturn NULL;\n}\n\n/* \n any object with \n the .fields attribute and/or .itemsize attribute \n (if the .fields attribute does not give\n the total size -- i.e. a partial record naming).\n If itemsize is given it must be >= size computed from fields\n \n The .fields attribute must return a convertible dictionary if \n present. Result inherits from PyArray_VOID.\n*/\n\n\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to NULL\n*/\nstatic int\nPyArray_DescrConverter2(PyObject *obj, PyArray_Descr **at)\n{\n\tif (obj == Py_None) {\n\t\t*at = NULL;\n\t\treturn PY_SUCCEED;\n\t}\n\telse return PyArray_DescrConverter(obj, at);\n}\n\n/* This function takes a Python object representing a type and converts it \n to a the correct PyArray_Descr * structure to describe the type.\n \n Many objects can be used to represent a data-type which in NumPy is\n quite a flexible concept. \n\n This is the central code that converts Python objects to \n Type-descriptor objects that are used throughout numpy.\n */\n\n/* new reference in *at */\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to &LONG_descr\n*/\nstatic int\nPyArray_DescrConverter(PyObject *obj, PyArray_Descr **at)\n{\n char *type;\n int check_num=PyArray_NOTYPE+10;\n\tint len;\n\tPyObject *item;\n\tint elsize = 0;\n\tchar endian = '=';\n\n\t*at=NULL;\n\t\n\t/* default */\n if (obj == Py_None) {\n\t\t*at = PyArray_DescrFromType(PyArray_LONG);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n\tif (PyArray_DescrCheck(obj)) {\n\t\t*at = (PyArray_Descr *)obj;\n\t\tPy_INCREF(*at);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n if (PyType_Check(obj)) {\n\t\tif (PyType_IsSubtype((PyTypeObject *)obj, \n\t\t\t\t &PyGenericArrType_Type)) {\n\t\t\t*at = PyArray_DescrFromTypeObject(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t\telse return PY_FAIL;\n\t\t}\n\t\tcheck_num = PyArray_OBJECT;\n\t\tif (obj == (PyObject *)(&PyInt_Type))\n\t\t\tcheck_num = PyArray_LONG;\n\t\telse if (obj == (PyObject *)(&PyLong_Type))\n\t\t\tcheck_num = PyArray_LONGLONG;\n\t\telse if (obj == (PyObject *)(&PyFloat_Type)) \n\t\t\tcheck_num = PyArray_DOUBLE;\n\t\telse if (obj == (PyObject *)(&PyComplex_Type)) \n\t\t\tcheck_num = PyArray_CDOUBLE;\n\t\telse if (obj == (PyObject *)(&PyBool_Type))\n\t\t\tcheck_num = PyArray_BOOL;\n else if (obj == (PyObject *)(&PyString_Type))\n check_num = PyArray_STRING;\n else if (obj == (PyObject *)(&PyUnicode_Type))\n check_num = PyArray_UNICODE;\n\t\telse if (obj == (PyObject *)(&PyBuffer_Type))\n\t\t\tcheck_num = PyArray_VOID;\n\t\telse {\n\t\t\t*at = _arraydescr_fromobj(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* or a typecode string */\n\n\tif (PyString_Check(obj)) {\n\t\t/* Check for a string typecode. */\n\t\ttype = PyString_AS_STRING(obj);\n\t\tlen = PyString_GET_SIZE(obj);\n\t\tif (len <= 0) goto fail;\n\t\tcheck_num = (int) type[0];\n\t\tif ((char) check_num == '>' || (char) check_num == '<' || \\\n\t\t (char) check_num == '|' || (char) check_num == '=') {\n\t\t\tif (len <= 1) goto fail;\n\t\t\tendian = (char) check_num;\n\t\t\ttype++; len--;\n\t\t\tcheck_num = (int) type[0];\n\t\t\tif (endian == '|') endian = '=';\n\t\t}\n\t\tif (len > 1) {\n\t\t\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\t\t\tfor (i=1;ielsize == 0) && (elsize != 0)) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->elsize = elsize;\n\t}\n\tif (endian != '=' && PyArray_ISNBO(endian)) endian = '='; \n\t\n\tif (endian != '=' && (*at)->byteorder != '|' &&\t\\\n\t (*at)->byteorder != endian) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->byteorder = endian;\n\t}\n\t\n return PY_SUCCEED;\n\n fail:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"data type not understood\");\n\t*at=NULL;\n\treturn PY_FAIL;\n}\t\n\n/*MULTIARRAY_API\n Convert object to endian\n*/\nstatic int\nPyArray_ByteorderConverter(PyObject *obj, char *endian)\n{\n\tchar *str;\n\t*endian = PyArray_SWAP;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Byteorder string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\t*endian = str[0];\n\tif (str[0] != PyArray_BIG && str[0] != PyArray_LITTLE &&\t\\\n\t str[0] != PyArray_NATIVE) {\n\t\tif (str[0] == 'b' || str[0] == 'B')\n\t\t\t*endian = PyArray_BIG;\n\t\telse if (str[0] == 'l' || str[0] == 'L')\n\t\t\t*endian = PyArray_LITTLE;\n\t\telse if (str[0] == 'n' || str[0] == 'N')\n\t\t\t*endian = PyArray_NATIVE;\n\t\telse if (str[0] == 'i' || str[0] == 'I')\n\t\t\t*endian = PyArray_IGNORE;\n\t\telse if (str[0] == 's' || str[0] == 'S')\n\t\t\t*endian = PyArray_SWAP;\n\t\telse {\n\t\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t\t \"%s is an unrecognized byteorder\",\n\t\t\t\t str);\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Convert object to sort kind \n*/\nstatic int\nPyArray_SortkindConverter(PyObject *obj, PyArray_SORTKIND *sortkind)\n{\n\tchar *str;\n\t*sortkind = PyArray_QUICKSORT;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Sort kind string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\tif (str[0] == 'q' || str[0] == 'Q')\n\t\t*sortkind = PyArray_QUICKSORT;\n\telse if (str[0] == 'h' || str[0] == 'H')\n\t\t*sortkind = PyArray_HEAPSORT;\n\telse if (str[0] == 'm' || str[0] == 'M')\n\t\t*sortkind = PyArray_MERGESORT;\n\telse if (str[0] == 't' || str[0] == 'T')\n\t\t*sortkind = PyArray_TIMSORT;\n\telse {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"%s is an unrecognized kind of sort\",\n\t\t\t str);\n\t\treturn PY_FAIL;\n\t}\n\treturn PY_SUCCEED;\n}\n\n\n/* This function returns true if the two typecodes are \n equivalent (same basic kind and same itemsize).\n*/\n\n/*MULTIARRAY_API*/\nstatic Bool\nPyArray_EquivTypes(PyArray_Descr *typ1, PyArray_Descr *typ2)\n{\n\tregister int typenum1=typ1->type_num;\n\tregister int typenum2=typ2->type_num;\n\tregister int size1=typ1->elsize;\n\tregister int size2=typ2->elsize;\n\n\tif (size1 != size2) return FALSE;\n\tif (typ1->fields != typ2->fields) return FALSE;\n\tif (PyArray_ISNBO(typ1->byteorder) != PyArray_ISNBO(typ2->byteorder))\n\t\treturn FALSE;\n\n\tif (typenum1 == PyArray_VOID || \\\n\t typenum2 == PyArray_VOID) {\n\t\treturn ((typenum1 == typenum2) && \n\t\t\t(typ1->typeobj == typ2->typeobj) &&\n\t\t\t(typ1->fields == typ2->fields));\n\t}\n\treturn (typ1->kind == typ2->kind);\n}\n\n/*** END C-API FUNCTIONS **/\n\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\n\n\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_fromobject[] = \"array(object, dtype=None, copy=1, fortran=0, \"\\\n \"subok=0,ndmin=0)\\n\"\\\n \"will return a new array formed from the given object type given.\\n\"\\\n \"Object can be anything with an __array__ method, or any object\\n\"\\\n \"exposing the array interface, or any (nested) sequence.\\n\"\\\n \"If no type is given, then the type will be determined as the\\n\"\\\n \"minimum type required to hold the objects in the sequence.\\n\"\\\n \"If copy is zero and sequence is already an array with the right \\n\"\\\n \"type, a reference will be returned. If the sequence is an array,\\n\"\\\n \"type can be used only to upcast the array. For downcasting \\n\"\\\n \"use .astype(t) method. If subok is true, then subclasses of the\\n\"\\\n \"array may be returned. Otherwise, a base-class ndarray is returned\\n\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\n\nstatic PyObject *\n_array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n{\n\tPyObject *op, *ret=NULL;\n\tstatic char *kwd[]= {\"object\", \"dtype\", \"copy\", \"fortran\", \"subok\", \n\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\n\tPyArray_Descr *type=NULL;\n\tPyArray_Descr *oldtype=NULL;\n\tBool fortran=FALSE;\n\tint flags=0;\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&i\", kwd, &op, \n\t\t\t\t\tPyArray_DescrConverter2,\n &type, \n\t\t\t\t\tPyArray_BoolConverter, ©, \n\t\t\t\t\tPyArray_BoolConverter, &fortran,\n PyArray_BoolConverter, &subok, \n\t\t\t\t\t&ndmin)) \n\t\treturn NULL;\n\n\t/* fast exit if simple call */\n\tif (PyArray_CheckExact(op)) {\n\t\tif (type==NULL) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\tret = op;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op, \n\t\t\t\t\t\t fortran);\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\t/* One more chance */\n\t\toldtype = PyArray_DESCR(op);\n\t\tif (PyArray_EquivTypes(oldtype, type)) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\tret = op;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op,\n\t\t\t\t\t\t fortran);\n\t\t\t\tif (oldtype == type) return ret;\n\t\t\t\tPy_INCREF(oldtype);\n\t\t\t\tPy_DECREF(PyArray_DESCR(ret));\n\t\t\t\tPyArray_DESCR(ret) = oldtype;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (copy) {\n\t\tflags = ENSURECOPY;\n\t}\n\tif (fortran) {\n\t\tflags |= FORTRAN;\n\t}\n if (!subok) {\n flags |= ENSUREARRAY;\n }\n\n\tif ((ret = PyArray_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\n}\n\n/* accepts NULL type */\n/* steals referenct to type */\n/*MULTIARRAY_API\n Empty\n*/\nstatic PyObject *\nPyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n \n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type, nd, dims, \n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n PyArray_FillObjectArray(ret, Py_None);\n\t}\n\treturn (PyObject *)ret;\n}\n\n\nstatic char doc_empty[] = \"empty((d1,...,dn),dtype=int,fortran=0) will return a new array\\n of shape (d1,...,dn) and given type with all its entries uninitialized. This can be faster than zeros.\";\n\nstatic PyObject *\narray_empty(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter, &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Empty(shape.len, shape.ptr, typecode, fortran); \n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_scalar[] = \"scalar(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype corresponds to an OBJECT descriptor, then obj can be any object, otherwise obj must be a string. If obj is not given it will be interpreted as None for object type and zeros for all other types.\";\n\nstatic PyObject *\narray_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"dtype\",\"obj\", NULL};\n\tPyArray_Descr *typecode;\n\tPyObject *obj=NULL;\n\tint alloc=0;\n\tvoid *dptr;\n\tPyObject *ret;\n\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|O\",\n\t\t\t\t\t kwlist, &PyArrayDescr_Type, \n\t\t\t\t\t &typecode,\n\t\t\t\t\t &obj)) \n\t\treturn NULL;\n\t\t\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\t\t\\\n\t\t\t\t\"itemsize cannot be zero\");\n\t\treturn NULL;\n\t}\n\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (obj == NULL) obj = Py_None;\n\t\tdptr = &obj;\n\t}\n\telse {\n\t\tif (obj == NULL) {\n\t\t\tdptr = _pya_malloc(typecode->elsize);\n\t\t\tif (dptr == NULL) {\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemset(dptr, '\\0', typecode->elsize);\n\t\t\talloc = 1;\n\t\t}\n\t\telse {\n\t\t\tif (!PyString_Check(obj)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"initializing object must \"\\\n\t\t\t\t\t\t\"be a string\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tif (PyString_GET_SIZE(obj) < typecode->elsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"initialization string is too\"\\\n\t\t\t\t\t\t\" small\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdptr = PyString_AS_STRING(obj);\n\t\t}\n\t}\n\n\tret = PyArray_Scalar(dptr, typecode, NULL);\n\t\n\t/* free dptr which contains zeros */\n\tif (alloc) _pya_free(dptr);\n\treturn ret;\n}\n\n\n/* steal a reference */\n/* accepts NULL type */\n/*MULTIARRAY_API\n Zeros\n*/\nstatic PyObject *\nPyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n\tintp n;\n\n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type,\n\t\t\t\t\t\t nd, dims, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n\t\tPyObject *zero = PyInt_FromLong(0);\n PyArray_FillObjectArray(ret, zero);\n Py_DECREF(zero);\n\t}\n\telse {\n\t\tn = PyArray_NBYTES(ret);\n\t\tmemset(ret->data, 0, n);\n\t}\n\treturn (PyObject *)ret;\n\n}\n\nstatic char doc_zeros[] = \"zeros((d1,...,dn),dtype=int,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.\";\n\n\nstatic PyObject *\narray_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL}; /* XXX ? */\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Zeros(shape.len, shape.ptr, typecode, (int) fortran);\n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_set_typeDict[] = \"set_typeDict(dict) set the internal \"\\\n\t\"dictionary that can look up an array type using a registered \"\\\n\t\"code\";\n\nstatic PyObject *\narray_set_typeDict(PyObject *ignored, PyObject *args)\n{\n\tPyObject *dict;\n\tif (!PyArg_ParseTuple(args, \"O\", &dict)) return NULL;\n\tPy_XDECREF(typeDict); /* Decrement old reference (if any)*/\n\ttypeDict = dict;\n\tPy_INCREF(dict); /* Create an internal reference to it */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\n\t\n\titemsize = dtype->elsize;\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"zero-valued itemsize\");\n\t\tPy_DECREF(dtype);\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_fromString[] = \"fromstring(string, dtype=int, count=-1, sep='') returns a new 1d array initialized from the raw binary data in string. If count is positive, the new array will have count elements, otherwise it's size is determined by the size of string. If sep is not empty then the string is interpreted in ASCII mode and converted to the desired number type using sep as the separator between elements (extra whitespace is ignored).\";\n\nstatic PyObject *\narray_fromString(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tchar *data;\n\tlonglong nin=-1;\n\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", kwlist, \n\t\t\t\t\t &data, &s, \n\t\t\t\t\t PyArray_DescrConverter, &descr,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\n}\n\n/* This needs an open file object and reads it in directly. \n memory-mapped files handled differently through buffer interface.\n\nfile pointer number in resulting 1d array \n(can easily reshape later, -1 for to end of file)\ntype of array\nsep is a separator string for character-based data (or NULL for binary)\n \" \" means whitespace\n*/\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep)\n{\n\tPyArrayObject *r;\n\tsize_t nread = 0;\n\tPyArray_ScanFunc *scan;\n\tBool binary;\n\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"0-sized elements.\");\n\t\tPy_DECREF(typecode);\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\n\tif (num == -1 && binary) { /* Get size for binary file*/\n\t\tintp start, numbytes;\n\t\tstart = (intp )ftell(fp);\n\t\tfseek(fp, 0, SEEK_END);\n\t\tnumbytes = (intp )ftell(fp) - start;\n\t\trewind(fp);\n\t\tif (numbytes == -1) {\n\t\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\t\"could not seek in file\");\n\t\t\tPy_DECREF(typecode);\n\t\t\treturn NULL;\n\t\t}\n\t\tnum = numbytes / typecode->elsize;\n\t}\n\t\n\tif (binary) { /* binary data */\n\t\tr = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t 0, NULL);\n\t\tif (r==NULL) return NULL;\n\t\tnread = fread(r->data, typecode->elsize, num, fp);\n\t}\n\telse { /* character reading */\n\t\tintp i;\n\t\tchar *dptr;\n\t\tint done=0;\n\n\t\tscan = typecode->f->scanfunc;\n\t\tif (scan == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character files with that \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(typecode);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (num != -1) { /* number to read is known */\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode, \n\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\tdptr = r->data;\n\t\t\tfor (i=0; i < num; i++) {\n\t\t\t\tif (done) break;\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\t\t\t\tif (done < -2) break;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\telse { /* we have to watch for the end of the file and \n\t\t\t reallocate at the end */\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * typecode->elsize;\n\t\t\tdptr = r->data;\n\t\t\twhile (!done) {\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\n\t\t\t\t/* end of file reached trying to \n\t\t\t\t scan value. done is 1 or 2\n\t\t\t\t if end of file reached trying to\n\t\t\t\t scan separator. Still good value.\n\t\t\t\t*/\n\t\t\t\tif (done < -2) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t\tif (!done && thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tr->data = PyDataMem_RENEW(r->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = r->data + (totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tr->data = PyDataMem_RENEW(r->data, nread*r->descr->elsize);\n\t\t\tPyArray_DIM(r,0) = nread;\n\t\t\tnum = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\tif (nread < num) {\n\t\tfprintf(stderr, \"%ld items requested but only %ld read\\n\", \n\t\t\t(long) num, (long) nread);\n\t\tr->data = PyDataMem_RENEW(r->data, nread * r->descr->elsize);\n\t\tPyArray_DIM(r,0) = nread;\n\t}\n\treturn (PyObject *)r;\n}\n\nstatic char doc_fromfile[] = \\\n\t\"fromfile(file=, dtype=int, count=-1, sep='')\\n\"\t\\\n\t\"\\n\"\\\n\t\" Return an array of the given data type from a \\n\"\\\n\t\" (text or binary) file. The file argument can be an open file\\n\"\\\n\t\" or a string with the name of a file to read from. If\\n\"\\\n\t\" count==-1, then the entire file is read, otherwise count is\\n\"\\\n\t\" the number of items of the given type read in. If sep is ''\\n\"\\\n\t\" then read a binary file, otherwise it gives the separator\\n\"\\\n\t\" between elements in a text file.\\n\"\\\n\t\"\\n\"\\\n\t\" WARNING: This function should be used sparingly, as it is not\\n\"\\\n\t\" a platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to read in simply-formatted or binary data quickly.\";\n\nstatic PyObject *\narray_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *file=NULL, *ret;\n\tFILE *fp;\n\tchar *sep=\"\";\n\tchar *mode=NULL;\n\tlonglong nin=-1;\n\tstatic char *kwlist[] = {\"file\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *type=NULL;\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Ls\", kwlist, \n\t\t\t\t\t &file,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\tif (type == NULL) type = PyArray_DescrFromType(PyArray_LONG);\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"rb\";\n\t\telse mode=\"r\";\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), mode);\n\t\tif (file==NULL) return NULL;\n\t}\n\telse {\n\t\tPy_INCREF(file);\n\t}\n\tfp = PyFile_AsFile(file);\n\tif (fp == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\"first argument must be an open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_FromFile(fp, type, (intp) nin, sep);\n\tPy_DECREF(file);\n\treturn ret;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, \n\t\t intp count, intp offset) \n{\n\tPyArrayObject *ret;\n\tchar *data;\n\tint ts;\n\tintp s, n;\n\tint itemsize;\n\tint write=1;\n\n\n\tif (type->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot create an OBJECT array from memory\"\\\n\t\t\t\t\" buffer\");\n\t\tPy_DECREF(type);\n\t\treturn NULL;\n\t}\n\tif (type->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"itemsize cannot be zero in type\");\n\t\tPy_DECREF(type);\n\t\treturn NULL; \t\t\n\t}\n\n\tif (buf->ob_type->tp_as_buffer == NULL || \\\n\t (buf->ob_type->tp_as_buffer->bf_getwritebuffer == NULL &&\t\\\n\t buf->ob_type->tp_as_buffer->bf_getreadbuffer == NULL)) {\n\t\tPyObject *newbuf;\n\t\tnewbuf = PyObject_GetAttrString(buf, \"__buffer__\");\n\t\tif (newbuf == NULL) {Py_DECREF(type); return NULL;}\n\t\tbuf = newbuf;\n\t}\n\telse {Py_INCREF(buf);}\n\n\tif (PyObject_AsWriteBuffer(buf, (void *)&data, &ts)==-1) {\n\t\twrite = 0;\n\t\tPyErr_Clear();\n\t\tif (PyObject_AsReadBuffer(buf, (void *)&data, &ts)==-1) {\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((offset < 0) || (offset >= ts)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"offset must be positive and smaller than %\"\n\t\t\t INTP_FMT, (intp)ts);\n\t}\n\n\tdata += offset;\n\ts = (intp)ts - offset;\n\tn = (intp)count;\n\titemsize = type->elsize;\n\t\n\tif (n < 0 ) {\n\t\tif (s % itemsize != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tn = s/itemsize;\n\t} else {\n\t\tif (s < n*itemsize) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t type, \n\t\t\t\t\t\t\t 1, &n, \n\t\t\t\t\t\t\t NULL, data, \n\t\t\t\t\t\t\t DEFAULT_FLAGS,\n\t\t\t\t\t\t\t NULL)) == NULL) {\n\t\tPy_DECREF(buf);\n\t\treturn NULL;\n\t}\n\t\n\tif (!write) ret->flags &= ~WRITEABLE;\n\n\t/* Store a reference for decref on deallocation */\n\tret->base = buf;\n\tPyArray_UpdateFlags(ret, ALIGNED);\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_frombuffer[] = \\\n\t\"frombuffer(buffer=, dtype=int, count=-1, offset=0)\\n\"\\\n\t\"\\n\"\t\t\t\t\t\t\t\t\\\n\t\" Returns a 1-d array of data type dtype from buffer. The buffer\\n\"\\\n\t\" argument must be an object that exposes the buffer interface.\\n\"\\\n\t\" If count is -1 then the entire buffer is used, otherwise, count\\n\"\\\n\t\" is the size of the output. If offset is given then jump that\\n\"\\\n\t\" far into the buffer. If the buffer has data that is out\\n\" \\\n\t\" not in machine byte-order, than use a propert data type\\n\"\\\n\t\" descriptor. The data will not\\n\" \\\n\t\" be byteswapped, but the array will manage it in future\\n\"\\\n\t\" operations.\\n\";\n\nstatic PyObject *\narray_frombuffer(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *obj=NULL;\n\tlonglong nin=-1, offset=0;\n\tstatic char *kwlist[] = {\"buffer\", \"dtype\", \"count\", \"offset\", NULL};\n\tPyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&LL\", kwlist, \n\t\t\t\t\t &obj,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &offset)) {\n\t\treturn NULL;\n\t}\n\tif (type==NULL)\n\t\ttype = PyArray_DescrFromType(PyArray_LONG);\n\t\n\treturn PyArray_FromBuffer(obj, type, (intp)nin, (intp)offset);\n}\n\n\nstatic char doc_concatenate[] = \"concatenate((a1,a2,...),axis=None).\";\n\nstatic PyObject *\narray_concatenate(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *a0;\n\tint axis=0;\n\tstatic char *kwlist[] = {\"seq\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist,\n\t\t\t\t\t &a0,\n\t\t\t\t\t PyArray_AxisConverter, &axis))\n\t\treturn NULL;\n\treturn PyArray_Concatenate(a0, axis);\n}\n\nstatic char doc_innerproduct[] = \\\n\t\"inner(a,b) returns the dot product of two arrays, which has\\n\"\\\n\t\"shape a.shape[:-1] + b.shape[:-1] with elements computed by\\n\" \\\n\t\"the product of the elements from the last dimensions of a and b.\";\n\nstatic PyObject *array_innerproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *b0, *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a0, &b0)) return NULL;\n\t\n\treturn _ARET(PyArray_InnerProduct(a0, b0));\n}\n\nstatic char doc_matrixproduct[] = \\\n\t\"dot(a,v) returns matrix-multiplication between a and b. \\n\"\\\n\t\"The product-sum is over the last dimension of a and the \\n\"\\\n\t\"second-to-last dimension of b.\";\n\nstatic PyObject *array_matrixproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *v, *a;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a, &v)) return NULL;\n\t\n\treturn _ARET(PyArray_MatrixProduct(a, v));\n}\n\nstatic char doc_fastCopyAndTranspose[] = \"_fastCopyAndTranspose(a)\";\n\nstatic PyObject *array_fastCopyAndTranspose(PyObject *dummy, PyObject *args) {\n\tPyObject *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &a0)) return NULL;\n\t\n\treturn _ARET(PyArray_CopyAndTranspose(a0));\n}\n\nstatic char doc_correlate[] = \"cross_correlate(a,v, mode=0)\";\n\nstatic PyObject *array_correlate(PyObject *dummy, PyObject *args, PyObject *kwds) {\n\tPyObject *shape, *a0;\n\tint mode=0;\n\tstatic char *kwlist[] = {\"a\", \"v\", \"mode\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO|i\", kwlist, \n\t\t\t\t\t &a0, &shape, &mode)) return NULL;\n\t\n\treturn PyArray_Correlate(a0, shape, mode);\n}\n\n\n/*MULTIARRAY_API\n Arange, \n*/\nstatic PyObject *\nPyArray_Arange(double start, double stop, double step, int type_num)\n{\n\tintp length;\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *obj;\n\tint ret;\n\n\tlength = (intp ) ceil((stop - start)/step);\n \n\tif (length <= 0) {\n\t\tlength = 0;\n\t\treturn PyArray_New(&PyArray_Type, 1, &length, type_num,\n\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t}\n\n\trange = PyArray_New(&PyArray_Type, 1, &length, type_num, \n\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (range == NULL) return NULL;\n\n\tfuncs = PyArray_DESCR(range)->f; \n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tobj = PyFloat_FromDouble(start);\n\tret = funcs->setitem(obj, PyArray_DATA(range), (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 1) return range;\n\n\tobj = PyFloat_FromDouble(start + step);\n\tret = funcs->setitem(obj, PyArray_BYTES(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 2) return range;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\treturn NULL;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\t\n\treturn range;\n\n fail:\n\tPy_DECREF(range);\n\treturn NULL;\n}\n\n/* the formula is \n len = (intp) ceil((start - stop) / step);\n*/\nstatic intp\n_calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, int cmplx)\n{\n\tintp len;\n\tPyObject *val;\n\tdouble value;\n\t\n\t*next = PyNumber_Subtract(stop, start);\n\tif (!(*next)) return -1;\n\tval = PyNumber_TrueDivide(*next, step);\n\tPy_DECREF(*next); *next=NULL;\n\tif (!val) return -1;\n\tif (cmplx && PyComplex_Check(val)) {\n\t\tvalue = PyComplex_RealAsDouble(val);\n\t\tif (error_converting(value)) {Py_DECREF(val); return -1;}\n\t\tlen = (intp) ceil(value);\n\t\tvalue = PyComplex_ImagAsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = MIN(len, (intp) ceil(value));\n\t}\n\telse {\n\t\tvalue = PyFloat_AsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = (intp) ceil(value);\n\t}\n\t\n\tif (len > 0) {\n\t\t*next = PyNumber_Add(start, step);\n\t\tif (!next) return -1;\n\t}\n\treturn len;\n}\n\n/* this doesn't change the references */\n/*MULTIARRAY_API\n ArangeObj,\n*/\nstatic PyObject *\nPyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr *dtype) \n{\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *next;\n\tintp length;\n\n\tif (!dtype) {\n\t\tPyArray_Descr *deftype;\n\t\tPyArray_Descr *newtype;\n\t\tdeftype = PyArray_DescrFromType(PyArray_LONG);\n\t\tnewtype = PyArray_DescrFromObject(start, deftype);\n\t\tPy_DECREF(deftype);\n\t\tdeftype = newtype;\n\t\tif (stop && stop != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(stop, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tif (step && step != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(step, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tdtype = deftype;\n\t}\n\telse Py_INCREF(dtype);\n\n\tif (!step || step == Py_None) {\n\t\tstep = PyInt_FromLong(1);\n\t}\n\telse Py_XINCREF(step);\n\n\tif (!stop || stop == Py_None) {\n\t\tstop = start;\n\t\tstart = PyInt_FromLong(0);\n\t}\n\telse Py_INCREF(start);\n\n\t/* calculate the length and next = start + step*/\n\tlength = _calc_length(start, stop, step, &next, \n\t\t\t PyTypeNum_ISCOMPLEX(dtype->type_num));\n\n\tif (PyErr_Occurred()) {Py_DECREF(dtype); goto fail;}\n\tif (length <= 0) {\n\t\tlength = 0;\n\t\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\t\tPy_DECREF(step); Py_DECREF(start); return range;\n\t}\n\n\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\tif (range == NULL) goto fail;\n\n\tfuncs = PyArray_DESCR(range)->f;\n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tif (funcs->setitem(start, PyArray_DATA(range), (PyArrayObject *)range) < 0)\n\t\tgoto fail;\n\tif (length == 1) goto finish;\n\tif (funcs->setitem(next, PyArray_BYTES(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range) < 0) goto fail;\n\tif (length == 2) goto finish;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\tgoto fail;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\n finish:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_DECREF(next);\n\treturn range;\n\t\n fail:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_XDECREF(next);\n\treturn NULL;\n}\n\n\nstatic char doc_arange[] = \n\"arange([start,] stop[, step,], dtype=None)\\n\\n\"\n\"For integer arguments, just like range() except it returns an array whose type can\\n\"\n\"be specified by the keyword argument dtype.\\n\\n\"\n\"If dtype is not specified, the type of the result is deduced from the type of the\\n\"\n\"arguments.\\n\\n\"\n\"For floating point arguments, the length of the result is ceil((stop - start)/step).\\n\"\n\"This rule may result in the last element of the result be greater than stop.\";\n\nstatic PyObject *\narray_arange(PyObject *ignored, PyObject *args, PyObject *kws) {\n\tPyObject *o_start=NULL, *o_stop=NULL, *o_step=NULL;\n\tstatic char *kwd[]= {\"start\", \"stop\", \"step\", \"dtype\", NULL};\n\tPyArray_Descr *typecode=NULL;\n\t\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|OOO&\", kwd, &o_start,\n\t\t\t\t\t&o_stop, &o_step, \n\t\t\t\t\tPyArray_DescrConverter2,\n\t\t\t\t\t&typecode)) \n\t\treturn NULL;\n\n\treturn PyArray_ArangeObj(o_start, o_stop, o_step, typecode);\n}\n\n/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\n}\n\nstatic char \ndoc_set_string_function[] = \"set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.\";\n\nstatic PyObject *\narray_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *op;\n\tint repr=1;\n\tstatic char *kwlist[] = {\"f\", \"repr\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|i\", kwlist, \n\t\t\t\t\t&op, &repr)) return NULL; \n\tif (!PyCallable_Check(op)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"Argument must be callable.\");\n\t\treturn NULL;\n\t}\n\tPyArray_SetStringFunction(op, repr);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char \ndoc_set_ops_function[] = \"set_numeric_ops(op=func, ...) sets some or all of the number methods for all array objects. Don't forget **dict can be used as the argument list. Returns the functions that were replaced -- can be stored and set later.\";\n\nstatic PyObject *\narray_set_ops_function(PyObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *oldops=NULL;\n\t\n\tif ((oldops = PyArray_GetNumericOps())==NULL) return NULL;\n\n\t/* Should probably ensure that objects are at least callable */\n\t/* Leave this to the caller for now --- error will be raised\n\t later when use is attempted \n\t*/\n\tif (kwds && PyArray_SetNumericOps(kwds) == -1) {\n\t\tPy_DECREF(oldops);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"one or more objects not callable\");\n\t\treturn NULL;\n\t}\n\treturn oldops;\n}\n\n\n/*MULTIARRAY_API\n Where\n*/\nstatic PyObject *\nPyArray_Where(PyObject *condition, PyObject *x, PyObject *y)\n{\n\tPyArrayObject *arr;\n\tPyObject *tup=NULL, *obj=NULL;\n\tPyObject *ret=NULL, *zero=NULL;\n\n\n\tarr = (PyArrayObject *)PyArray_FromAny(condition, NULL, 0, 0, 0, NULL);\n\tif (arr == NULL) return NULL;\n\n\tif ((x==NULL) && (y==NULL)) {\n\t\tret = PyArray_Nonzero(arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\n\tif ((x==NULL) || (y==NULL)) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \"either both or neither \"\n\t\t\t\t\"of x and y should be given\");\n\t\treturn NULL;\n\t}\n\n\n\tzero = PyInt_FromLong((long) 0);\n\n\tobj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, \n\t\t\t\t\t\t\t\tn_ops.not_equal));\n\tPy_DECREF(zero);\n\tPy_DECREF(arr);\n\tif (obj == NULL) return NULL;\n\n\ttup = Py_BuildValue(\"(OO)\", y, x);\n\tif (tup == NULL) {Py_DECREF(obj); return NULL;}\n\n\tret = PyArray_Choose((PyAO *)obj, tup);\n\n\tPy_DECREF(obj);\n\tPy_DECREF(tup);\n\treturn ret;\n}\n\nstatic char doc_where[] = \"where(condition, | x, y) is shaped like condition\"\\\n\t\" and has elements of x and y where condition is respectively true or\"\\\n\t\" false. If x or y are not given, then it is equivalent to\"\\\n\t\" nonzero(condition).\";\n\nstatic PyObject *\narray_where(PyObject *ignored, PyObject *args)\n{\n\tPyObject *obj=NULL, *x=NULL, *y=NULL;\n\t\n\tif (!PyArg_ParseTuple(args, \"O|OO\", &obj, &x, &y)) return NULL;\n\n\treturn PyArray_Where(obj, x, y);\n\n}\n\nstatic char doc_lexsort[] = \"lexsort(keys=, axis=-1) returns an array of indexes\"\\\n\t\" similar to argsort except the sorting is done using the provided sorting\"\\\n\t\" keys. First the sort is done using key[0], then the resulting list of\"\\\n\t\" indexes is further manipulated by sorting on key[0]. And so forth\"\\\n\t\" The result is a sort on multiple keys. If the keys represented columns\" \\\n\t\" of a spread-sheet, for example, this would sort using multiple columns.\"\\\n\t\" The keys argument must be a tuple of things that can be converted to \"\\\n\t\" arrays of the same shape.\";\n\nstatic PyObject *\narray_lexsort(PyObject *ignored, PyObject *args, PyObject *kwds)\n{\n\tint axis=-1;\n\tPyObject *obj;\n\tstatic char *kwlist[] = {\"keys\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|i\", kwlist, \n\t\t\t\t\t &PyTuple_Type, &obj, &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_LexSort(obj, axis));\n}\n\n#undef _ARET\n\n\nstatic char doc_register_dtype[] = \\\n\t\"register_dtype(a) registers a new type object -- gives it a typenum\";\n\nstatic PyObject *\narray_register_dtype(PyObject *dummy, PyObject *args)\n{\n\tPyObject *dtype;\n\tint ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &dtype)) return NULL;\n\t\n\tret = PyArray_RegisterDataType((PyTypeObject *)dtype);\n\tif (ret < 0)\n\t\treturn NULL;\n\treturn PyInt_FromLong((long) ret);\n}\n\nstatic char doc_can_cast_safely[] = \\\n\t\"can_cast_safely(from=d1, to=d2) returns True if data type d1 \"\\\n\t\"can be cast to data type d2 without losing precision.\";\n\nstatic PyObject *\narray_can_cast_safely(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *d1=NULL;\n\tPyArray_Descr *d2=NULL;\n\tBool ret;\n\tPyObject *retobj;\n\tstatic char *kwlist[] = {\"from\", \"to\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O&O&\", kwlist, \n\t\t\t\t\tPyArray_DescrConverter, &d1,\n\t\t\t\t\tPyArray_DescrConverter, &d2))\n\t\treturn NULL;\n\tif (d1 == NULL || d2 == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"did not understand one of the types; \"\t\\\n\t\t\t\t\"'None' not accepted\");\n\t\treturn NULL;\n\t}\n\t\t\n\tret = PyArray_CanCastTo(d1, d2);\n\tretobj = (ret ? Py_True : Py_False);\n\tPy_INCREF(retobj);\n\treturn retobj;\n}\n\nstatic char doc_new_buffer[] = \\\n\t\"newbuffer(size) return a new uninitialized buffer object of size \"\n\t\"bytes\";\n\nstatic PyObject *\nnew_buffer(PyObject *dummy, PyObject *args)\n{\n\tint size;\n\n\tif(!PyArg_ParseTuple(args, \"i\", &size))\n\t\treturn NULL;\n\t\n\treturn PyBuffer_New(size);\n}\n\nstatic char doc_buffer_buffer[] = \\\n\t\"getbuffer(obj [,offset[, size]]) create a buffer object from the \"\\\n\t\"given object\\n referencing a slice of length size starting at \"\\\n\t\"offset. Default\\n is the entire buffer. A read-write buffer is \"\\\n\t\"attempted followed by a read-only buffer.\";\n\nstatic PyObject *\nbuffer_buffer(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj;\n\tint offset=0, size=Py_END_OF_BUFFER, n;\n\tvoid *unused;\n\tstatic char *kwlist[] = {\"object\", \"offset\", \"size\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ii\", kwlist, \n\t\t\t\t\t &obj, &offset, &size))\n\t\treturn NULL;\n\n\n\tif (PyObject_AsWriteBuffer(obj, &unused, &n) < 0) {\n\t\tPyErr_Clear();\n\t\treturn PyBuffer_FromObject(obj, offset, size);\t\t\n\t}\n\telse\n\t\treturn PyBuffer_FromReadWriteObject(obj, offset, size);\n}\n\n\nstatic struct PyMethodDef array_module_methods[] = {\n\t{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\n\t{\"set_string_function\", (PyCFunction)array_set_string_function, \n\t METH_VARARGS|METH_KEYWORDS, doc_set_string_function},\n\t{\"set_numeric_ops\", (PyCFunction)array_set_ops_function,\n\t METH_VARARGS|METH_KEYWORDS, doc_set_ops_function},\n\t{\"set_typeDict\", (PyCFunction)array_set_typeDict,\n\t METH_VARARGS, doc_set_typeDict},\n\n\t{\"array\",\t(PyCFunction)_array_fromobject, \n\t METH_VARARGS|METH_KEYWORDS, doc_fromobject},\n\t{\"arange\", (PyCFunction)array_arange, \n\t METH_VARARGS|METH_KEYWORDS, doc_arange},\n\t{\"zeros\",\t(PyCFunction)array_zeros, \n\t METH_VARARGS|METH_KEYWORDS, doc_zeros},\n\t{\"empty\",\t(PyCFunction)array_empty, \n\t METH_VARARGS|METH_KEYWORDS, doc_empty},\n\t{\"scalar\", (PyCFunction)array_scalar,\n\t METH_VARARGS|METH_KEYWORDS, doc_scalar},\n\t{\"where\", (PyCFunction)array_where,\n\t METH_VARARGS, doc_where},\n\t{\"lexsort\", (PyCFunction)array_lexsort,\n\t METH_VARARGS | METH_KEYWORDS, doc_lexsort},\n\t{\"fromstring\",(PyCFunction)array_fromString,\n\t METH_VARARGS|METH_KEYWORDS, doc_fromString},\n\t{\"concatenate\", (PyCFunction)array_concatenate, \n\t METH_VARARGS|METH_KEYWORDS, doc_concatenate},\n\t{\"inner\", (PyCFunction)array_innerproduct, \n\t METH_VARARGS, doc_innerproduct}, \n\t{\"dot\", (PyCFunction)array_matrixproduct, \n\t METH_VARARGS, doc_matrixproduct}, \n\t{\"_fastCopyAndTranspose\", (PyCFunction)array_fastCopyAndTranspose, \n\t METH_VARARGS, doc_fastCopyAndTranspose},\n\t{\"correlate\", (PyCFunction)array_correlate, \n\t METH_VARARGS | METH_KEYWORDS, doc_correlate},\n\t{\"frombuffer\", (PyCFunction)array_frombuffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_frombuffer},\n\t{\"fromfile\", (PyCFunction)array_fromfile,\n\t METH_VARARGS | METH_KEYWORDS, doc_fromfile},\n\t{\"register_dtype\", (PyCFunction)array_register_dtype,\n\t METH_VARARGS, doc_register_dtype},\n\t{\"can_cast\", (PyCFunction)array_can_cast_safely,\n\t METH_VARARGS | METH_KEYWORDS, doc_can_cast_safely},\t\t\n\t{\"newbuffer\", (PyCFunction)new_buffer,\n\t METH_VARARGS, doc_new_buffer},\t\n\t{\"getbuffer\", (PyCFunction)buffer_buffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_buffer_buffer},\t\n\t{NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n#include \"__multiarray_api.c\"\n\n/* Establish scalar-type hierarchy */\n\n/* For dual inheritance we need to make sure that the objects being\n inherited from have the tp->mro object initialized. This is\n not necessarily true for the basic type objects of Python (it is \n checked for single inheritance but not dual in PyType_Ready).\n\n Thus, we call PyType_Ready on the standard Python Types, here.\n*/ \nstatic int\nsetup_scalartypes(PyObject *dict)\n{\n\n\tinitialize_numeric_types();\n\n if (PyType_Ready(&PyBool_Type) < 0) return -1;\n if (PyType_Ready(&PyInt_Type) < 0) return -1;\n if (PyType_Ready(&PyFloat_Type) < 0) return -1;\n if (PyType_Ready(&PyComplex_Type) < 0) return -1;\n if (PyType_Ready(&PyString_Type) < 0) return -1;\n if (PyType_Ready(&PyUnicode_Type) < 0) return -1;\n\n#define SINGLE_INHERIT(child, parent) \\\n Py##child##ArrType_Type.tp_base = &Py##parent##ArrType_Type;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) {\t\t\\\n PyErr_Print(); \\\n PyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1;\t\t\t\t\t\t\\\n }\n \n if (PyType_Ready(&PyGenericArrType_Type) < 0)\n return -1;\n\n SINGLE_INHERIT(Number, Generic);\n SINGLE_INHERIT(Integer, Number);\n SINGLE_INHERIT(Inexact, Number);\n SINGLE_INHERIT(SignedInteger, Integer);\n SINGLE_INHERIT(UnsignedInteger, Integer);\n SINGLE_INHERIT(Floating, Inexact);\n SINGLE_INHERIT(ComplexFloating, Inexact);\n SINGLE_INHERIT(Flexible, Generic);\n SINGLE_INHERIT(Character, Flexible);\n\t\n#define DUAL_INHERIT(child, parent1, parent2) \\\n Py##child##ArrType_Type.tp_base = &Py##parent2##ArrType_Type;\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent2##ArrType_Type,\t\\\n\t\t\t &Py##parent1##_Type);\t\t\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\n\n#define DUAL_INHERIT2(child, parent1, parent2)\t\t\t\t\\\n Py##child##ArrType_Type.tp_base = &Py##parent1##_Type;\t\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent1##_Type,\t\t\\\n\t\t\t &Py##parent2##ArrType_Type);\t\t\\\n\tPy##child##ArrType_Type.tp_richcompare =\t\t\t\\\n\t\tPy##parent1##_Type.tp_richcompare;\t\t\t\\\n\tPy##child##ArrType_Type.tp_compare =\t\t\t\t\\\n\t\tPy##parent1##_Type.tp_compare;\t\t\t\t\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\n\n SINGLE_INHERIT(Bool, Generic);\n SINGLE_INHERIT(Byte, SignedInteger);\n SINGLE_INHERIT(Short, SignedInteger);\n#if SIZEOF_INT == SIZEOF_LONG\n DUAL_INHERIT(Int, Int, SignedInteger);\n#else\n SINGLE_INHERIT(Int, SignedInteger);\n#endif\n DUAL_INHERIT(Long, Int, SignedInteger);\n#if SIZEOF_LONGLONG == SIZEOF_LONG\n DUAL_INHERIT(LongLong, Int, SignedInteger);\n#else\n SINGLE_INHERIT(LongLong, SignedInteger);\n#endif\n\n /* fprintf(stderr, \"tp_free = %p, PyObject_Del = %p, int_tp_free = %p, base.tp_free = %p\\n\", PyIntArrType_Type.tp_free, PyObject_Del, PyInt_Type.tp_free, PySignedIntegerArrType_Type.tp_free);\n\t */\n\tSINGLE_INHERIT(UByte, UnsignedInteger);\n SINGLE_INHERIT(UShort, UnsignedInteger);\n SINGLE_INHERIT(UInt, UnsignedInteger);\n SINGLE_INHERIT(ULong, UnsignedInteger);\n SINGLE_INHERIT(ULongLong, UnsignedInteger);\n\n SINGLE_INHERIT(Float, Floating);\n DUAL_INHERIT(Double, Float, Floating);\n SINGLE_INHERIT(LongDouble, Floating);\n\n SINGLE_INHERIT(CFloat, ComplexFloating);\n DUAL_INHERIT(CDouble, Complex, ComplexFloating);\n SINGLE_INHERIT(CLongDouble, ComplexFloating);\n\n DUAL_INHERIT2(String, String, Character);\n DUAL_INHERIT2(Unicode, Unicode, Character);\n\t\n SINGLE_INHERIT(Void, Flexible);\n \n SINGLE_INHERIT(Object, Generic);\n\n return 0;\n\n#undef SINGLE_INHERIT\n#undef DUAL_INHERIT\n\n\t/* Clean up string and unicode array types so they act more like\n\t strings -- get their tables from the standard types.\n\t*/\n}\n\n/* place a flag dictionary in d */\n\nstatic void\nset_flaginfo(PyObject *d)\n{\n PyObject *s;\n PyObject *newd;\n \n newd = PyDict_New();\n\n PyDict_SetItemString(newd, \"OWNDATA\", s=PyInt_FromLong(OWNDATA));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"FORTRAN\", s=PyInt_FromLong(FORTRAN));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"CONTIGUOUS\", s=PyInt_FromLong(CONTIGUOUS));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"ALIGNED\", s=PyInt_FromLong(ALIGNED));\n Py_DECREF(s);\n\n PyDict_SetItemString(newd, \"UPDATEIFCOPY\", s=PyInt_FromLong(UPDATEIFCOPY));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"WRITEABLE\", s=PyInt_FromLong(WRITEABLE));\n Py_DECREF(s);\n \n PyDict_SetItemString(d, \"_flagdict\", newd);\n Py_DECREF(newd);\n return;\n}\n\n\n/* Initialization function for the module */\n\nDL_EXPORT(void) initmultiarray(void) {\n\tPyObject *m, *d, *s;\n\tPyObject *c_api;\n\n\tif (_multiarray_module_loaded) return;\n\t_multiarray_module_loaded = 1;\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\tif (PyType_Ready(&PyArray_Type) < 0)\n return;\n\n if (setup_scalartypes(d) < 0) goto err;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMultiIter_Type.tp_iter = PyObject_SelfIter;\n\tif (PyType_Ready(&PyArrayIter_Type) < 0)\n\t\treturn; \n \n\tif (PyType_Ready(&PyArrayMapIter_Type) < 0)\n return; \n\n\tif (PyType_Ready(&PyArrayMultiIter_Type) < 0)\n\t\treturn;\n\n\tif (PyType_Ready(&PyArrayDescr_Type) < 0)\n\t\treturn;\n\n\tif (PyType_Ready(&PyArrayFlags_Type) < 0)\n\t\treturn;\n\n\tc_api = PyCObject_FromVoidPtr((void *)PyArray_API, NULL);\n\tif (PyErr_Occurred()) goto err;\n\tPyDict_SetItemString(d, \"_ARRAY_API\", c_api);\n\tPy_DECREF(c_api);\n\tif (PyErr_Occurred()) goto err;\n\n\tMultiArrayError = PyString_FromString (\"multiarray.error\");\n\tPyDict_SetItemString (d, \"error\", MultiArrayError);\n\t\n\ts = PyString_FromString(\"3.0\");\n\tPyDict_SetItemString(d, \"__version__\", s);\n\tPy_DECREF(s);\n Py_INCREF(&PyArray_Type);\n\tPyDict_SetItemString(d, \"ndarray\", (PyObject *)&PyArray_Type);\n Py_INCREF(&PyArrayIter_Type);\n\tPyDict_SetItemString(d, \"flatiter\", (PyObject *)&PyArrayIter_Type);\n Py_INCREF(&PyArrayMultiIter_Type);\n\tPyDict_SetItemString(d, \"broadcast\", \n\t\t\t (PyObject *)&PyArrayMultiIter_Type);\n\tPy_INCREF(&PyArrayDescr_Type);\n\tPyDict_SetItemString(d, \"dtype\", (PyObject *)&PyArrayDescr_Type);\n\n\tPy_INCREF(&PyArrayFlags_Type);\n\tPyDict_SetItemString(d, \"flagsobj\", (PyObject *)&PyArrayFlags_Type);\n\n set_flaginfo(d);\n\n\tif (set_typeinfo(d) != 0) goto err;\n\n\t_numpy_internal =\t\t\t\t\t\t\\\n\t\tPyImport_ImportModule(\"numpy.core._internal\");\n\tif (_numpy_internal != NULL) return;\n\n err:\t\n\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\n\treturn;\n}\n\n", + "source_code_before": "/*\n Python Multiarray Module -- A useful collection of functions for creating and\n using ndarrays\n\n Original file \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n Modified extensively for numpy in 2005 \n\n Travis E. Oliphant\n Assistant Professor at\n Brigham Young University\n \n*/\n\n/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */\n\n#include \"Python.h\"\n#include \"structmember.h\"\n/*#include \n#include \n*/\n\n#define _MULTIARRAYMODULE\n#include \"numpy/arrayobject.h\"\n\n#define PyAO PyArrayObject\n\nstatic PyObject *typeDict=NULL; /* Must be explicitly loaded */\nstatic PyObject *_numpy_internal=NULL; /* A Python module for callbacks */\nstatic int _multiarray_module_loaded=0;\n\nstatic PyArray_Descr *\n_arraydescr_fromobj(PyObject *obj)\n{\n\tPyObject *dtypedescr;\n\tPyArray_Descr *new;\n\tint ret;\n\t\n\tdtypedescr = PyObject_GetAttrString(obj, \"dtype\");\n\tPyErr_Clear();\n\tif (dtypedescr) {\n\t\tret = PyArray_DescrConverter(dtypedescr, &new);\n\t\tPy_DECREF(dtypedescr);\n\t\tif (ret) return new;\n\t\tPyErr_Clear();\n\t}\n\treturn NULL;\n}\n\n\n/* Including this file is the only way I know how to declare functions\n static in each file, and store the pointers from functions in both\n arrayobject.c and multiarraymodule.c for the C-API \n\n Declarying an external pointer-containing variable in arrayobject.c\n and trying to copy it to PyArray_API, did not work.\n\n Think about two modules with a common api that import each other...\n\n This file would just be the module calls. \n*/\n\n#include \"arrayobject.c\"\n\n\n/* An Error object -- rarely used? */\nstatic PyObject *MultiArrayError;\n\n/*MULTIARRAY_API\n Multiply a List of ints\n*/\nstatic int\nPyArray_MultiplyIntList(register int *l1, register int n) \n{\n\tregister int s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Multiply a List\n*/\nstatic intp \nPyArray_MultiplyList(register intp *l1, register int n) \n{\n\tregister intp s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Produce a pointer into array\n*/\nstatic void *\nPyArray_GetPtr(PyArrayObject *obj, register intp* ind)\n{\n\tregister int n = obj->nd;\n\tregister intp *strides = obj->strides;\n\tregister char *dptr = obj->data;\n\t\n\twhile (n--) dptr += (*strides++) * (*ind++);\n\treturn (void *)dptr;\n}\n\n/*MULTIARRAY_API\n Get axis from an object (possibly None) -- a converter function,\n*/\nstatic int \nPyArray_AxisConverter(PyObject *obj, int *axis)\n{\n\tif (obj == Py_None) {\n\t\t*axis = MAX_DIMS;\n\t}\n\telse {\n\t\t*axis = (int) PyInt_AsLong(obj);\n\t\tif (PyErr_Occurred()) {\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Compare Lists\n*/\nstatic int \nPyArray_CompareLists(intp *l1, intp *l2, int n) \n{\n int i;\n for(i=0;iob_type;\n\t\n\tPy_INCREF(self->descr);\n\tnew = PyArray_NewFromDescr(subtype,\n\t\t\t\t self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides,\n\t\t\t\t self->data,\n\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (new==NULL) return NULL;\n\tPy_INCREF(self);\n PyArray_BASE(new) = (PyObject *)self;\n\t\n\tif (type != NULL) {\n\t\tif (PyObject_SetAttrString(new, \"dtype\",\n\t\t\t\t\t (PyObject *)type) < 0) {\n\t\t\tPy_DECREF(new);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tPy_DECREF(type);\n\t}\n\treturn new;\t\n}\n\n/*MULTIARRAY_API\n Ravel\n*/\nstatic PyObject *\nPyArray_Ravel(PyArrayObject *a, int fortran)\n{\n\tPyArray_Dims newdim = {NULL,1};\n\tintp val[1] = {-1};\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tnewdim.ptr = val;\n\tif (!fortran && PyArray_ISCONTIGUOUS(a)) {\n\t\tif (a->nd == 1) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\treturn PyArray_Newshape(a, &newdim);\n\t}\n\telse\n\t return PyArray_Flatten(a, fortran);\n}\n\nstatic double\npower_of_ten(int n)\n{\n\tstatic const double p10[] = {1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8};\n\tdouble ret;\n\tif (n < 9)\n\t\tret = p10[n];\n\telse {\n\t\tret = 1e9;\n\t\twhile (n-- > 9)\n\t\t\tret *= 10.;\n\t}\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Round\n*/\nstatic PyObject *\nPyArray_Round(PyArrayObject *a, int decimals)\n{\n\tif (PyArray_ISCOMPLEX(a)) {\n\t\tPyObject *part;\n\t\tPyObject *round_part;\n\t\tPyObject *new;\n\t\tint res;\n\t\tnew = PyArray_Copy(a);\n\t\tif (new == NULL) return NULL;\n\n\t\t/* new.real = a.real.round(decimals) */\n\t\tpart = PyObject_GetAttrString(new, \"real\");\n\t\tif (part == NULL) {Py_DECREF(new); return NULL;}\n\t\tround_part = PyArray_Round\\\n\t\t\t((PyArrayObject *)PyArray_EnsureAnyArray(part), \n\t\t\t decimals);\n\t\tPy_DECREF(part);\n\t\tif (round_part == NULL) {Py_DECREF(new); return NULL;}\n\t\tres = PyObject_SetAttrString(new, \"real\", round_part);\n\t\tPy_DECREF(round_part);\n\t\tif (res < 0) {Py_DECREF(new); return NULL;}\n\n\t\t/* new.imag = a.imag.round(decimals) */\n\t\tpart = PyObject_GetAttrString(new, \"imag\");\n\t\tif (part == NULL) {Py_DECREF(new); return NULL;}\n\t\tround_part = PyArray_Round\\\n\t\t\t((PyArrayObject *)PyArray_EnsureAnyArray(part), \n\t\t\t decimals);\n\t\tPy_DECREF(part);\n\t\tif (round_part == NULL) {Py_DECREF(new); return NULL;}\n\t\tres = PyObject_SetAttrString(new, \"imag\", round_part);\n\t\tPy_DECREF(round_part);\n\t\tif (res < 0) {Py_DECREF(new); return NULL;}\n\t\treturn new;\n\t}\n\t/* do the most common case first */\n\tif (decimals == 0) {\n\t\tif (PyArray_ISINTEGER(a)) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\treturn PyArray_GenericUnaryFunction((PyAO *)a, n_ops.rint);\n\t}\n\tif (decimals > 0) {\n\t\tPyObject *f, *ret;\n\t\tif (PyArray_ISINTEGER(a)) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\tf = PyFloat_FromDouble(power_of_ten(decimals));\n\t\tif (f==NULL) return NULL;\n\t\tret = PyNumber_Multiply((PyObject *)a, f);\n\t\tif (ret==NULL) {Py_DECREF(f); return NULL;}\n\t\tif (PyArray_IsScalar(ret, Generic)) {\n\t\t\t/* array scalars cannot be modified inplace */\n\t\t\tPyObject *tmp;\n\t\t\ttmp = PyObject_CallFunction(n_ops.rint, \"O\", ret);\n\t\t\tPy_DECREF(ret);\n\t\t\tret = PyObject_CallFunction(n_ops.divide, \"OO\", \n\t\t\t\t\t\t tmp, f);\n\t\t\tPy_DECREF(tmp);\n\t\t} else {\n\t\t\tPyObject_CallFunction(n_ops.rint, \"OO\", ret, ret);\n\t\t\tPyObject_CallFunction(n_ops.divide, \"OOO\", ret, \n\t\t\t\t\t f, ret);\n\t\t}\n\t\tPy_DECREF(f);\n\t\treturn ret;\n\t} \n\telse {\n\t\t/* remaining case: decimals < 0 */\n\t\tPyObject *f, *ret;\n\t\tf = PyFloat_FromDouble(power_of_ten(-decimals));\n\t\tif (f==NULL) return NULL;\n\t\tret = PyNumber_Divide((PyObject *)a, f);\n\t\tif (ret==NULL) {Py_DECREF(f); return NULL;}\n\t\tif (PyArray_IsScalar(ret, Generic)) {\n\t\t\t/* array scalars cannot be modified inplace */\n\t\t\tPyObject *tmp;\n\t\t\ttmp = PyObject_CallFunction(n_ops.rint, \"O\", ret);\n\t\t\tPy_DECREF(ret);\n\t\t\tret = PyObject_CallFunction(n_ops.multiply, \"OO\", \n\t\t\t\t\t\t tmp, f);\n\t\t\tPy_DECREF(tmp);\n\t\t} else {\n\t\t\tPyObject_CallFunction(n_ops.rint, \"OO\", ret, ret);\n\t\t\tPyObject_CallFunction(n_ops.multiply, \"OOO\", ret, \n\t\t\t\t\t f, ret);\n\t\t}\n\t\tPy_DECREF(f);\n\t\treturn ret;\n\t}\n}\n\n\n/*MULTIARRAY_API\n Flatten\n*/\nstatic PyObject *\nPyArray_Flatten(PyArrayObject *a, int fortran)\n{\n\tPyObject *ret, *new;\n\tintp size;\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tsize = PyArray_SIZE(a);\n\tPy_INCREF(a->descr);\n\tret = PyArray_NewFromDescr(a->ob_type,\n\t\t\t\t a->descr,\n\t\t\t\t 1, &size,\n\t\t\t\t NULL,\n\t\t\t\t NULL,\n\t\t\t\t 0, (PyObject *)a);\n\t\n\tif (ret== NULL) return NULL;\n\tif (fortran) {\n\t\tnew = PyArray_Transpose(a, NULL);\n\t\tif (new == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tPy_INCREF(a);\n\t\tnew = (PyObject *)a;\n\t}\n\tif (PyArray_CopyInto((PyArrayObject *)ret, (PyArrayObject *)new) < 0) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn NULL;\n\t}\n\tPy_DECREF(new);\n\treturn ret;\n}\n\n\n/* For back-ward compatability *\n\n/ * Not recommended */\n\n/*MULTIARRAY_API\n Reshape an array\n*/\nstatic PyObject *\nPyArray_Reshape(PyArrayObject *self, PyObject *shape) \n{\n PyObject *ret;\n PyArray_Dims newdims;\n\n if (!PyArray_IntpConverter(shape, &newdims)) return NULL;\n ret = PyArray_Newshape(self, &newdims);\n PyDimMem_FREE(newdims.ptr);\n return ret;\n}\n\nstatic int\n_check_ones(PyArrayObject *self, int newnd, intp* newdims, intp *strides)\n{\n\tint nd;\n\tintp *dims;\n\tBool done=FALSE;\n\tint j, k;\n\n\tnd = self->nd;\n\tdims = self->dimensions;\n\n\tfor (k=0, j=0; !done && (jstrides[j];\n\t\t\tj++; k++;\n\t\t}\n\t\telse if ((kptr;\n PyArrayObject *ret;\n\tchar msg[] = \"total size of new array must be unchanged\";\n\tint n = newdims->len;\n Bool same;\n\tintp *strides = NULL;\n\tintp newstrides[MAX_DIMS];\n\n /* Quick check to make sure anything needs to be done */\n if (n == self->nd) {\n same = TRUE;\n i=0;\n while(same && i= 0) {\n\t\t\tif ((s_known == 0) || (s_original % s_known != 0)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdimensions[i_unknown] = s_original/s_known;\n\t\t} else {\n\t\t\tif (s_original != s_known) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t}\n \n\tPy_INCREF(self->descr);\n\tret = (PyAO *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t self->descr,\n\t\t\t\t\t n, dimensions,\n\t\t\t\t\t strides,\n\t\t\t\t\t self->data,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (ret== NULL) return NULL;\n\t\n Py_INCREF(self);\n ret->base = (PyObject *)self;\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\n\t\n return (PyObject *)ret;\n}\n\n/* return a new view of the array object with all of its unit-length \n dimensions squeezed out if needed, otherwise\n return the same array.\n */\n\n/*MULTIARRAY_API*/\nstatic PyObject *\nPyArray_Squeeze(PyArrayObject *self)\n{\n\tint nd = self->nd;\n\tint newnd = nd;\n\tintp dimensions[MAX_DIMS];\n\tintp strides[MAX_DIMS];\n\tint i,j;\n\tPyObject *ret;\n\n\tif (nd == 0) {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\tfor (j=0, i=0; idimensions[i] == 1) {\n\t\t\tnewnd -= 1;\n\t\t}\n\t\telse {\n\t\t\tdimensions[j] = self->dimensions[i];\n\t\t\tstrides[j++] = self->strides[i];\n\t\t}\n\t}\n\t\n\tPy_INCREF(self->descr);\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t self->descr,\n\t\t\t\t newnd, dimensions, \n\t\t\t\t strides, self->data, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPyArray_FLAGS(ret) &= ~OWN_DATA;\n\tPyArray_BASE(ret) = (PyObject *)self;\n\tPy_INCREF(self);\n\treturn (PyObject *)ret;\n}\n\n\n/*MULTIARRAY_API\n Mean\n*/\nstatic PyObject *\nPyArray_Mean(PyArrayObject *self, int axis, int rtype)\n{\n\tPyObject *obj1=NULL, *obj2=NULL;\n\tPyObject *new, *ret;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\n\tobj1 = PyArray_GenericReduceFunction((PyAO *)new, n_ops.add, axis,\n\t\t\t\t\t rtype);\n\tobj2 = PyFloat_FromDouble((double) PyArray_DIM(new,axis));\n Py_DECREF(new);\n\tif (obj1 == NULL || obj2 == NULL) {\n\t\tPy_XDECREF(obj1);\n\t\tPy_XDECREF(obj2);\n\t\treturn NULL;\n\t}\n\n\tret = PyNumber_Divide(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n}\n\n/* Set variance to 1 to by-pass square-root calculation and return variance */\n/*MULTIARRAY_API\n Std\n*/\nstatic PyObject *\nPyArray_Std(PyArrayObject *self, int axis, int rtype, int variance)\n{\n\tPyObject *obj1=NULL, *obj2=NULL, *new=NULL;\n\tPyObject *ret=NULL, *newshape=NULL;\n\tint i, n;\n\tintp val;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\t\n\t/* Compute and reshape mean */\n\tobj1 = PyArray_EnsureArray(PyArray_Mean((PyAO *)new, axis, rtype));\n\tif (obj1 == NULL) {Py_DECREF(new); return NULL;} \n\tn = PyArray_NDIM(new);\n\tnewshape = PyTuple_New(n);\n\tif (newshape == NULL) {Py_DECREF(obj1); Py_DECREF(new); return NULL;}\n\tfor (i=0; ind != 1) {\n Py_DECREF(cond);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"condition must be 1-d array\");\n return NULL;\n }\n\n res = PyArray_Nonzero(cond);\n Py_DECREF(cond);\n\tret = PyArray_Take(self, res, axis);\n\tPy_DECREF(res);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Nonzero\n*/\nstatic PyObject *\nPyArray_Nonzero(PyArrayObject *self)\n{\n int n=self->nd, j;\n\tintp count=0, i, size;\n\tPyArrayIterObject *it=NULL;\n\tPyObject *ret=NULL, *item;\n\tintp *dptr[MAX_DIMS];\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (it==NULL) return NULL;\n\n\tsize = it->size;\n\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) count++;\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\n\tPyArray_ITER_RESET(it);\n\tif (n==1) {\n\t\tret = PyArray_New(self->ob_type, 1, &count, PyArray_INTP, \n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)self);\n\t\tif (ret == NULL) goto fail;\n\t\tdptr[0] = (intp *)PyArray_DATA(ret);\n\t\t\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\t*(dptr[0])++ = i;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\t\t\n\t}\n\telse {\n\t\tret = PyTuple_New(n);\n\t\tfor (j=0; job_type, 1, &count, \n\t\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0,\n\t\t\t\t\t (PyObject *)self);\n\t\t\tif (item == NULL) goto fail;\n\t\t\tPyTuple_SET_ITEM(ret, j, item);\n\t\t\tdptr[j] = (intp *)PyArray_DATA(item);\n\t\t}\n\t\t\n\t\t/* reset contiguous so that coordinates gets updated */\n\t\tit->contiguous = 0;\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\tfor (j=0; jcoordinates[j];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\n\n\tPy_DECREF(it);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(ret);\n\tPy_XDECREF(it);\n\treturn NULL;\n \n}\n\n/*MULTIARRAY_API\n Clip\n*/\nstatic PyObject *\nPyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max)\n{\n\tPyObject *selector=NULL, *newtup=NULL, *ret=NULL;\n\tPyObject *res1=NULL, *res2=NULL, *res3=NULL;\n\tPyObject *two;\n\n\ttwo = PyInt_FromLong((long)2);\n\tres1 = PyArray_GenericBinaryFunction(self, max, n_ops.greater);\n\tres2 = PyArray_GenericBinaryFunction(self, min, n_ops.less);\n\tif ((res1 == NULL) || (res2 == NULL)) {\n\t\tPy_DECREF(two);\n\t\tPy_XDECREF(res1);\n\t\tPy_XDECREF(res2);\n\t}\n\tres3 = PyNumber_Multiply(two, res1);\n\tPy_DECREF(two); \n\tPy_DECREF(res1); \n\tif (res3 == NULL) return NULL;\n\n\tselector = PyArray_EnsureArray(PyNumber_Add(res2, res3));\n\tPy_DECREF(res2);\n\tPy_DECREF(res3);\n\tif (selector == NULL) return NULL;\n\n\tnewtup = Py_BuildValue(\"(OOO)\", (PyObject *)self, min, max);\n\tif (newtup == NULL) {Py_DECREF(selector); return NULL;}\n\tret = PyArray_Choose((PyAO *)selector, newtup);\n\tPy_DECREF(selector);\n\tPy_DECREF(newtup);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Conjugate\n*/\nstatic PyObject *\nPyArray_Conjugate(PyArrayObject *self)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyObject *new;\n\t\tintp size, i;\n\t\t/* Make a copy */\n\t\tnew = PyArray_NewCopy(self, -1);\n\t\tif (new==NULL) return NULL;\n\t\tsize = PyArray_SIZE(new);\n\t\tif (self->descr->type_num == PyArray_CFLOAT) {\n\t\t\tcfloat *dptr = (cfloat *) PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CDOUBLE) {\n\t\t\tcdouble *dptr = (cdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CLONGDOUBLE) {\n\t\t\tclongdouble *dptr = (clongdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\t\t\t\n\t\t}\t\t\n\t\treturn new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *) self;\n\t}\n}\n\n/*MULTIARRAY_API\n Trace\n*/\nstatic PyObject *\nPyArray_Trace(PyArrayObject *self, int offset, int axis1, int axis2, \nint rtype)\n{\n\tPyObject *diag=NULL, *ret=NULL;\n\n\tdiag = PyArray_Diagonal(self, offset, axis1, axis2);\n\tif (diag == NULL) return NULL;\n\tret = PyArray_GenericReduceFunction((PyAO *)diag, n_ops.add, -1, rtype);\n\tPy_DECREF(diag);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Diagonal\n*/\nstatic PyObject *\nPyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)\n{\n\tint n = self->nd;\n\tPyObject *new;\n\tPyArray_Dims newaxes;\n\tintp dims[MAX_DIMS];\n\tint i, pos;\t\n\n\tnewaxes.ptr = dims;\n\tif (n < 2) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"array.ndim must be >= 2\");\n\t\treturn NULL;\n\t}\n\tif (axis1 < 0) axis1 += n;\n\tif (axis2 < 0) axis2 += n;\n\tif ((axis1 == axis2) || (axis1 < 0) || (axis1 >= n) ||\t\\\n\t (axis2 < 0) || (axis2 >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \"axis1(=%d) and axis2(=%d) \"\\\n\t\t\t \"must be different and within range (nd=%d)\",\n\t\t\t axis1, axis2, n);\n\t\treturn NULL;\n\t}\n \n\tnewaxes.len = n;\n\t/* insert at the end */\n\tnewaxes.ptr[n-2] = axis1;\n\tnewaxes.ptr[n-1] = axis2;\n\tpos = 0;\n\tfor (i=0; idimensions[0];\n\t\tn2 = self->dimensions[1];\n\t\tstep = n2+1;\n\t\tif (offset < 0) {\n\t\t\tstart = -n2 * offset;\n\t\t\tstop = MIN(n2, n1+offset)*(n2+1) - n2*offset;\n\t\t}\n\t\telse {\n\t\t\tstart = offset;\n\t\t\tstop = MIN(n1, n2-offset)*(n2+1) + offset;\n\t\t}\n\t\t\n\t\t/* count = ceil((stop-start)/step) */\n\t\tcount = ((stop-start) / step) + (((stop-start) % step) != 0);\n\t\t\t\n\t\tindices = PyArray_New(&PyArray_Type, 1, &count, \n\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0, NULL);\n\t\tif (indices == NULL) {\n\t\t\tPy_DECREF(self); return NULL;\n\t\t}\n\t\tdptr = (intp *)PyArray_DATA(indices);\n\t\tfor (n1=start; n1descr;\n\n\t\tmydiagonal = PyList_New(0);\n\t\tif (mydiagonal == NULL) {Py_DECREF(self); return NULL;}\n\t\tn1 = self->dimensions[0];\n\t\tfor (i=0; i 3)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"C arrays of only 1-3 dimensions available\");\n\t\tPy_XDECREF(typedescr);\n\t\treturn -1;\n\t}\n\tif ((ap = (PyArrayObject*)PyArray_FromAny(*op, typedescr, nd, nd,\n\t\t\t\t\t\t CARRAY_FLAGS, NULL)) == NULL)\n\t\treturn -1;\n\tswitch(nd) {\n\tcase 1:\n\t\t*((char **)ptr) = ap->data;\n\t\tbreak;\n\tcase 2:\n\t\tn = ap->dimensions[0];\n\t\tptr2 = (char **)_pya_malloc(n * sizeof(char *));\n\t\tif (!ptr2) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0];\n\t\t}\n\t\t*((char ***)ptr) = ptr2;\n\t\tbreak;\t\t\n\tcase 3:\n\t\tn = ap->dimensions[0];\n\t\tm = ap->dimensions[1];\n\t\tptr3 = (char ***)_pya_malloc(n*(m+1) * sizeof(char *));\n\t\tif (!ptr3) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0] + \\\n\t\t\t\t\tj*ap->strides[1];\n\t\t\t}\n\t\t}\n\t\t*((char ****)ptr) = ptr3;\n\t}\n\tmemcpy(dims, ap->dimensions, nd*sizeof(intp));\n\t*op = (PyObject *)ap;\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_MemoryError, \"no memory\");\n\treturn -1;\n}\n\n/* Deprecated --- Use PyArray_AsCArray instead */\n\n/*MULTIARRAY_API\n Convert to a 1D C-array\n*/\nstatic int \nPyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) \n{\n\tintp newd1;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, descr) == -1)\n\t\treturn -1;\t\n\t*d1 = (int) newd1;\n\treturn 0;\n}\n\n/*MULTIARRAY_API\n Convert to a 2D C-array\n*/\nstatic int \nPyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) \n{\n\tintp newdims[2];\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, newdims, 2, descr) == -1)\n\t\treturn -1;\n\n\t*d1 = (int ) newdims[0];\n\t*d2 = (int ) newdims[1];\n return 0;\n}\n\n/* End Deprecated */\n\n/*MULTIARRAY_API\n Free pointers created if As2D is called\n*/\nstatic int \nPyArray_Free(PyObject *op, void *ptr) \n{\n PyArrayObject *ap = (PyArrayObject *)op;\n\t\n if ((ap->nd < 1) || (ap->nd > 3)) \n\t\treturn -1;\n if (ap->nd >= 2) {\n\t\t_pya_free(ptr);\n }\n Py_DECREF(ap);\n return 0;\n}\n\n\nstatic PyObject *\n_swap_and_concat(PyObject *op, int axis, int n)\n{\n\tPyObject *newtup=NULL;\n\tPyObject *otmp, *arr;\n\tint i;\n\n\tnewtup = PyTuple_New(n);\n\tif (newtup==NULL) return NULL;\n\tfor (i=0; i= MAX_DIMS) {\n\t\t\totmp = PyArray_Ravel(mps[i],0);\n\t\t\tPy_DECREF(mps[i]);\n\t\t\tmps[i] = (PyArrayObject *)otmp;\n\t\t}\n\t\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\n\t\t}\n\t}\n\t\n\tnew_dim = 0;\n\tfor(i=0; ind;\n\t\telse {\n\t\t\tif (nd != mps[i]->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"arrays must have same \"\\\n\t\t\t\t\t\t\"number of dimensions\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CompareLists(mps[0]->dimensions+1, \n\t\t\t\t\t\t mps[i]->dimensions+1, \n\t\t\t\t\t\t nd-1)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"array dimensions must \"\\\n\t\t\t\t\t\t\"agree except for d_0\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (nd == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"0-d arrays can't be concatenated\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnew_dim += mps[i]->dimensions[0];\n\t}\n\t\n\ttmp = mps[0]->dimensions[0];\n\tmps[0]->dimensions[0] = new_dim;\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(subtype, \n\t\t\t\t\t\t mps[0]->descr, nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ret);\n\tmps[0]->dimensions[0] = tmp;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tdata = ret->data;\n\tfor(i=0; idata, numbytes);\n\t\tdata += numbytes;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; ind;\n\tif (n <= 1) {\n\t\tPy_INCREF(ap);\n\t\treturn (PyObject *)ap;\n\t}\n\n\tif (a1 < 0) a1 += n;\n\tif (a2 < 0) a2 += n;\n\tif ((a1 < 0) || (a1 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis1 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tif ((a2 < 0) || (a2 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis2 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tnew_axes.ptr = dims;\n\tnew_axes.len = n;\n\n\tfor (i=0; ind;\n\t\tfor(i=0; ilen;\n\t\taxes = permute->ptr;\n\t\tif (n > ap->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many axes for this array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tfor(i=0; ind+axis;\n\t\t\tif (axis < 0 || axis >= ap->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"invalid axis for this array\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tpermutation[i] = axis;\n\t\t}\n\t}\n\t\n\t/* this allocates memory for dimensions and strides (but fills them\n\t incorrectly), sets up descr, and points data at ap->data. */\n\tPy_INCREF(ap->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t ap->descr, \n\t\t\t\t n, permutation, \n\t\t\t\t NULL, ap->data, ap->flags,\n\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) return NULL;\n\t\n\t/* point at true owner of memory: */\n\tret->base = (PyObject *)ap;\n\tPy_INCREF(ap);\n\t\n\tfor(i=0; idimensions[i] = ap->dimensions[permutation[i]];\n\t\tret->strides[i] = ap->strides[permutation[i]];\n\t}\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\t\n\n\treturn (PyObject *)ret;\t\n}\n\n/*MULTIARRAY_API\n Repeat the array.\n*/\nstatic PyObject *\nPyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis)\n{\n\tintp *counts;\n\tintp n, n_outer, i, j, k, chunk, total;\n\tintp tmp;\n\tint nd;\n\tPyArrayObject *repeats=NULL;\n\tPyObject *ap=NULL;\n\tPyArrayObject *ret=NULL;\n\tchar *new_data, *old_data;\n\n\trepeats = (PyAO *)PyArray_ContiguousFromAny(op, PyArray_INTP, 0, 1);\n\tif (repeats == NULL) return NULL;\n\tnd = repeats->nd;\n\tcounts = (intp *)repeats->data;\n\n\tif ((ap=_check_axis(aop, &axis, CARRAY_FLAGS))==NULL) {\n\t\tPy_DECREF(repeats);\n\t\treturn NULL;\n\t}\n\n\taop = (PyAO *)ap;\n\n\tif (nd == 1)\n\t\tn = repeats->dimensions[0];\n\telse /* nd == 0 */\n\t\tn = aop->dimensions[axis];\n\n\tif (aop->dimensions[axis] != n) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"a.shape[axis] != len(repeats)\");\n\t\tgoto fail;\n\t}\n\n\t\n\tif (nd == 0) \n\t\ttotal = counts[0]*n;\n\telse {\n\t\t\n\t\ttotal = 0;\n\t\tfor(j=0; jdimensions[axis] = total;\n\tPy_INCREF(aop->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(aop->ob_type, \n\t\t\t\t\t\t aop->descr,\n\t\t\t\t\t\t aop->nd,\n\t\t\t\t\t\t aop->dimensions,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)aop);\n\taop->dimensions[axis] = n;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tnew_data = ret->data;\n\told_data = aop->data;\n\t\n\tchunk = aop->descr->elsize;\n\tfor(i=axis+1; ind; i++) {\n\t\tchunk *= aop->dimensions[i];\n\t}\n\t\n\tn_outer = 1;\n\tfor(i=0; idimensions[i];\n\n\tfor(i=0; idescr->elsize;\n\tbyteorder = arr->descr->byteorder;\n\tptr = arr->data;\n\tif (elsize > 1 && \\\n\t (byteorder == PyArray_LITTLE ||\t\\\n\t (byteorder == PyArray_NATIVE &&\n\t PyArray_ISNBO(PyArray_LITTLE))))\n\t\tptr += elsize-1;\n\t\n\treturn ((*ptr & bitmask) != 0);\t\n}\n\n\n/*OBJECT_API*/\nstatic PyArray_SCALARKIND\nPyArray_ScalarKind(int typenum, PyArrayObject **arr) \n{\n\tif (PyTypeNum_ISSIGNED(typenum)) {\n\t\tif (arr && _signbit_set(*arr)) return PyArray_INTNEG_SCALAR;\n\t\telse return PyArray_INTPOS_SCALAR;\n\t}\n\tif (PyTypeNum_ISFLOAT(typenum)) return PyArray_FLOAT_SCALAR;\n\tif (PyTypeNum_ISUNSIGNED(typenum)) return PyArray_INTPOS_SCALAR;\n\tif (PyTypeNum_ISCOMPLEX(typenum)) return PyArray_COMPLEX_SCALAR;\n\tif (PyTypeNum_ISBOOL(typenum)) return PyArray_BOOL_SCALAR;\n\n\treturn PyArray_OBJECT_SCALAR;\n}\n\n/*OBJECT_API*/\nstatic int \nPyArray_CanCoerceScalar(char thistype, char neededtype, \n\t\t\tPyArray_SCALARKIND scalar) \n{\n\n\tswitch(scalar) {\n\tcase PyArray_NOSCALAR:\n\tcase PyArray_BOOL_SCALAR:\n\tcase PyArray_OBJECT_SCALAR:\n\t\treturn PyArray_CanCastSafely(thistype, neededtype);\n\tcase PyArray_INTPOS_SCALAR:\n\t\treturn (neededtype >= PyArray_UBYTE);\n\tcase PyArray_INTNEG_SCALAR:\n\t\treturn (neededtype >= PyArray_BYTE) &&\t\t\\\n\t\t\t!(PyTypeNum_ISUNSIGNED(neededtype));\n\tcase PyArray_FLOAT_SCALAR:\n\t\treturn (neededtype >= PyArray_FLOAT);\n\tcase PyArray_COMPLEX_SCALAR:\n\t\treturn (neededtype >= PyArray_CFLOAT);\n\t}\n\tfprintf(stderr, \"\\n**Error** coerce fall through: %d %d %d\\n\\n\", \n\t\tthistype, neededtype, scalar);\n\treturn 1; /* should never get here... */ \n}\n\n\n/* This needs to change to allow scalars of a different \"kind\" to alter the input type\n */\n\n/*OBJECT_API*/\nstatic PyArrayObject **\nPyArray_ConvertToCommonType(PyObject *op, int *retn)\n{\n\tint i, n, allscalars=0; \n\tPyArrayObject **mps=NULL;\n\tPyObject *otmp;\n\tPyArray_Descr *intype=NULL, *stype=NULL;\n\tPyArray_Descr *newtype=NULL;\n\tchar scalarkind;\n\n\t\n\t*retn = n = PySequence_Length(op);\n\tif (PyErr_Occurred()) {*retn = 0; return NULL;}\n\t\n\tmps = (PyArrayObject **)PyDataMem_NEW(n*sizeof(PyArrayObject *));\n\tif (mps == NULL) {\n\t\t*retn = 0;\n\t\treturn (void*)PyErr_NoMemory();\n\t}\n\t\n\tfor(i=0; itype_num, NULL);\n\t\t\tif (intype && !PyArray_CanCoerceScalar(newtype->type_num,\n\t\t\t\t\t\t\t intype->type_num, \n\t\t\t\t\t\t\t scalarkind)) {\n\t\t\t\tPy_XDECREF(intype);\n\t\t\t\tintype = stype;\n\t\t\t}\n\t\t\tmps[i] = (PyArrayObject *)Py_None;\n\t\t\tPy_INCREF(Py_None);\n\t\t}\n\t\tPy_XDECREF(otmp);\n\t}\n\tif (intype==NULL) { /* all scalars */\n\t\tallscalars = 1;\n\t\tintype = stype;\n\t\tPy_INCREF(intype);\n\t\tfor (i=0; ind < mps[i]->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many dimensions\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (!PyArray_CompareLists(ap->dimensions+(ap->nd-mps[i]->nd),\n\t\t\t\t mps[i]->dimensions, mps[i]->nd)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"array dimensions must agree\");\n\t\t\tgoto fail;\n\t\t}\n\t\tsizes[i] = PyArray_NBYTES(mps[i]);\n\t}\n\t\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t\t\t mps[0]->descr,\n\t\t\t\t\t\t ap->nd,\n\t\t\t\t\t\t ap->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\telsize = ret->descr->elsize;\n\tm = PyArray_SIZE(ret);\n\tself_data = (intp *)ap->data;\n\tret_data = ret->data;\n\t\n\tfor (i=0; i= n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid entry in choice array\");\n\t\t\tgoto fail;\n\t\t}\n\t\toffset = i*elsize;\n\t\tif (offset >= sizes[mi]) {offset = offset % sizes[mi]; }\n\t\tmemmove(ret_data, mps[mi]->data+offset, elsize);\n\t\tret_data += elsize; self_data++;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; idescr->f->sort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize);\n\n\tif (needcopy) {\n\t\tchar *buffer;\n\t\tbuffer = PyDataMem_NEW(N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(buffer, (intp) elsize, it->dataptr, \n\t\t\t\t astride, N, elsize);\n\t\t\tif (sort(buffer, N, op) < 0) {\n\t\t\t\tPyDataMem_FREE(buffer); goto fail;\n\t\t\t}\n\t\t\t_strided_copy(it->dataptr, astride, buffer, \n\t\t\t\t (intp) elsize, N, elsize);\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyDataMem_FREE(buffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tif (sort(it->dataptr, N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\t\n\t\n\tEND_THREADS\n\t\n\tPy_DECREF(it);\n\treturn 0;\n\n fail:\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nstatic PyObject*\n_new_argsort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\n\tPyArrayIterObject *it=NULL;\n\tPyArrayIterObject *rit=NULL;\n\tPyObject *ret;\n\tint needcopy=0, i;\n\tintp N, size;\n\tint elsize;\n\tintp astride, rstride, *iptr;\n\tPyArray_ArgSortFunc *argsort;\n\tBEGIN_THREADS_DEF \n\n\tret = PyArray_New(op->ob_type, op->nd,\n\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) return NULL;\n\n\tit = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)op, axis);\n\trit = (PyArrayIterObject *)PyArray_IterAllButAxis(ret, axis);\n\tif (rit == NULL || it == NULL) goto fail;\n\n\tBEGIN_THREADS\n\n\targsort = op->descr->f->argsort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize) || \\\n\t\t(rstride != sizeof(intp));\n\t\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(elsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(valbuffer, (intp) elsize, it->dataptr,\n\t\t\t\t astride, N, elsize);\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idataptr, rstride, indbuffer, \n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idataptr, (intp *)rit->dataptr, \n\t\t\t\t N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\t\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\tPy_DECREF(rit);\n\treturn ret;\n\n fail:\n\n\tEND_THREADS\n\n\tPy_DECREF(ret);\n\tPy_XDECREF(it);\n\tPy_XDECREF(rit);\n\treturn NULL;\n}\n\n\n/* Be sure to save this global_compare when necessary */\n\nstatic PyArrayObject *global_obj;\n\nstatic int \nqsortCompare (const void *a, const void *b) \n{\n\treturn global_obj->descr->f->compare(a,b,global_obj);\n}\n\n/* Consumes reference to ap (op gets it)\n op contains a version of the array with axes swapped if\n local variable axis is not the last dimension.\n orign must be defined locally. \n*/\n\n#define SWAPAXES(op, ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* Consumes reference to ap (op gets it)\n origin must be previously defined locally. \n SWAPAXES must have been called previously. \n op contains the swapped version of the array. \n*/\n#define SWAPBACK(op, ap) {\t \\\n\t\tif (axis != orign) { \\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* These swap axes in-place if necessary */\n#define SWAPINTP(a,b) {intp c; c=(a); (a) = (b); (b) = c;}\n#define SWAPAXES2(ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN); \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define SWAPBACK2(ap) {\t\t \\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n/*MULTIARRAY_API\n Sort an array in-place\n*/\nstatic int\nPyArray_Sort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *store_arr=NULL;\n\tchar *ip;\n\tint i, n, m, elsize, orign;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) return 0;\n\n\tif (axis < 0) axis += n;\n\tif ((axis < 0) || (axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\treturn -1;\n\t}\n\tif (!PyArray_ISWRITEABLE(op)) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"attempted sort on unwriteable array.\");\n\t\treturn -1;\n\t}\n\n\t/* Determine if we should use type-specific algorithm or not */\n\tif (op->descr->f->sort[which] != NULL) {\n\t\treturn _new_sort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || \\\n\t op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"desired sort not supported for this type\");\n\t\treturn -1;\n\t}\n\n\tSWAPAXES2(op);\n\n ap = (PyArrayObject *)PyArray_FromAny((PyObject *)op, \n\t\t\t\t\t NULL, 1, 0, \n\t\t\t\t\t DEFAULT_FLAGS | UPDATEIFCOPY, NULL);\t\n\tif (ap == NULL) goto fail;\n\t\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(ap)/m;\n\n\t/* Store global -- allows re-entry -- restore before leaving*/\n\tstore_arr = global_obj; \n\tglobal_obj = ap;\n\t\n\tfor (ip=ap->data, i=0; idescr->elsize;\n\tconst intp *ipa = ip1;\n\tconst intp *ipb = ip2;\t\n\treturn global_obj->descr->f->compare(global_data + (isize * *ipa),\n global_data + (isize * *ipb), \n\t\t\t\t\t global_obj);\n}\n\n/*MULTIARRAY_API\n ArgSort an array\n*/\nstatic PyObject *\nPyArray_ArgSort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *ret=NULL, *store;\n\tintp *ip;\n\tintp i, j, n, m, orign;\n\tint argsort_elsize;\n\tchar *store_ptr;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t\t op->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, \n\t\t\t\t\t\t (PyObject *)op);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)ret->data) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += n;\n\tif ((axis < 0) || (axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\treturn NULL;\n\t}\n\n\t/* Determine if we should use new algorithm or not */\n\tif (op->descr->f->argsort[which] != NULL) {\n\t\treturn _new_argsort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"requested sort not available for type\");\n\t\tgoto fail;\n\t}\n\n\tSWAPAXES(ap, op);\n\n\top = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ap, \n\t\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t\t 1, 0);\n\n\tif (op == NULL) return NULL;\n\t\n\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) goto fail;\n\t\n\t\n\tip = (intp *)ret->data;\n\targsort_elsize = op->descr->elsize;\n\tm = op->dimensions[op->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(op)/m;\n\tstore_ptr = global_data;\n\tglobal_data = op->data;\n\tstore = global_obj;\n\tglobal_obj = op;\n\tfor (i=0; i 0 in lexsort\");\n\t\treturn NULL;\n\t}\n\tmps = (PyArrayObject **) _pya_malloc(n*sizeof(PyArrayObject));\n\tif (mps==NULL) return PyErr_NoMemory();\n\tits = (PyArrayIterObject **) _pya_malloc(n*sizeof(PyArrayIterObject));\n\tif (its == NULL) {_pya_free(mps); return PyErr_NoMemory();}\n\tfor (i=0; i0) {\n\t\t\tif ((mps[i]->nd != mps[0]->nd) ||\t\\\n\t\t\t (!PyArray_CompareLists(mps[i]->dimensions,\n\t\t\t\t\t\t mps[0]->dimensions,\n\t\t\t\t\t\t mps[0]->nd))) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"all keys need to be the same shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (!mps[i]->descr->f->argsort[PyArray_MERGESORT]) {\n\t\t\tPyErr_Format(PyExc_TypeError, \n\t\t\t\t \"merge sort not available for item %d\", i);\n\t\t\tgoto fail;\n\t\t}\n\t\tits[i] = (PyArrayIterObject *)PyArray_IterAllButAxis\t\\\n\t\t\t((PyObject *)mps[i], axis);\n\t\tif (its[i]==NULL) goto fail;\n\t}\n\n\t/* Now we can check the axis */\n\tnd = mps[0]->nd;\n\tif ((nd==0) || (PyArray_SIZE(mps[0])==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)(ret->data)) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += nd;\n\tif ((axis < 0) || (axis >= nd)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\tgoto fail;\n\t}\n\n\t/* Now do the sorting */\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t mps[0]->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (ret == NULL) goto fail;\n\n\trit = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ret, axis);\n\tif (rit == NULL) goto fail;\n\n\tsize = rit->size;\n\tN = mps[0]->dimensions[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n maxelsize = mps[0]->descr->elsize;\n\tneedcopy = (rstride != sizeof(intp));\n\tfor (j=0; jflags & ALIGNED) || \\\n\t\t\t(mps[j]->strides[axis] != (intp)mps[j]->descr->elsize);\n if (mps[j]->descr->elsize > maxelsize) \n maxelsize = mps[j]->descr->elsize;\n\t}\n\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(maxelsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*maxelsize);\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idescr->elsize;\n\t\t\t\tastride = mps[j]->strides[axis];\t\n\t\t\t\targsort = mps[j]->descr->f->argsort[PyArray_MERGESORT];\n\t\t\t\t_strided_copy(valbuffer, (intp) elsize, its[j]->dataptr,\n\t\t\t\t\t astride, N, elsize);\n\t\t\t\tif (argsort(valbuffer, (intp *)indbuffer, N, mps[j]) < 0) {\n\t\t\t\t\tPyDataMem_FREE(valbuffer); goto fail;\n\t\t\t\t}\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\t_strided_copy(rit->dataptr, rstride, indbuffer,\n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idescr->f->argsort[PyArray_MERGESORT];\n\t\t\t\tif (argsort(its[j]->dataptr, (intp *)rit->dataptr,\n\t\t\t\t\t N, mps[j]) < 0) goto fail;\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\n\tfor (i=0; idescr->f->compare;\n\tintp min_i, max_i, i, j;\n\tint location, elsize = ap1->descr->elsize;\n\tintp elements = ap1->dimensions[ap1->nd-1];\n\tintp n = PyArray_SIZE(ap2);\n\tintp *rp = (intp *)ret->data;\n\tchar *ip = ap2->data;\n\tchar *vp = ap1->data;\n\n\tfor (j=0; j 0) {\n\t\t\t\t\tif (compare(ip, vp+elsize*(--i), ap2) \\\n\t\t\t\t\t != 0) {\n\t\t\t\t\t\ti = i+1; break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmin_i = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (location < 0) {\n\t\t\t\tmax_i = i;\n\t\t\t} else {\n\t\t\t\tmin_i = i+1;\n\t\t\t}\n\t\t}\n\t\t*rp = min_i;\n\t}\n}\n\n/*MULTIARRAY_API\n Numeric.searchsorted(a,v)\n*/\nstatic PyObject *\nPyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n\tint typenum = 0;\n\n\t/* \n PyObject *args;\n args = Py_BuildValue(\"O\",op2);\n\tPy_DELEGATE_ARGS(((PyObject *)op1), searchsorted, args);\n Py_XDECREF(args);\n\t*/\n\n\ttypenum = PyArray_ObjectType((PyObject *)op1, 0);\n\ttypenum = PyArray_ObjectType(op2, typenum);\n\tret = NULL;\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op1, \n\t\t\t\t\t\t\t typenum, \n\t\t\t\t\t\t\t 1, 1);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tret = (PyArrayObject *)PyArray_New(ap2->ob_type, ap2->nd, \n\t\t\t\t\t ap2->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap2);\n\tif (ret == NULL) goto fail;\n\n\tif (ap2->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tgoto fail;\n\t}\n\t\n\tlocal_where(ap1, ap2, ret); \n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n/*\n Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\treturn ret;\n}\n\n/* Could perhaps be redone to not make contiguous arrays \n */\n\n/*MULTIARRAY_API\n Numeric.innerproduct(a,v)\n*/\nstatic PyObject *\nPyArray_InnerProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tPyArray_Descr *typec;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\tdot = (ret->descr->f->dotfunc);\n\t\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[ap1->nd-1]; \n\tis2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, ap2->nd-1);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\n\tif (PyErr_Occurred()) goto fail;\n\t\t\n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n\n/* just like inner product but does the swapaxes stuff on the fly */\n/*MULTIARRAY_API\n Numeric.matrixproduct(a,v)\n*/\nstatic PyObject *\nPyArray_MatrixProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tintp matchDim;\n\tPyArray_Descr *typec;\n\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\t\n\t\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t}\n\telse {\n\t\tmatchDim = 0;\n\t}\n\n\tif (ap2->dimensions[matchDim] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"objects are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-2; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\tif(ap2->nd > 1) {\n\t\tdimensions[j++] = ap2->dimensions[ap2->nd-1];\n\t}\n\t/*\n\tfprintf(stderr, \"nd=%d dimensions=\", nd);\n\t for(i=0; istrides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\n /* Choose which subtype to return */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\n\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\t\t\n\top = ret->data; os = ret->descr->elsize;\n\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, matchDim);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\tif (PyErr_Occurred()) goto fail; /* only for OBJECT arrays */\n\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n/*MULTIARRAY_API\n Fast Copy and Transpose\n*/\nstatic PyObject *\nPyArray_CopyAndTranspose(PyObject *op) \n{\n\tPyObject *ret, *arr;\n\tint nd;\n\tintp dims[2];\n\tintp i,j;\n\tint elsize, str2;\n\tchar *iptr;\n\tchar *optr;\n\n\t/* make sure it is well-behaved */\n\tarr = PyArray_FromAny(op, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\tnd = PyArray_NDIM(arr);\n\tif (nd == 1) { /* we will give in to old behavior */\n\t\tret = PyArray_Copy((PyArrayObject *)arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\t\t\n\t}\n\telse if (nd != 2) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"only 2-d arrays are allowed\");\n\t\treturn NULL;\n\t}\n\n\t/* Now construct output array */\n\tdims[0] = PyArray_DIM(arr,1);\n\tdims[1] = PyArray_DIM(arr,0);\n\telsize = PyArray_ITEMSIZE(arr);\n\t\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(arr->ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t 2, dims, \n\t\t\t\t NULL, NULL, 0, arr);\n\n\tif (ret == NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn NULL;\n\t}\n\t/* do 2-d loop */\n\toptr = PyArray_DATA(ret);\n\tstr2 = elsize*dims[0];\n\tfor (i=0; idimensions[0];\n\tn2 = ap2->dimensions[0];\n\n\tif (n1 < n2) { \n\t\tret = ap1; ap1 = ap2; ap2 = ret; \n\t\tret = NULL; i = n1;n1=n2;n2=i;\n\t}\n\tlength = n1;\n\tn = n2;\n\tswitch(mode) {\n\tcase 0:\t\n\t\tlength = length-n+1;\n\t\tn_left = n_right = 0;\n\t\tbreak;\n\tcase 1:\n\t\tn_left = (intp)(n/2);\n\t\tn_right = n-n_left-1;\n\t\tbreak;\n\tcase 2:\n\t\tn_right = n-1;\n\t\tn_left = n-1;\n\t\tlength = length+n-1;\n\t\tbreak;\n\tdefault:\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mode must be 0, 1, or 2\");\n\t\tgoto fail;\n\t}\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\n\tif (ret == NULL) goto fail;\n\t\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"function not available for this data type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[0]; is2 = ap2->strides[0];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data; ip2 = ap2->data+n_left*is2;\n\tn = n-n_left;\n\tfor(i=0; idescr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Min\n*/\nstatic PyObject *\nPyArray_Min(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tret = PyArray_GenericReduceFunction(arr, n_ops.minimum, axis,\n\t\t\t\t\t arr->descr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Ptp\n*/\nstatic PyObject *\nPyArray_Ptp(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\tPyObject *obj1=NULL, *obj2=NULL;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tobj1 = PyArray_Max(arr, axis);\n\tif (obj1 == NULL) goto fail;\n\tobj2 = PyArray_Min(arr, axis);\n\tif (obj2 == NULL) goto fail;\n\tPy_DECREF(arr);\n\tret = PyNumber_Subtract(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(obj1);\n\tPy_XDECREF(obj2);\n\treturn NULL;\n}\n\n\n/*MULTIARRAY_API\n ArgMax\n*/\nstatic PyObject *\nPyArray_ArgMax(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap=NULL, *rp=NULL;\n\tPyArray_ArgFunc* arg_func;\n\tchar *ip;\n\tintp *rptr;\n\tintp i, n, orign, m;\n\tint elsize;\n\t\n\tif ((ap=(PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny((PyObject *)op, \n\t\t\t\t\t PyArray_NOTYPE, 1, 0);\n\n\tPy_DECREF(op);\n\tif (ap == NULL) return NULL;\n\t\n\targ_func = ap->descr->f->argmax;\n\tif (arg_func == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"data type not ordered\");\n\t\tgoto fail;\n\t}\n\n\trp = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd-1,\n\t\t\t\t\t ap->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)ap);\n\tif (rp == NULL) goto fail;\n\n\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) {\n\t\tPyErr_SetString(MultiArrayError, \n\t\t\t\t\"attempt to get argmax/argmin \"\\\n\t\t\t\t\"of an empty sequence??\");\n\t\tgoto fail;\n\t}\n\tn = PyArray_SIZE(ap)/m;\n\trptr = (intp *)rp->data;\n\tfor (ip = ap->data, i=0; ind + indices->nd - 1;\n for (i=0; i< nd; i++) {\n if (i < axis) {\n shape[i] = self->dimensions[i];\n n *= shape[i];\n } else {\n if (i < axis+indices->nd) {\n shape[i] = indices->dimensions[i-axis];\n m *= shape[i];\n } else {\n shape[i] = self->dimensions[i-indices->nd+1];\n chunk *= shape[i];\n }\n }\n }\n\tPy_INCREF(self->descr);\n ret = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t nd, shape, \n\t\t\t\t\t\t NULL, NULL, 0, \n\t\t\t\t\t\t (PyObject *)self);\n\t\n if (ret == NULL) goto fail;\n\t\n max_item = self->dimensions[axis];\n chunk = chunk * ret->descr->elsize;\n src = self->data;\n dest = ret->data;\n\t\n for(i=0; idata))[j];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\t\"index out of range for \"\\\n\t\t\t\t\t\t\"array\");\n goto fail;\n }\n memmove(dest, src+tmp*chunk, chunk);\n dest += chunk;\n }\n src += chunk*max_item;\n }\n\t\n PyArray_INCREF(ret);\n\n Py_XDECREF(indices);\n Py_XDECREF(self);\n\n return (PyObject *)ret;\n\t\n\t\n fail:\n Py_XDECREF(ret);\n Py_XDECREF(indices);\n Py_XDECREF(self);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array\n*/\nstatic PyObject *\nPyArray_Put(PyArrayObject *self, PyObject* values0, PyObject *indices0) \n{\n PyArrayObject *indices, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype; \n char *src, *dest;\n\n indices = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \"put: first argument must be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \"put: first argument must be contiguous\");\n return NULL;\n }\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0);\n if (indices == NULL) goto fail;\n ni = PyArray_SIZE(indices);\n\n\tthistype = self->descr->type_num;\n Py_INCREF(self->descr); \n\tvalues = (PyArrayObject *)PyArray_FromAny(values0, self->descr, 0, 0, \n\t\t\t\t\t\t DEFAULT_FLAGS | FORCECAST, NULL); \n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\n if (thistype == PyArray_OBJECT) { \n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n Py_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+tmp*chunk)));\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n\n }\n\n Py_XDECREF(values);\n Py_XDECREF(indices);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(indices);\n Py_XDECREF(values);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array according to a mask.\n*/\nstatic PyObject *\nPyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) \n{\n PyArrayObject *mask, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype;\n char *src, *dest;\n\n mask = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"putmask: first argument must \"\\\n\t\t\t\t\"be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: first argument must be contiguous\");\n return NULL;\n }\n\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n mask = (PyArrayObject *)\\\n\t\tPyArray_FROM_OTF(mask0, PyArray_BOOL, CARRAY_FLAGS | FORCECAST);\n\tif (mask == NULL) goto fail;\n ni = PyArray_SIZE(mask);\n if (ni != max_item) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: mask and data must be \"\\\n\t\t\t\t\"the same size\");\n goto fail;\n }\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n\tif (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\t /* zero if null array */\n if (nv > 0) {\n if (thistype == PyArray_OBJECT) {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) {\n\t\t\t\t\tPy_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+i*chunk)));\n memmove(dest + i * chunk, src, chunk);\n }\n\t\t\t}\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) memmove(dest + i * chunk, src, chunk);\n\t\t\t}\n\t\t}\n }\n\n Py_XDECREF(values);\n Py_XDECREF(mask);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(mask);\n Py_XDECREF(values);\n return NULL;\n}\n\n\n/* This conversion function can be used with the \"O&\" argument for\n PyArg_ParseTuple. It will immediately return an object of array type\n or will convert to a CARRAY any other object. \n\n If you use PyArray_Converter, you must DECREF the array when finished\n as you get a new reference to it.\n*/\n \n/*MULTIARRAY_API\n Useful to pass as converter function for O& processing in\n PyArgs_ParseTuple.\n*/\nstatic int \nPyArray_Converter(PyObject *object, PyObject **address) \n{\n if (PyArray_Check(object)) {\n *address = object;\n\t\tPy_INCREF(object);\n return PY_SUCCEED;\n }\n else {\n\t\t*address = PyArray_FromAny(object, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\t\tif (*address == NULL) return PY_FAIL;\n\t\treturn PY_SUCCEED;\n }\n}\n\n/*MULTIARRAY_API\n Convert an object to true / false\n*/\nstatic int\nPyArray_BoolConverter(PyObject *object, Bool *val)\n{ \n if (PyObject_IsTrue(object))\n *val=TRUE;\n else *val=FALSE;\n if (PyErr_Occurred())\n return PY_FAIL;\n return PY_SUCCEED;\n}\n\n\n/*MULTIARRAY_API\n Typestr converter\n*/\nstatic int\nPyArray_TypestrConvert(int itemsize, int gentype)\n{\n\tregister int newtype = gentype;\n\t\n\tif (gentype == PyArray_GENBOOLLTR) {\n\t\tif (itemsize == 1)\n\t\t\tnewtype = PyArray_BOOL;\n\t\telse \n\t\t\tnewtype = PyArray_NOTYPE;\n\t}\n\telse if (gentype == PyArray_SIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_INT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_INT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_INT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_INT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_INT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\n\t}\n\n\telse if (gentype == PyArray_UNSIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_UINT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_UINT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_UINT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_UINT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_UINT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t\tbreak;\n\t\t}\n\t}\n\telse if (gentype == PyArray_FLOATINGLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 4:\n\t\t\tnewtype = PyArray_FLOAT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_FLOAT64;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 10:\n\t\t\tnewtype = PyArray_FLOAT80;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 12:\n\t\t\tnewtype = PyArray_FLOAT96;\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_FLOAT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\t\n\telse if (gentype == PyArray_COMPLEXLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 8:\n\t\t\tnewtype = PyArray_COMPLEX64;\n\t\t\tbreak;\n\t\tcase 16:\n\t\t\tnewtype = PyArray_COMPLEX128;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 20:\n\t\t\tnewtype = PyArray_COMPLEX160;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 24:\n\t\t\tnewtype = PyArray_COMPLEX192;\t\t\t\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 32:\n\t\t\tnewtype = PyArray_COMPLEX256;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\n\treturn newtype;\n}\n\n\n/* this function takes a Python object which exposes the (single-segment)\n buffer interface and returns a pointer to the data segment\n \n You should increment the reference count by one of buf->base\n if you will hang on to a reference\n\n You only get a borrowed reference to the object. Do not free the\n memory...\n*/\n\n\n/*MULTIARRAY_API\n Get buffer chunk from object\n*/\nstatic int\nPyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)\n{\n int buflen;\n\n buf->ptr = NULL;\n buf->flags = BEHAVED_FLAGS;\n buf->base = NULL;\n\n\tif (obj == Py_None)\n\t\treturn PY_SUCCEED;\n\n if (PyObject_AsWriteBuffer(obj, &(buf->ptr), &buflen) < 0) {\n PyErr_Clear();\n buf->flags &= ~WRITEABLE;\n if (PyObject_AsReadBuffer(obj, (const void **)&(buf->ptr), \n &buflen) < 0)\n return PY_FAIL;\n }\n buf->len = (intp) buflen;\n \n /* Point to the base of the buffer object if present */\n if (PyBuffer_Check(obj)) buf->base = ((PyArray_Chunk *)obj)->base;\n if (buf->base == NULL) buf->base = obj;\n \n return PY_SUCCEED; \n}\n\n\n\n/* This function takes a Python sequence object and allocates and\n fills in an intp array with the converted values.\n\n **Remember to free the pointer seq.ptr when done using\n PyDimMem_FREE(seq.ptr)**\n*/\n\n/*MULTIARRAY_API\n Get intp chunk from sequence\n*/\nstatic int\nPyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)\n{\n int len;\n int nd;\n\n seq->ptr = NULL;\n if (obj == Py_None) return PY_SUCCEED;\n len = PySequence_Size(obj);\n if (len == -1) { /* Check to see if it is a number */\n if (PyNumber_Check(obj)) len = 1;\n }\n if (len < 0) {\n PyErr_SetString(PyExc_TypeError, \n \"expected sequence object with len >= 0\");\n return PY_FAIL;\n }\n if (len > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError, \"sequence too large; \" \\\n \"must be smaller than %d\", MAX_DIMS);\n return PY_FAIL;\n }\n\tif (len > 0) {\n\t\tseq->ptr = PyDimMem_NEW(len);\n\t\tif (seq->ptr == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n seq->len = len;\n nd = PyArray_IntpFromSequence(obj, (intp *)seq->ptr, len);\n if (nd == -1 || nd != len) {\n\t\tPyDimMem_FREE(seq->ptr);\n\t\tseq->ptr=NULL;\n\t\treturn PY_FAIL;\n\t}\n return PY_SUCCEED;\n}\n\n\n/* A tuple type would be either (generic typeobject, typesize) \n or (fixed-length data-type, shape) \n\n or (inheriting data-type, new-data-type)\n The new data-type must have the same itemsize as the inheriting data-type\n unless the latter is 0 \n \n Thus (int32, {'real':(int16,0),'imag',(int16,2)})\n\n is one way to specify a descriptor that will give \n a['real'] and a['imag'] to an int32 array.\n*/\n\n/* leave type reference alone */\nstatic PyArray_Descr *\n_use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) \n{\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n\t\n\t*errflag = 0;\n\tif (!PyArray_DescrConverter(newobj, &conv)) {\n\t\treturn NULL;\n\t}\n\t*errflag = 1;\n\tif (type == &OBJECT_Descr) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"cannot base a new descriptor on an\"\\\n\t\t\t\t\" OBJECT descriptor.\");\n\t\tgoto fail;\n\t}\n\tnew = PyArray_DescrNew(type);\n\tif (new == NULL) goto fail;\n\n\tif (new->elsize && new->elsize != conv->elsize) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mismatch in size of old\"\\\n\t\t\t\t\"and new data-descriptor\");\n\t\tgoto fail;\n\t}\n\tnew->elsize = conv->elsize;\n\tif (conv->fields != Py_None) {\n\t\tnew->fields = conv->fields;\n\t\tPy_XINCREF(new->fields);\n\t}\n\tPy_DECREF(conv);\n\t*errflag = 0;\n\treturn new;\n\n fail:\n\tPy_DECREF(conv);\n\treturn NULL;\n\n}\n\nstatic PyArray_Descr *\n_convert_from_tuple(PyObject *obj) \n{\n\tPyArray_Descr *type, *res;\n\tPyObject *val;\n\tint errflag;\n\t\n\tif (PyTuple_GET_SIZE(obj) != 2) return NULL;\n\n\tif (!PyArray_DescrConverter(PyTuple_GET_ITEM(obj,0), &type)) \n\t\treturn NULL;\n\tval = PyTuple_GET_ITEM(obj,1);\n\t/* try to interpret next item as a type */\n\tres = _use_inherit(type, val, &errflag);\n\tif (res || errflag) {\n\t\tPy_DECREF(type);\n\t\tif (res) return res;\n\t\telse return NULL;\n\t}\n\tPyErr_Clear();\n\t/* We get here if res was NULL but errflag wasn't set\n\t --- i.e. the conversion to a data-descr failed in _use_inherit\n\t*/\n\n\tif (type->elsize == 0) { /* interpret next item as a typesize */\n\t\tint itemsize;\n\t\titemsize = PyArray_PyIntAsInt(PyTuple_GET_ITEM(obj,1));\n\t\tif (error_converting(itemsize)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid itemsize in generic type \"\\\n\t\t\t\t\t\"tuple\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(type);\n\t\tif (type->type_num == PyArray_UNICODE)\n\t\t\ttype->elsize = itemsize << 2; \n\t\telse\n\t\t\ttype->elsize = itemsize;\n\t}\n\telse {\n\t\t/* interpret next item as shape (if it's a tuple)\n\t\t and reset the type to PyArray_VOID with \n\t\t a new fields attribute. \n\t */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyArray_Descr *newdescr;\n\t\tif (!(PyArray_IntpConverter(val, &shape)) || \n\t\t (shape.len > MAX_DIMS)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n\t\t\tgoto fail;\n\t\t}\n\t\t/* If (type, 1) was given, it is equivalent to type... */\n\t\tif (shape.len == 1 && shape.ptr[0] == 1 && \\\n\t\t PyNumber_Check(val)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\treturn type;\n\t\t}\n\t\tnewdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tif (newdescr == NULL) {PyDimMem_FREE(shape.ptr); goto fail;}\n\t\tnewdescr->elsize = type->elsize;\n\t\tnewdescr->elsize *= PyArray_MultiplyList(shape.ptr, \n\t\t\t\t\t\t\t shape.len);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tnewdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tnewdescr->subarray->base = type;\n\t\tif (type->hasobject) newdescr->hasobject = 1;\n\t\tPy_INCREF(val);\n\t\tnewdescr->subarray->shape = val;\n\t\tPy_XDECREF(newdescr->fields);\n\t\tnewdescr->fields = NULL;\n\t\ttype = newdescr;\n\t}\n\treturn type;\n\n fail:\n\tPy_XDECREF(type);\n\treturn NULL;\n}\n\n/* obj is a list. Each item is a tuple with\n\n(field-name, data-type (either a list or a string), and an optional \n shape parameter).\n*/\nstatic PyArray_Descr *\n_convert_from_array_descr(PyObject *obj)\n{\n\tint n, i, totalsize;\n\tint ret;\n\tPyObject *fields, *item, *newobj;\n\tPyObject *name, *key, *tup, *title;\n\tPyObject *nameslist;\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n int hasobject=0;\n\t\n\tn = PyList_GET_SIZE(obj);\t\n\tnameslist = PyTuple_New(n);\n\tif (!nameslist) return NULL;\n\ttotalsize = 0;\n\tfields = PyDict_New();\n\tfor (i=0; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New((title == NULL ? 2 : 3));\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\tif (title != NULL) {\t\t\t\n\t\t\tPy_INCREF(title);\n\t\t\tPyTuple_SET_ITEM(tup, 2, title);\n\t\t\tPyDict_SetItem(fields, title, tup);\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\ttotalsize += conv->elsize;\n\t\tPy_DECREF(tup);\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n\tnew->elsize = totalsize;\n new->hasobject=hasobject;\n\treturn new;\n \n fail:\n\tPy_DECREF(fields);\n\tPy_DECREF(nameslist);\n\treturn NULL;\n\n}\n\n/* a list specifying a data-type can just be\n a list of formats. The names for the fields\n will default to f1, f2, f3, and so forth.\n\n or it can be an array_descr format string -- in which case\n align must be 0. \n*/\n\nstatic PyArray_Descr *\n_convert_from_list(PyObject *obj, int align, int try_descr)\n{\n\tint n, i;\n\tint totalsize;\n\tPyObject *fields;\n\tPyArray_Descr *conv=NULL;\n\tPyArray_Descr *new;\n\tPyObject *key, *tup;\n\tPyObject *nameslist=NULL;\n \tint ret;\n\tint maxalign=0;\n int hasobject=0;\n\t\n\tn = PyList_GET_SIZE(obj);\n\ttotalsize = 0;\n\tif (n==0) return NULL;\n\tnameslist = PyTuple_New(n);\n\tif (!nameslist) return NULL;\n\tfields = PyDict_New();\n\tfor (i=0; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tif (align) {\n\t\t\tint _align;\n\t\t\t_align = conv->alignment;\n\t\t\tif (_align > 1) totalsize =\t\t\t\\\n\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\tmaxalign = MAX(maxalign, _align);\n\t\t}\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\tPyDict_SetItem(fields, key, tup);\n\t\tPy_DECREF(tup);\n\t\tPyTuple_SET_ITEM(nameslist, i, key);\n\t\ttotalsize += conv->elsize;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n new->hasobject=hasobject;\n\tif (maxalign > 1) {\n\t\ttotalsize = ((totalsize+maxalign-1)/maxalign)*maxalign;\n\t}\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\treturn new;\n\n fail:\n\tPy_DECREF(nameslist);\n\tPy_DECREF(fields);\n\tif (!try_descr) return NULL;\n\tif (align) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"failed to convert from list of formats \"\\\n\t\t\t\t\"and align cannot be 1 for conversion from \"\\\n\t\t\t\t\"array_descr structure\");\n\t\treturn NULL;\n\t}\n\tPyErr_Clear();\n\treturn _convert_from_array_descr(obj);\n}\n\n\n/* comma-separated string */\n/* this is the format developed by the numarray records module */\n/* and implemented by the format parser in that module */\n/* this is an alternative implementation found in the _internal.py \n file patterned after that one -- the approach is to try to convert \n to a list (with tuples if any repeat information is present) \n and then call the _convert_from_list)\n*/\n\nstatic PyArray_Descr *\n_convert_from_commastring(PyObject *obj, int align)\n{\n\tPyObject *listobj;\n\tPyArray_Descr *res;\n\n\tif (!PyString_Check(obj)) return NULL;\n listobj = PyObject_CallMethod(_numpy_internal, \"_commastring\",\n\t\t\t\t \"O\", obj);\n\tif (!listobj) return NULL;\n\tres = _convert_from_list(listobj, align, 0);\n\tPy_DECREF(listobj);\n\tif (!res && !PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_ValueError, \"invalid data-type\");\n\t\treturn NULL;\n\t}\n\treturn res;\n}\n\n\n\n/* a dictionary specifying a data-type\n must have at least two and up to four\n keys These must all be sequences of the same length.\n\n \"names\" --- field names \n \"formats\" --- the data-type descriptors for the field.\n \n Optional:\n\n \"offsets\" --- integers indicating the offset into the \n record of the start of the field.\n\t\t if not given, then \"consecutive offsets\" \n\t\t will be assumed and placed in the dictionary.\n \n \"titles\" --- Allows the use of an additional key\n for the fields dictionary.\n \nAttribute-lookup-based field names merely has to query the fields \ndictionary of the data-descriptor. Any result present can be used\nto return the correct field.\n\nSo, the notion of what is a name and what is a title is really quite\narbitrary. \n\nWhat does distinguish a title, however, is that if it is not None, \nit will be placed at the end of the tuple inserted into the \nfields dictionary.\n\nIf the dictionary does not have \"names\" and \"formats\" entries,\nthen it will be checked for conformity and used directly. \n*/\n\nstatic PyArray_Descr *\n_use_fields_dict(PyObject *obj, int align)\n{\n return (PyArray_Descr *)PyObject_CallMethod(_numpy_internal, \n\t\t\t\t\t\t \"_usefields\", \n\t\t\t\t\t\t \"Oi\", obj, align);\n}\n\nstatic PyArray_Descr *\n_convert_from_dict(PyObject *obj, int align)\n{\n\tPyArray_Descr *new;\n\tPyObject *fields=NULL;\n\tPyObject *names, *offsets, *descrs, *titles, *key;\n\tint n, i;\n\tint totalsize;\n\tint maxalign=0;\n int hasobject=0;\n\t\n\tfields = PyDict_New();\n\tif (fields == NULL) return (PyArray_Descr *)PyErr_NoMemory();\n\t\n\tnames = PyDict_GetItemString(obj, \"names\");\n\tdescrs = PyDict_GetItemString(obj, \"formats\");\n\n\tif (!names || !descrs) {\n\t\tPy_DECREF(fields);\n\t\treturn _use_fields_dict(obj, align);\n\t}\n\tn = PyObject_Length(names);\n\toffsets = PyDict_GetItemString(obj, \"offsets\");\n\ttitles = PyDict_GetItemString(obj, \"titles\");\n\tif ((n > PyObject_Length(descrs)) ||\t\t\t\\\n\t (offsets && (n > PyObject_Length(offsets))) ||\t\\\n\t (titles && (n > PyObject_Length(titles)))) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"all items in the dictionary must have\" \\\n\t\t\t\t\" the same length.\");\n\t\tgoto fail;\n\t}\n\n\ttotalsize = 0;\n\tfor(i=0; i totalsize) totalsize = offset;\n\t\t}\n\t\telse {\n\t\t\tif (align) {\n\t\t\t\tint _align = newdescr->alignment;\n\t\t\t\tif (_align > 1) totalsize =\t\t\\\n\t\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\t\tmaxalign = MAX(maxalign,_align);\n\t\t\t}\n\t\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\n\t\t}\n\t\tif (len == 3) PyTuple_SET_ITEM(tup, 2, item);\n\t\tname = PyObject_GetItem(names, index);\n\t\tPy_DECREF(index);\n\n\t\t/* Insert into dictionary */\n\t\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"name already used as a name or title\");\n\t\t\tret = PY_FAIL;\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) {\n\t\t\tif (PyDict_GetItem(fields, item) != NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"title already used as a name or \" \\\n\t\t\t\t\t\t\" title.\");\n\t\t\t\tret=PY_FAIL;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyDict_SetItem(fields, item, tup);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n if (!hasobject && newdescr->hasobject)\n hasobject = 1;\n\t\ttotalsize += newdescr->elsize;\n\t}\n\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tif (new == NULL) goto fail;\n\tif (maxalign > 1)\n\t\ttotalsize = ((totalsize + maxalign - 1)/maxalign)*maxalign;\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\tkey = PyInt_FromLong(-1);\n if (!PyTuple_Check(names)) {\n names = PySequence_Tuple(names);\n PyDict_SetItem(fields, key, names);\n Py_DECREF(names);\n }\n else PyDict_SetItem(fields, key, names);\n\tPy_DECREF(key);\n\tnew->fields = fields;\n new->hasobject=hasobject;\n\treturn new;\n\n fail:\n\tPy_XDECREF(fields);\n\treturn NULL;\n}\n\n/* \n any object with \n the .fields attribute and/or .itemsize attribute \n (if the .fields attribute does not give\n the total size -- i.e. a partial record naming).\n If itemsize is given it must be >= size computed from fields\n \n The .fields attribute must return a convertible dictionary if \n present. Result inherits from PyArray_VOID.\n*/\n\n\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to NULL\n*/\nstatic int\nPyArray_DescrConverter2(PyObject *obj, PyArray_Descr **at)\n{\n\tif (obj == Py_None) {\n\t\t*at = NULL;\n\t\treturn PY_SUCCEED;\n\t}\n\telse return PyArray_DescrConverter(obj, at);\n}\n\n/* This function takes a Python object representing a type and converts it \n to a the correct PyArray_Descr * structure to describe the type.\n \n Many objects can be used to represent a data-type which in NumPy is\n quite a flexible concept. \n\n This is the central code that converts Python objects to \n Type-descriptor objects that are used throughout numpy.\n */\n\n/* new reference in *at */\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to &LONG_descr\n*/\nstatic int\nPyArray_DescrConverter(PyObject *obj, PyArray_Descr **at)\n{\n char *type;\n int check_num=PyArray_NOTYPE+10;\n\tint len;\n\tPyObject *item;\n\tint elsize = 0;\n\tchar endian = '=';\n\n\t*at=NULL;\n\t\n\t/* default */\n if (obj == Py_None) {\n\t\t*at = PyArray_DescrFromType(PyArray_LONG);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n\tif (PyArray_DescrCheck(obj)) {\n\t\t*at = (PyArray_Descr *)obj;\n\t\tPy_INCREF(*at);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n if (PyType_Check(obj)) {\n\t\tif (PyType_IsSubtype((PyTypeObject *)obj, \n\t\t\t\t &PyGenericArrType_Type)) {\n\t\t\t*at = PyArray_DescrFromTypeObject(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t\telse return PY_FAIL;\n\t\t}\n\t\tcheck_num = PyArray_OBJECT;\n\t\tif (obj == (PyObject *)(&PyInt_Type))\n\t\t\tcheck_num = PyArray_LONG;\n\t\telse if (obj == (PyObject *)(&PyLong_Type))\n\t\t\tcheck_num = PyArray_LONGLONG;\n\t\telse if (obj == (PyObject *)(&PyFloat_Type)) \n\t\t\tcheck_num = PyArray_DOUBLE;\n\t\telse if (obj == (PyObject *)(&PyComplex_Type)) \n\t\t\tcheck_num = PyArray_CDOUBLE;\n\t\telse if (obj == (PyObject *)(&PyBool_Type))\n\t\t\tcheck_num = PyArray_BOOL;\n else if (obj == (PyObject *)(&PyString_Type))\n check_num = PyArray_STRING;\n else if (obj == (PyObject *)(&PyUnicode_Type))\n check_num = PyArray_UNICODE;\n\t\telse if (obj == (PyObject *)(&PyBuffer_Type))\n\t\t\tcheck_num = PyArray_VOID;\n\t\telse {\n\t\t\t*at = _arraydescr_fromobj(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* or a typecode string */\n\n\tif (PyString_Check(obj)) {\n\t\t/* Check for a string typecode. */\n\t\ttype = PyString_AS_STRING(obj);\n\t\tlen = PyString_GET_SIZE(obj);\n\t\tif (len <= 0) goto fail;\n\t\tcheck_num = (int) type[0];\n\t\tif ((char) check_num == '>' || (char) check_num == '<' || \\\n\t\t (char) check_num == '|' || (char) check_num == '=') {\n\t\t\tif (len <= 1) goto fail;\n\t\t\tendian = (char) check_num;\n\t\t\ttype++; len--;\n\t\t\tcheck_num = (int) type[0];\n\t\t\tif (endian == '|') endian = '=';\n\t\t}\n\t\tif (len > 1) {\n\t\t\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\t\t\tfor (i=1;ielsize == 0) && (elsize != 0)) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->elsize = elsize;\n\t}\n\tif (endian != '=' && PyArray_ISNBO(endian)) endian = '='; \n\t\n\tif (endian != '=' && (*at)->byteorder != '|' &&\t\\\n\t (*at)->byteorder != endian) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->byteorder = endian;\n\t}\n\t\n return PY_SUCCEED;\n\n fail:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"data type not understood\");\n\t*at=NULL;\n\treturn PY_FAIL;\n}\t\n\n/*MULTIARRAY_API\n Convert object to endian\n*/\nstatic int\nPyArray_ByteorderConverter(PyObject *obj, char *endian)\n{\n\tchar *str;\n\t*endian = PyArray_SWAP;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Byteorder string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\t*endian = str[0];\n\tif (str[0] != PyArray_BIG && str[0] != PyArray_LITTLE &&\t\\\n\t str[0] != PyArray_NATIVE) {\n\t\tif (str[0] == 'b' || str[0] == 'B')\n\t\t\t*endian = PyArray_BIG;\n\t\telse if (str[0] == 'l' || str[0] == 'L')\n\t\t\t*endian = PyArray_LITTLE;\n\t\telse if (str[0] == 'n' || str[0] == 'N')\n\t\t\t*endian = PyArray_NATIVE;\n\t\telse if (str[0] == 'i' || str[0] == 'I')\n\t\t\t*endian = PyArray_IGNORE;\n\t\telse if (str[0] == 's' || str[0] == 'S')\n\t\t\t*endian = PyArray_SWAP;\n\t\telse {\n\t\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t\t \"%s is an unrecognized byteorder\",\n\t\t\t\t str);\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Convert object to sort kind \n*/\nstatic int\nPyArray_SortkindConverter(PyObject *obj, PyArray_SORTKIND *sortkind)\n{\n\tchar *str;\n\t*sortkind = PyArray_QUICKSORT;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Sort kind string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\tif (str[0] == 'q' || str[0] == 'Q')\n\t\t*sortkind = PyArray_QUICKSORT;\n\telse if (str[0] == 'h' || str[0] == 'H')\n\t\t*sortkind = PyArray_HEAPSORT;\n\telse if (str[0] == 'm' || str[0] == 'M')\n\t\t*sortkind = PyArray_MERGESORT;\n\telse if (str[0] == 't' || str[0] == 'T')\n\t\t*sortkind = PyArray_TIMSORT;\n\telse {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"%s is an unrecognized kind of sort\",\n\t\t\t str);\n\t\treturn PY_FAIL;\n\t}\n\treturn PY_SUCCEED;\n}\n\n\n/* This function returns true if the two typecodes are \n equivalent (same basic kind and same itemsize).\n*/\n\n/*MULTIARRAY_API*/\nstatic Bool\nPyArray_EquivTypes(PyArray_Descr *typ1, PyArray_Descr *typ2)\n{\n\tregister int typenum1=typ1->type_num;\n\tregister int typenum2=typ2->type_num;\n\tregister int size1=typ1->elsize;\n\tregister int size2=typ2->elsize;\n\n\tif (size1 != size2) return FALSE;\n\tif (typ1->fields != typ2->fields) return FALSE;\n\tif (PyArray_ISNBO(typ1->byteorder) != PyArray_ISNBO(typ2->byteorder))\n\t\treturn FALSE;\n\n\tif (typenum1 == PyArray_VOID || \\\n\t typenum2 == PyArray_VOID) {\n\t\treturn ((typenum1 == typenum2) && \n\t\t\t(typ1->typeobj == typ2->typeobj) &&\n\t\t\t(typ1->fields == typ2->fields));\n\t}\n\treturn (typ1->kind == typ2->kind);\n}\n\n/*** END C-API FUNCTIONS **/\n\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\n\n\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_fromobject[] = \"array(object, dtype=None, copy=1, fortran=0, \"\\\n \"subok=0,ndmin=0)\\n\"\\\n \"will return a new array formed from the given object type given.\\n\"\\\n \"Object can be anything with an __array__ method, or any object\\n\"\\\n \"exposing the array interface, or any (nested) sequence.\\n\"\\\n \"If no type is given, then the type will be determined as the\\n\"\\\n \"minimum type required to hold the objects in the sequence.\\n\"\\\n \"If copy is zero and sequence is already an array with the right \\n\"\\\n \"type, a reference will be returned. If the sequence is an array,\\n\"\\\n \"type can be used only to upcast the array. For downcasting \\n\"\\\n \"use .astype(t) method. If subok is true, then subclasses of the\\n\"\\\n \"array may be returned. Otherwise, a base-class ndarray is returned\\n\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\n\nstatic PyObject *\n_array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n{\n\tPyObject *op, *ret=NULL;\n\tstatic char *kwd[]= {\"object\", \"dtype\", \"copy\", \"fortran\", \"subok\", \n\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\n\tPyArray_Descr *type=NULL;\n\tPyArray_Descr *oldtype=NULL;\n\tBool fortran=FALSE;\n\tint flags=0;\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&i\", kwd, &op, \n\t\t\t\t\tPyArray_DescrConverter2,\n &type, \n\t\t\t\t\tPyArray_BoolConverter, ©, \n\t\t\t\t\tPyArray_BoolConverter, &fortran,\n PyArray_BoolConverter, &subok, \n\t\t\t\t\t&ndmin)) \n\t\treturn NULL;\n\n\t/* fast exit if simple call */\n\tif (PyArray_CheckExact(op)) {\n\t\tif (type==NULL) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\tret = op;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op, \n\t\t\t\t\t\t fortran);\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\t/* One more chance */\n\t\toldtype = PyArray_DESCR(op);\n\t\tif (PyArray_EquivTypes(oldtype, type)) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\tret = op;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op,\n\t\t\t\t\t\t fortran);\n\t\t\t\tif (oldtype == type) return ret;\n\t\t\t\tPy_INCREF(oldtype);\n\t\t\t\tPy_DECREF(PyArray_DESCR(ret));\n\t\t\t\tPyArray_DESCR(ret) = oldtype;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (copy) {\n\t\tflags = ENSURECOPY;\n\t}\n\tif (fortran) {\n\t\tflags |= FORTRAN;\n\t}\n if (!subok) {\n flags |= ENSUREARRAY;\n }\n\n\tif ((ret = PyArray_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\n}\n\n/* accepts NULL type */\n/* steals referenct to type */\n/*MULTIARRAY_API\n Empty\n*/\nstatic PyObject *\nPyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n \n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type, nd, dims, \n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n PyArray_FillObjectArray(ret, Py_None);\n\t}\n\treturn (PyObject *)ret;\n}\n\n\nstatic char doc_empty[] = \"empty((d1,...,dn),dtype=int,fortran=0) will return a new array\\n of shape (d1,...,dn) and given type with all its entries uninitialized. This can be faster than zeros.\";\n\nstatic PyObject *\narray_empty(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter, &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Empty(shape.len, shape.ptr, typecode, fortran); \n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_scalar[] = \"scalar(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype corresponds to an OBJECT descriptor, then obj can be any object, otherwise obj must be a string. If obj is not given it will be interpreted as None for object type and zeros for all other types.\";\n\nstatic PyObject *\narray_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"dtype\",\"obj\", NULL};\n\tPyArray_Descr *typecode;\n\tPyObject *obj=NULL;\n\tint alloc=0;\n\tvoid *dptr;\n\tPyObject *ret;\n\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|O\",\n\t\t\t\t\t kwlist, &PyArrayDescr_Type, \n\t\t\t\t\t &typecode,\n\t\t\t\t\t &obj)) \n\t\treturn NULL;\n\t\t\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\t\t\\\n\t\t\t\t\"itemsize cannot be zero\");\n\t\treturn NULL;\n\t}\n\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (obj == NULL) obj = Py_None;\n\t\tdptr = &obj;\n\t}\n\telse {\n\t\tif (obj == NULL) {\n\t\t\tdptr = _pya_malloc(typecode->elsize);\n\t\t\tif (dptr == NULL) {\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemset(dptr, '\\0', typecode->elsize);\n\t\t\talloc = 1;\n\t\t}\n\t\telse {\n\t\t\tif (!PyString_Check(obj)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"initializing object must \"\\\n\t\t\t\t\t\t\"be a string\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tif (PyString_GET_SIZE(obj) < typecode->elsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"initialization string is too\"\\\n\t\t\t\t\t\t\" small\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdptr = PyString_AS_STRING(obj);\n\t\t}\n\t}\n\n\tret = PyArray_Scalar(dptr, typecode, NULL);\n\t\n\t/* free dptr which contains zeros */\n\tif (alloc) _pya_free(dptr);\n\treturn ret;\n}\n\n\n/* steal a reference */\n/* accepts NULL type */\n/*MULTIARRAY_API\n Zeros\n*/\nstatic PyObject *\nPyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n\tintp n;\n\n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type,\n\t\t\t\t\t\t nd, dims, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n\t\tPyObject *zero = PyInt_FromLong(0);\n PyArray_FillObjectArray(ret, zero);\n Py_DECREF(zero);\n\t}\n\telse {\n\t\tn = PyArray_NBYTES(ret);\n\t\tmemset(ret->data, 0, n);\n\t}\n\treturn (PyObject *)ret;\n\n}\n\nstatic char doc_zeros[] = \"zeros((d1,...,dn),dtype=int,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.\";\n\n\nstatic PyObject *\narray_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL}; /* XXX ? */\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Zeros(shape.len, shape.ptr, typecode, (int) fortran);\n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_set_typeDict[] = \"set_typeDict(dict) set the internal \"\\\n\t\"dictionary that can look up an array type using a registered \"\\\n\t\"code\";\n\nstatic PyObject *\narray_set_typeDict(PyObject *ignored, PyObject *args)\n{\n\tPyObject *dict;\n\tif (!PyArg_ParseTuple(args, \"O\", &dict)) return NULL;\n\tPy_XDECREF(typeDict); /* Decrement old reference (if any)*/\n\ttypeDict = dict;\n\tPy_INCREF(dict); /* Create an internal reference to it */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\n\t\n\titemsize = dtype->elsize;\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"zero-valued itemsize\");\n\t\tPy_DECREF(dtype);\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_fromString[] = \"fromstring(string, dtype=int, count=-1, sep='') returns a new 1d array initialized from the raw binary data in string. If count is positive, the new array will have count elements, otherwise it's size is determined by the size of string. If sep is not empty then the string is interpreted in ASCII mode and converted to the desired number type using sep as the separator between elements (extra whitespace is ignored).\";\n\nstatic PyObject *\narray_fromString(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tchar *data;\n\tlonglong nin=-1;\n\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", kwlist, \n\t\t\t\t\t &data, &s, \n\t\t\t\t\t PyArray_DescrConverter, &descr,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\n}\n\n/* This needs an open file object and reads it in directly. \n memory-mapped files handled differently through buffer interface.\n\nfile pointer number in resulting 1d array \n(can easily reshape later, -1 for to end of file)\ntype of array\nsep is a separator string for character-based data (or NULL for binary)\n \" \" means whitespace\n*/\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep)\n{\n\tPyArrayObject *r;\n\tsize_t nread = 0;\n\tPyArray_ScanFunc *scan;\n\tBool binary;\n\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"0-sized elements.\");\n\t\tPy_DECREF(typecode);\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\n\tif (num == -1 && binary) { /* Get size for binary file*/\n\t\tintp start, numbytes;\n\t\tstart = (intp )ftell(fp);\n\t\tfseek(fp, 0, SEEK_END);\n\t\tnumbytes = (intp )ftell(fp) - start;\n\t\trewind(fp);\n\t\tif (numbytes == -1) {\n\t\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\t\"could not seek in file\");\n\t\t\tPy_DECREF(typecode);\n\t\t\treturn NULL;\n\t\t}\n\t\tnum = numbytes / typecode->elsize;\n\t}\n\t\n\tif (binary) { /* binary data */\n\t\tr = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t 0, NULL);\n\t\tif (r==NULL) return NULL;\n\t\tnread = fread(r->data, typecode->elsize, num, fp);\n\t}\n\telse { /* character reading */\n\t\tintp i;\n\t\tchar *dptr;\n\t\tint done=0;\n\n\t\tscan = typecode->f->scanfunc;\n\t\tif (scan == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character files with that \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(typecode);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (num != -1) { /* number to read is known */\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode, \n\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\tdptr = r->data;\n\t\t\tfor (i=0; i < num; i++) {\n\t\t\t\tif (done) break;\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\t\t\t\tif (done < -2) break;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\telse { /* we have to watch for the end of the file and \n\t\t\t reallocate at the end */\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * typecode->elsize;\n\t\t\tdptr = r->data;\n\t\t\twhile (!done) {\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\n\t\t\t\t/* end of file reached trying to \n\t\t\t\t scan value. done is 1 or 2\n\t\t\t\t if end of file reached trying to\n\t\t\t\t scan separator. Still good value.\n\t\t\t\t*/\n\t\t\t\tif (done < -2) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t\tif (!done && thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tr->data = PyDataMem_RENEW(r->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = r->data + (totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tr->data = PyDataMem_RENEW(r->data, nread*r->descr->elsize);\n\t\t\tPyArray_DIM(r,0) = nread;\n\t\t\tnum = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\tif (nread < num) {\n\t\tfprintf(stderr, \"%ld items requested but only %ld read\\n\", \n\t\t\t(long) num, (long) nread);\n\t\tr->data = PyDataMem_RENEW(r->data, nread * r->descr->elsize);\n\t\tPyArray_DIM(r,0) = nread;\n\t}\n\treturn (PyObject *)r;\n}\n\nstatic char doc_fromfile[] = \\\n\t\"fromfile(file=, dtype=int, count=-1, sep='')\\n\"\t\\\n\t\"\\n\"\\\n\t\" Return an array of the given data type from a \\n\"\\\n\t\" (text or binary) file. The file argument can be an open file\\n\"\\\n\t\" or a string with the name of a file to read from. If\\n\"\\\n\t\" count==-1, then the entire file is read, otherwise count is\\n\"\\\n\t\" the number of items of the given type read in. If sep is ''\\n\"\\\n\t\" then read a binary file, otherwise it gives the separator\\n\"\\\n\t\" between elements in a text file.\\n\"\\\n\t\"\\n\"\\\n\t\" WARNING: This function should be used sparingly, as it is not\\n\"\\\n\t\" a platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to read in simply-formatted or binary data quickly.\";\n\nstatic PyObject *\narray_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *file=NULL, *ret;\n\tFILE *fp;\n\tchar *sep=\"\";\n\tchar *mode=NULL;\n\tlonglong nin=-1;\n\tstatic char *kwlist[] = {\"file\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *type=NULL;\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Ls\", kwlist, \n\t\t\t\t\t &file,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\tif (type == NULL) type = PyArray_DescrFromType(PyArray_LONG);\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"rb\";\n\t\telse mode=\"r\";\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), mode);\n\t\tif (file==NULL) return NULL;\n\t}\n\telse {\n\t\tPy_INCREF(file);\n\t}\n\tfp = PyFile_AsFile(file);\n\tif (fp == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\"first argument must be an open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_FromFile(fp, type, (intp) nin, sep);\n\tPy_DECREF(file);\n\treturn ret;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, \n\t\t intp count, intp offset) \n{\n\tPyArrayObject *ret;\n\tchar *data;\n\tint ts;\n\tintp s, n;\n\tint itemsize;\n\tint write=1;\n\n\n\tif (type->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot create an OBJECT array from memory\"\\\n\t\t\t\t\" buffer\");\n\t\tPy_DECREF(type);\n\t\treturn NULL;\n\t}\n\tif (type->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"itemsize cannot be zero in type\");\n\t\tPy_DECREF(type);\n\t\treturn NULL; \t\t\n\t}\n\n\tif (buf->ob_type->tp_as_buffer == NULL || \\\n\t (buf->ob_type->tp_as_buffer->bf_getwritebuffer == NULL &&\t\\\n\t buf->ob_type->tp_as_buffer->bf_getreadbuffer == NULL)) {\n\t\tPyObject *newbuf;\n\t\tnewbuf = PyObject_GetAttrString(buf, \"__buffer__\");\n\t\tif (newbuf == NULL) {Py_DECREF(type); return NULL;}\n\t\tbuf = newbuf;\n\t}\n\telse {Py_INCREF(buf);}\n\n\tif (PyObject_AsWriteBuffer(buf, (void *)&data, &ts)==-1) {\n\t\twrite = 0;\n\t\tPyErr_Clear();\n\t\tif (PyObject_AsReadBuffer(buf, (void *)&data, &ts)==-1) {\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((offset < 0) || (offset >= ts)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"offset must be positive and smaller than %\"\n\t\t\t INTP_FMT, (intp)ts);\n\t}\n\n\tdata += offset;\n\ts = (intp)ts - offset;\n\tn = (intp)count;\n\titemsize = type->elsize;\n\t\n\tif (n < 0 ) {\n\t\tif (s % itemsize != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tn = s/itemsize;\n\t} else {\n\t\tif (s < n*itemsize) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t type, \n\t\t\t\t\t\t\t 1, &n, \n\t\t\t\t\t\t\t NULL, data, \n\t\t\t\t\t\t\t DEFAULT_FLAGS,\n\t\t\t\t\t\t\t NULL)) == NULL) {\n\t\tPy_DECREF(buf);\n\t\treturn NULL;\n\t}\n\t\n\tif (!write) ret->flags &= ~WRITEABLE;\n\n\t/* Store a reference for decref on deallocation */\n\tret->base = buf;\n\tPyArray_UpdateFlags(ret, ALIGNED);\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_frombuffer[] = \\\n\t\"frombuffer(buffer=, dtype=int, count=-1, offset=0)\\n\"\\\n\t\"\\n\"\t\t\t\t\t\t\t\t\\\n\t\" Returns a 1-d array of data type dtype from buffer. The buffer\\n\"\\\n\t\" argument must be an object that exposes the buffer interface.\\n\"\\\n\t\" If count is -1 then the entire buffer is used, otherwise, count\\n\"\\\n\t\" is the size of the output. If offset is given then jump that\\n\"\\\n\t\" far into the buffer. If the buffer has data that is out\\n\" \\\n\t\" not in machine byte-order, than use a propert data type\\n\"\\\n\t\" descriptor. The data will not\\n\" \\\n\t\" be byteswapped, but the array will manage it in future\\n\"\\\n\t\" operations.\\n\";\n\nstatic PyObject *\narray_frombuffer(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *obj=NULL;\n\tlonglong nin=-1, offset=0;\n\tstatic char *kwlist[] = {\"buffer\", \"dtype\", \"count\", \"offset\", NULL};\n\tPyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&LL\", kwlist, \n\t\t\t\t\t &obj,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &offset)) {\n\t\treturn NULL;\n\t}\n\tif (type==NULL)\n\t\ttype = PyArray_DescrFromType(PyArray_LONG);\n\t\n\treturn PyArray_FromBuffer(obj, type, (intp)nin, (intp)offset);\n}\n\n\nstatic char doc_concatenate[] = \"concatenate((a1,a2,...),axis=None).\";\n\nstatic PyObject *\narray_concatenate(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *a0;\n\tint axis=0;\n\tstatic char *kwlist[] = {\"seq\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist,\n\t\t\t\t\t &a0,\n\t\t\t\t\t PyArray_AxisConverter, &axis))\n\t\treturn NULL;\n\treturn PyArray_Concatenate(a0, axis);\n}\n\nstatic char doc_innerproduct[] = \\\n\t\"inner(a,b) returns the dot product of two arrays, which has\\n\"\\\n\t\"shape a.shape[:-1] + b.shape[:-1] with elements computed by\\n\" \\\n\t\"the product of the elements from the last dimensions of a and b.\";\n\nstatic PyObject *array_innerproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *b0, *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a0, &b0)) return NULL;\n\t\n\treturn _ARET(PyArray_InnerProduct(a0, b0));\n}\n\nstatic char doc_matrixproduct[] = \\\n\t\"dot(a,v) returns matrix-multiplication between a and b. \\n\"\\\n\t\"The product-sum is over the last dimension of a and the \\n\"\\\n\t\"second-to-last dimension of b.\";\n\nstatic PyObject *array_matrixproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *v, *a;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a, &v)) return NULL;\n\t\n\treturn _ARET(PyArray_MatrixProduct(a, v));\n}\n\nstatic char doc_fastCopyAndTranspose[] = \"_fastCopyAndTranspose(a)\";\n\nstatic PyObject *array_fastCopyAndTranspose(PyObject *dummy, PyObject *args) {\n\tPyObject *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &a0)) return NULL;\n\t\n\treturn _ARET(PyArray_CopyAndTranspose(a0));\n}\n\nstatic char doc_correlate[] = \"cross_correlate(a,v, mode=0)\";\n\nstatic PyObject *array_correlate(PyObject *dummy, PyObject *args, PyObject *kwds) {\n\tPyObject *shape, *a0;\n\tint mode=0;\n\tstatic char *kwlist[] = {\"a\", \"v\", \"mode\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO|i\", kwlist, \n\t\t\t\t\t &a0, &shape, &mode)) return NULL;\n\t\n\treturn PyArray_Correlate(a0, shape, mode);\n}\n\n\n/*MULTIARRAY_API\n Arange, \n*/\nstatic PyObject *\nPyArray_Arange(double start, double stop, double step, int type_num)\n{\n\tintp length;\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *obj;\n\tint ret;\n\n\tlength = (intp ) ceil((stop - start)/step);\n \n\tif (length <= 0) {\n\t\tlength = 0;\n\t\treturn PyArray_New(&PyArray_Type, 1, &length, type_num,\n\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t}\n\n\trange = PyArray_New(&PyArray_Type, 1, &length, type_num, \n\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (range == NULL) return NULL;\n\n\tfuncs = PyArray_DESCR(range)->f; \n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tobj = PyFloat_FromDouble(start);\n\tret = funcs->setitem(obj, PyArray_DATA(range), (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 1) return range;\n\n\tobj = PyFloat_FromDouble(start + step);\n\tret = funcs->setitem(obj, PyArray_BYTES(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 2) return range;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\treturn NULL;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\t\n\treturn range;\n\n fail:\n\tPy_DECREF(range);\n\treturn NULL;\n}\n\n/* the formula is \n len = (intp) ceil((start - stop) / step);\n*/\nstatic intp\n_calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, int cmplx)\n{\n\tintp len;\n\tPyObject *val;\n\tdouble value;\n\t\n\t*next = PyNumber_Subtract(stop, start);\n\tif (!(*next)) return -1;\n\tval = PyNumber_TrueDivide(*next, step);\n\tPy_DECREF(*next); *next=NULL;\n\tif (!val) return -1;\n\tif (cmplx && PyComplex_Check(val)) {\n\t\tvalue = PyComplex_RealAsDouble(val);\n\t\tif (error_converting(value)) {Py_DECREF(val); return -1;}\n\t\tlen = (intp) ceil(value);\n\t\tvalue = PyComplex_ImagAsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = MIN(len, (intp) ceil(value));\n\t}\n\telse {\n\t\tvalue = PyFloat_AsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = (intp) ceil(value);\n\t}\n\t\n\tif (len > 0) {\n\t\t*next = PyNumber_Add(start, step);\n\t\tif (!next) return -1;\n\t}\n\treturn len;\n}\n\n/* this doesn't change the references */\n/*MULTIARRAY_API\n ArangeObj,\n*/\nstatic PyObject *\nPyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr *dtype) \n{\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *next;\n\tintp length;\n\n\tif (!dtype) {\n\t\tPyArray_Descr *deftype;\n\t\tPyArray_Descr *newtype;\n\t\tdeftype = PyArray_DescrFromType(PyArray_LONG);\n\t\tnewtype = PyArray_DescrFromObject(start, deftype);\n\t\tPy_DECREF(deftype);\n\t\tdeftype = newtype;\n\t\tif (stop && stop != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(stop, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tif (step && step != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(step, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tdtype = deftype;\n\t}\n\telse Py_INCREF(dtype);\n\n\tif (!step || step == Py_None) {\n\t\tstep = PyInt_FromLong(1);\n\t}\n\telse Py_XINCREF(step);\n\n\tif (!stop || stop == Py_None) {\n\t\tstop = start;\n\t\tstart = PyInt_FromLong(0);\n\t}\n\telse Py_INCREF(start);\n\n\t/* calculate the length and next = start + step*/\n\tlength = _calc_length(start, stop, step, &next, \n\t\t\t PyTypeNum_ISCOMPLEX(dtype->type_num));\n\n\tif (PyErr_Occurred()) {Py_DECREF(dtype); goto fail;}\n\tif (length <= 0) {\n\t\tlength = 0;\n\t\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\t\tPy_DECREF(step); Py_DECREF(start); return range;\n\t}\n\n\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\tif (range == NULL) goto fail;\n\n\tfuncs = PyArray_DESCR(range)->f;\n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tif (funcs->setitem(start, PyArray_DATA(range), (PyArrayObject *)range) < 0)\n\t\tgoto fail;\n\tif (length == 1) goto finish;\n\tif (funcs->setitem(next, PyArray_BYTES(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range) < 0) goto fail;\n\tif (length == 2) goto finish;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\tgoto fail;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\n finish:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_DECREF(next);\n\treturn range;\n\t\n fail:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_XDECREF(next);\n\treturn NULL;\n}\n\n\nstatic char doc_arange[] = \n\"arange([start,] stop[, step,], dtype=None)\\n\\n\"\n\"For integer arguments, just like range() except it returns an array whose type can\\n\"\n\"be specified by the keyword argument dtype.\\n\\n\"\n\"If dtype is not specified, the type of the result is deduced from the type of the\\n\"\n\"arguments.\\n\\n\"\n\"For floating point arguments, the length of the result is ceil((stop - start)/step).\\n\"\n\"This rule may result in the last element of the result be greater than stop.\";\n\nstatic PyObject *\narray_arange(PyObject *ignored, PyObject *args, PyObject *kws) {\n\tPyObject *o_start=NULL, *o_stop=NULL, *o_step=NULL;\n\tstatic char *kwd[]= {\"start\", \"stop\", \"step\", \"dtype\", NULL};\n\tPyArray_Descr *typecode=NULL;\n\t\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|OOO&\", kwd, &o_start,\n\t\t\t\t\t&o_stop, &o_step, \n\t\t\t\t\tPyArray_DescrConverter2,\n\t\t\t\t\t&typecode)) \n\t\treturn NULL;\n\n\treturn PyArray_ArangeObj(o_start, o_stop, o_step, typecode);\n}\n\n/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\n}\n\nstatic char \ndoc_set_string_function[] = \"set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.\";\n\nstatic PyObject *\narray_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *op;\n\tint repr=1;\n\tstatic char *kwlist[] = {\"f\", \"repr\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|i\", kwlist, \n\t\t\t\t\t&op, &repr)) return NULL; \n\tif (!PyCallable_Check(op)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"Argument must be callable.\");\n\t\treturn NULL;\n\t}\n\tPyArray_SetStringFunction(op, repr);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char \ndoc_set_ops_function[] = \"set_numeric_ops(op=func, ...) sets some or all of the number methods for all array objects. Don't forget **dict can be used as the argument list. Returns the functions that were replaced -- can be stored and set later.\";\n\nstatic PyObject *\narray_set_ops_function(PyObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *oldops=NULL;\n\t\n\tif ((oldops = PyArray_GetNumericOps())==NULL) return NULL;\n\n\t/* Should probably ensure that objects are at least callable */\n\t/* Leave this to the caller for now --- error will be raised\n\t later when use is attempted \n\t*/\n\tif (kwds && PyArray_SetNumericOps(kwds) == -1) {\n\t\tPy_DECREF(oldops);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"one or more objects not callable\");\n\t\treturn NULL;\n\t}\n\treturn oldops;\n}\n\n\n/*MULTIARRAY_API\n Where\n*/\nstatic PyObject *\nPyArray_Where(PyObject *condition, PyObject *x, PyObject *y)\n{\n\tPyArrayObject *arr;\n\tPyObject *tup=NULL, *obj=NULL;\n\tPyObject *ret=NULL, *zero=NULL;\n\n\n\tarr = (PyArrayObject *)PyArray_FromAny(condition, NULL, 0, 0, 0, NULL);\n\tif (arr == NULL) return NULL;\n\n\tif ((x==NULL) && (y==NULL)) {\n\t\tret = PyArray_Nonzero(arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\n\tif ((x==NULL) || (y==NULL)) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \"either both or neither \"\n\t\t\t\t\"of x and y should be given\");\n\t\treturn NULL;\n\t}\n\n\n\tzero = PyInt_FromLong((long) 0);\n\n\tobj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, \n\t\t\t\t\t\t\t\tn_ops.not_equal));\n\tPy_DECREF(zero);\n\tPy_DECREF(arr);\n\tif (obj == NULL) return NULL;\n\n\ttup = Py_BuildValue(\"(OO)\", y, x);\n\tif (tup == NULL) {Py_DECREF(obj); return NULL;}\n\n\tret = PyArray_Choose((PyAO *)obj, tup);\n\n\tPy_DECREF(obj);\n\tPy_DECREF(tup);\n\treturn ret;\n}\n\nstatic char doc_where[] = \"where(condition, | x, y) is shaped like condition\"\\\n\t\" and has elements of x and y where condition is respectively true or\"\\\n\t\" false. If x or y are not given, then it is equivalent to\"\\\n\t\" nonzero(condition).\";\n\nstatic PyObject *\narray_where(PyObject *ignored, PyObject *args)\n{\n\tPyObject *obj=NULL, *x=NULL, *y=NULL;\n\t\n\tif (!PyArg_ParseTuple(args, \"O|OO\", &obj, &x, &y)) return NULL;\n\n\treturn PyArray_Where(obj, x, y);\n\n}\n\nstatic char doc_lexsort[] = \"lexsort(keys=, axis=-1) returns an array of indexes\"\\\n\t\" similar to argsort except the sorting is done using the provided sorting\"\\\n\t\" keys. First the sort is done using key[0], then the resulting list of\"\\\n\t\" indexes is further manipulated by sorting on key[0]. And so forth\"\\\n\t\" The result is a sort on multiple keys. If the keys represented columns\" \\\n\t\" of a spread-sheet, for example, this would sort using multiple columns.\"\\\n\t\" The keys argument must be a tuple of things that can be converted to \"\\\n\t\" arrays of the same shape.\";\n\nstatic PyObject *\narray_lexsort(PyObject *ignored, PyObject *args, PyObject *kwds)\n{\n\tint axis=-1;\n\tPyObject *obj;\n\tstatic char *kwlist[] = {\"keys\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|i\", kwlist, \n\t\t\t\t\t &PyTuple_Type, &obj, &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_LexSort(obj, axis));\n}\n\n#undef _ARET\n\n\nstatic char doc_register_dtype[] = \\\n\t\"register_dtype(a) registers a new type object -- gives it a typenum\";\n\nstatic PyObject *\narray_register_dtype(PyObject *dummy, PyObject *args)\n{\n\tPyObject *dtype;\n\tint ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &dtype)) return NULL;\n\t\n\tret = PyArray_RegisterDataType((PyTypeObject *)dtype);\n\tif (ret < 0)\n\t\treturn NULL;\n\treturn PyInt_FromLong((long) ret);\n}\n\nstatic char doc_can_cast_safely[] = \\\n\t\"can_cast_safely(from=d1, to=d2) returns True if data type d1 \"\\\n\t\"can be cast to data type d2 without losing precision.\";\n\nstatic PyObject *\narray_can_cast_safely(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *d1=NULL;\n\tPyArray_Descr *d2=NULL;\n\tBool ret;\n\tPyObject *retobj;\n\tstatic char *kwlist[] = {\"from\", \"to\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O&O&\", kwlist, \n\t\t\t\t\tPyArray_DescrConverter, &d1,\n\t\t\t\t\tPyArray_DescrConverter, &d2))\n\t\treturn NULL;\n\tif (d1 == NULL || d2 == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"did not understand one of the types; \"\t\\\n\t\t\t\t\"'None' not accepted\");\n\t\treturn NULL;\n\t}\n\t\t\n\tret = PyArray_CanCastTo(d1, d2);\n\tretobj = (ret ? Py_True : Py_False);\n\tPy_INCREF(retobj);\n\treturn retobj;\n}\n\nstatic char doc_new_buffer[] = \\\n\t\"newbuffer(size) return a new uninitialized buffer object of size \"\n\t\"bytes\";\n\nstatic PyObject *\nnew_buffer(PyObject *dummy, PyObject *args)\n{\n\tint size;\n\n\tif(!PyArg_ParseTuple(args, \"i\", &size))\n\t\treturn NULL;\n\t\n\treturn PyBuffer_New(size);\n}\n\nstatic char doc_buffer_buffer[] = \\\n\t\"getbuffer(obj [,offset[, size]]) create a buffer object from the \"\\\n\t\"given object\\n referencing a slice of length size starting at \"\\\n\t\"offset. Default\\n is the entire buffer. A read-write buffer is \"\\\n\t\"attempted followed by a read-only buffer.\";\n\nstatic PyObject *\nbuffer_buffer(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj;\n\tint offset=0, size=Py_END_OF_BUFFER, n;\n\tvoid *unused;\n\tstatic char *kwlist[] = {\"object\", \"offset\", \"size\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ii\", kwlist, \n\t\t\t\t\t &obj, &offset, &size))\n\t\treturn NULL;\n\n\n\tif (PyObject_AsWriteBuffer(obj, &unused, &n) < 0) {\n\t\tPyErr_Clear();\n\t\treturn PyBuffer_FromObject(obj, offset, size);\t\t\n\t}\n\telse\n\t\treturn PyBuffer_FromReadWriteObject(obj, offset, size);\n}\n\n\nstatic struct PyMethodDef array_module_methods[] = {\n\t{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\n\t{\"set_string_function\", (PyCFunction)array_set_string_function, \n\t METH_VARARGS|METH_KEYWORDS, doc_set_string_function},\n\t{\"set_numeric_ops\", (PyCFunction)array_set_ops_function,\n\t METH_VARARGS|METH_KEYWORDS, doc_set_ops_function},\n\t{\"set_typeDict\", (PyCFunction)array_set_typeDict,\n\t METH_VARARGS, doc_set_typeDict},\n\n\t{\"array\",\t(PyCFunction)_array_fromobject, \n\t METH_VARARGS|METH_KEYWORDS, doc_fromobject},\n\t{\"arange\", (PyCFunction)array_arange, \n\t METH_VARARGS|METH_KEYWORDS, doc_arange},\n\t{\"zeros\",\t(PyCFunction)array_zeros, \n\t METH_VARARGS|METH_KEYWORDS, doc_zeros},\n\t{\"empty\",\t(PyCFunction)array_empty, \n\t METH_VARARGS|METH_KEYWORDS, doc_empty},\n\t{\"scalar\", (PyCFunction)array_scalar,\n\t METH_VARARGS|METH_KEYWORDS, doc_scalar},\n\t{\"where\", (PyCFunction)array_where,\n\t METH_VARARGS, doc_where},\n\t{\"lexsort\", (PyCFunction)array_lexsort,\n\t METH_VARARGS | METH_KEYWORDS, doc_lexsort},\n\t{\"fromstring\",(PyCFunction)array_fromString,\n\t METH_VARARGS|METH_KEYWORDS, doc_fromString},\n\t{\"concatenate\", (PyCFunction)array_concatenate, \n\t METH_VARARGS|METH_KEYWORDS, doc_concatenate},\n\t{\"inner\", (PyCFunction)array_innerproduct, \n\t METH_VARARGS, doc_innerproduct}, \n\t{\"dot\", (PyCFunction)array_matrixproduct, \n\t METH_VARARGS, doc_matrixproduct}, \n\t{\"_fastCopyAndTranspose\", (PyCFunction)array_fastCopyAndTranspose, \n\t METH_VARARGS, doc_fastCopyAndTranspose},\n\t{\"correlate\", (PyCFunction)array_correlate, \n\t METH_VARARGS | METH_KEYWORDS, doc_correlate},\n\t{\"frombuffer\", (PyCFunction)array_frombuffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_frombuffer},\n\t{\"fromfile\", (PyCFunction)array_fromfile,\n\t METH_VARARGS | METH_KEYWORDS, doc_fromfile},\n\t{\"register_dtype\", (PyCFunction)array_register_dtype,\n\t METH_VARARGS, doc_register_dtype},\n\t{\"can_cast\", (PyCFunction)array_can_cast_safely,\n\t METH_VARARGS | METH_KEYWORDS, doc_can_cast_safely},\t\t\n\t{\"newbuffer\", (PyCFunction)new_buffer,\n\t METH_VARARGS, doc_new_buffer},\t\n\t{\"getbuffer\", (PyCFunction)buffer_buffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_buffer_buffer},\t\n\t{NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n#include \"__multiarray_api.c\"\n\n/* Establish scalar-type hierarchy */\n\n/* For dual inheritance we need to make sure that the objects being\n inherited from have the tp->mro object initialized. This is\n not necessarily true for the basic type objects of Python (it is \n checked for single inheritance but not dual in PyType_Ready).\n\n Thus, we call PyType_Ready on the standard Python Types, here.\n*/ \nstatic int\nsetup_scalartypes(PyObject *dict)\n{\n\n\tinitialize_numeric_types();\n\n if (PyType_Ready(&PyBool_Type) < 0) return -1;\n if (PyType_Ready(&PyInt_Type) < 0) return -1;\n if (PyType_Ready(&PyFloat_Type) < 0) return -1;\n if (PyType_Ready(&PyComplex_Type) < 0) return -1;\n if (PyType_Ready(&PyString_Type) < 0) return -1;\n if (PyType_Ready(&PyUnicode_Type) < 0) return -1;\n\n#define SINGLE_INHERIT(child, parent) \\\n Py##child##ArrType_Type.tp_base = &Py##parent##ArrType_Type;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) {\t\t\\\n PyErr_Print(); \\\n PyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1;\t\t\t\t\t\t\\\n }\n \n if (PyType_Ready(&PyGenericArrType_Type) < 0)\n return -1;\n\n SINGLE_INHERIT(Number, Generic);\n SINGLE_INHERIT(Integer, Number);\n SINGLE_INHERIT(Inexact, Number);\n SINGLE_INHERIT(SignedInteger, Integer);\n SINGLE_INHERIT(UnsignedInteger, Integer);\n SINGLE_INHERIT(Floating, Inexact);\n SINGLE_INHERIT(ComplexFloating, Inexact);\n SINGLE_INHERIT(Flexible, Generic);\n SINGLE_INHERIT(Character, Flexible);\n\t\n#define DUAL_INHERIT(child, parent1, parent2) \\\n Py##child##ArrType_Type.tp_base = &Py##parent2##ArrType_Type;\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent2##ArrType_Type,\t\\\n\t\t\t &Py##parent1##_Type);\t\t\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\n\n#define DUAL_INHERIT2(child, parent1, parent2)\t\t\t\t\\\n Py##child##ArrType_Type.tp_base = &Py##parent1##_Type;\t\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent1##_Type,\t\t\\\n\t\t\t &Py##parent2##ArrType_Type);\t\t\\\n\tPy##child##ArrType_Type.tp_richcompare =\t\t\t\\\n\t\tPy##parent1##_Type.tp_richcompare;\t\t\t\\\n\tPy##child##ArrType_Type.tp_compare =\t\t\t\t\\\n\t\tPy##parent1##_Type.tp_compare;\t\t\t\t\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\n\n SINGLE_INHERIT(Bool, Generic);\n SINGLE_INHERIT(Byte, SignedInteger);\n SINGLE_INHERIT(Short, SignedInteger);\n#if SIZEOF_INT == SIZEOF_LONG\n DUAL_INHERIT(Int, Int, SignedInteger);\n#else\n SINGLE_INHERIT(Int, SignedInteger);\n#endif\n DUAL_INHERIT(Long, Int, SignedInteger);\n#if SIZEOF_LONGLONG == SIZEOF_LONG\n DUAL_INHERIT(LongLong, Int, SignedInteger);\n#else\n SINGLE_INHERIT(LongLong, SignedInteger);\n#endif\n\n /* fprintf(stderr, \"tp_free = %p, PyObject_Del = %p, int_tp_free = %p, base.tp_free = %p\\n\", PyIntArrType_Type.tp_free, PyObject_Del, PyInt_Type.tp_free, PySignedIntegerArrType_Type.tp_free);\n\t */\n\tSINGLE_INHERIT(UByte, UnsignedInteger);\n SINGLE_INHERIT(UShort, UnsignedInteger);\n SINGLE_INHERIT(UInt, UnsignedInteger);\n SINGLE_INHERIT(ULong, UnsignedInteger);\n SINGLE_INHERIT(ULongLong, UnsignedInteger);\n\n SINGLE_INHERIT(Float, Floating);\n DUAL_INHERIT(Double, Float, Floating);\n SINGLE_INHERIT(LongDouble, Floating);\n\n SINGLE_INHERIT(CFloat, ComplexFloating);\n DUAL_INHERIT(CDouble, Complex, ComplexFloating);\n SINGLE_INHERIT(CLongDouble, ComplexFloating);\n\n DUAL_INHERIT2(String, String, Character);\n DUAL_INHERIT2(Unicode, Unicode, Character);\n\t\n SINGLE_INHERIT(Void, Flexible);\n \n SINGLE_INHERIT(Object, Generic);\n\n return 0;\n\n#undef SINGLE_INHERIT\n#undef DUAL_INHERIT\n\n\t/* Clean up string and unicode array types so they act more like\n\t strings -- get their tables from the standard types.\n\t*/\n}\n\n/* place a flag dictionary in d */\n\nstatic void\nset_flaginfo(PyObject *d)\n{\n PyObject *s;\n PyObject *newd;\n \n newd = PyDict_New();\n\n PyDict_SetItemString(newd, \"OWNDATA\", s=PyInt_FromLong(OWNDATA));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"FORTRAN\", s=PyInt_FromLong(FORTRAN));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"CONTIGUOUS\", s=PyInt_FromLong(CONTIGUOUS));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"ALIGNED\", s=PyInt_FromLong(ALIGNED));\n Py_DECREF(s);\n\n PyDict_SetItemString(newd, \"UPDATEIFCOPY\", s=PyInt_FromLong(UPDATEIFCOPY));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"WRITEABLE\", s=PyInt_FromLong(WRITEABLE));\n Py_DECREF(s);\n \n PyDict_SetItemString(d, \"_flagdict\", newd);\n Py_DECREF(newd);\n return;\n}\n\n\n/* Initialization function for the module */\n\nDL_EXPORT(void) initmultiarray(void) {\n\tPyObject *m, *d, *s;\n\tPyObject *c_api;\n\n\tif (_multiarray_module_loaded) return;\n\t_multiarray_module_loaded = 1;\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\tif (PyType_Ready(&PyArray_Type) < 0)\n return;\n\n if (setup_scalartypes(d) < 0) goto err;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMultiIter_Type.tp_iter = PyObject_SelfIter;\n\tif (PyType_Ready(&PyArrayIter_Type) < 0)\n\t\treturn; \n \n\tif (PyType_Ready(&PyArrayMapIter_Type) < 0)\n return; \n\n\tif (PyType_Ready(&PyArrayMultiIter_Type) < 0)\n\t\treturn;\n\n\tif (PyType_Ready(&PyArrayDescr_Type) < 0)\n\t\treturn;\n\n\tc_api = PyCObject_FromVoidPtr((void *)PyArray_API, NULL);\n\tif (PyErr_Occurred()) goto err;\n\tPyDict_SetItemString(d, \"_ARRAY_API\", c_api);\n\tPy_DECREF(c_api);\n\tif (PyErr_Occurred()) goto err;\n\n\tMultiArrayError = PyString_FromString (\"multiarray.error\");\n\tPyDict_SetItemString (d, \"error\", MultiArrayError);\n\t\n\ts = PyString_FromString(\"3.0\");\n\tPyDict_SetItemString(d, \"__version__\", s);\n\tPy_DECREF(s);\n Py_INCREF(&PyArray_Type);\n\tPyDict_SetItemString(d, \"ndarray\", (PyObject *)&PyArray_Type);\n Py_INCREF(&PyArrayIter_Type);\n\tPyDict_SetItemString(d, \"flatiter\", (PyObject *)&PyArrayIter_Type);\n Py_INCREF(&PyArrayMultiIter_Type);\n\tPyDict_SetItemString(d, \"broadcast\", \n\t\t\t (PyObject *)&PyArrayMultiIter_Type);\n\tPy_INCREF(&PyArrayDescr_Type);\n\tPyDict_SetItemString(d, \"dtype\", (PyObject *)&PyArrayDescr_Type);\n\n set_flaginfo(d);\n\n\tif (set_typeinfo(d) != 0) goto err;\n\n\t_numpy_internal =\t\t\t\t\t\t\\\n\t\tPyImport_ImportModule(\"numpy.core._internal\");\n\tif (_numpy_internal != NULL) return;\n\n err:\t\n\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\n\treturn;\n}\n\n", + "methods": [ + { + "name": "_arraydescr_fromobj", + "long_name": "_arraydescr_fromobj( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 15, + "complexity": 3, + "token_count": 67, + "parameters": [ + "obj" + ], + "start_line": 34, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyIntList", + "long_name": "PyArray_MultiplyIntList( register int * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 74, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyList", + "long_name": "PyArray_MultiplyList( register intp * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 85, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPtr", + "long_name": "PyArray_GetPtr( PyArrayObject * obj , register intp * ind)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "obj", + "ind" + ], + "start_line": 96, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AxisConverter", + "long_name": "PyArray_AxisConverter( PyObject * obj , int * axis)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 53, + "parameters": [ + "obj", + "axis" + ], + "start_line": 110, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CompareLists", + "long_name": "PyArray_CompareLists( intp * l1 , intp * l2 , int n)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 3, + "token_count": 51, + "parameters": [ + "l1", + "l2", + "n" + ], + "start_line": 128, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_View", + "long_name": "PyArray_View( PyArrayObject * self , PyArray_Descr * type , PyTypeObject * pytype)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self", + "type", + "pytype" + ], + "start_line": 142, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ravel", + "long_name": "PyArray_Ravel( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 102, + "parameters": [ + "a", + "fortran" + ], + "start_line": 178, + "end_line": 195, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "power_of_ten", + "long_name": "power_of_ten( int n)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 72, + "parameters": [ + "n" + ], + "start_line": 198, + "end_line": 210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Round", + "long_name": "PyArray_Round( PyArrayObject * a , int decimals)", + "filename": "multiarraymodule.c", + "nloc": 85, + "complexity": 19, + "token_count": 614, + "parameters": [ + "a", + "decimals" + ], + "start_line": 216, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Flatten", + "long_name": "PyArray_Flatten( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 6, + "token_count": 176, + "parameters": [ + "a", + "fortran" + ], + "start_line": 315, + "end_line": 350, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Reshape", + "long_name": "PyArray_Reshape( PyArrayObject * self , PyObject * shape)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "shape" + ], + "start_line": 361, + "end_line": 370, + "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": 373, + "end_line": 399, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Newshape", + "long_name": "PyArray_Newshape( PyArrayObject * self , PyArray_Dims * newdims)", + "filename": "multiarraymodule.c", + "nloc": 72, + "complexity": 17, + "token_count": 409, + "parameters": [ + "self", + "newdims" + ], + "start_line": 410, + "end_line": 497, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Squeeze", + "long_name": "PyArray_Squeeze( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 34, + "complexity": 5, + "token_count": 204, + "parameters": [ + "self" + ], + "start_line": 506, + "end_line": 541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Mean", + "long_name": "PyArray_Mean( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 19, + "complexity": 4, + "token_count": 139, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 548, + "end_line": 569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Std", + "long_name": "PyArray_Std( PyArrayObject * self , int axis , int rtype , int variance)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 13, + "token_count": 450, + "parameters": [ + "self", + "axis", + "rtype", + "variance" + ], + "start_line": 576, + "end_line": 635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sum", + "long_name": "PyArray_Sum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 642, + "end_line": 652, + "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": 658, + "end_line": 668, + "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": 674, + "end_line": 684, + "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": 690, + "end_line": 701, + "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": 707, + "end_line": 718, + "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": 724, + "end_line": 735, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Compress", + "long_name": "PyArray_Compress( PyArrayObject * self , PyObject * condition , int axis)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 3, + "token_count": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 742, + "end_line": 762, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Nonzero", + "long_name": "PyArray_Nonzero( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 13, + "token_count": 414, + "parameters": [ + "self" + ], + "start_line": 768, + "end_line": 827, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Clip", + "long_name": "PyArray_Clip( PyArrayObject * self , PyObject * min , PyObject * max)", + "filename": "multiarraymodule.c", + "nloc": 28, + "complexity": 6, + "token_count": 237, + "parameters": [ + "self", + "min", + "max" + ], + "start_line": 833, + "end_line": 863, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Conjugate", + "long_name": "PyArray_Conjugate( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 9, + "token_count": 228, + "parameters": [ + "self" + ], + "start_line": 869, + "end_line": 905, + "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": 911, + "end_line": 921, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Diagonal", + "long_name": "PyArray_Diagonal( PyArrayObject * self , int offset , int axis1 , int axis2)", + "filename": "multiarraymodule.c", + "nloc": 104, + "complexity": 23, + "token_count": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 927, + "end_line": 1046, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AsCArray", + "long_name": "PyArray_AsCArray( PyObject ** op , * ptr , intp * dims , int nd , PyArray_Descr * typedescr)", + "filename": "multiarraymodule.c", + "nloc": 50, + "complexity": 12, + "token_count": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 1062, + "end_line": 1113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As1D", + "long_name": "PyArray_As1D( PyObject ** op , char ** ptr , int * d1 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 71, + "parameters": [ + "op", + "ptr", + "d1", + "typecode" + ], + "start_line": 1121, + "end_line": 1131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As2D", + "long_name": "PyArray_As2D( PyObject ** op , char ** * ptr , int * d1 , int * d2 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 92, + "parameters": [ + "op", + "ptr", + "d1", + "d2", + "typecode" + ], + "start_line": 1137, + "end_line": 1149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Free", + "long_name": "PyArray_Free( PyObject * op , * ptr)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 4, + "token_count": 67, + "parameters": [ + "op", + "ptr" + ], + "start_line": 1157, + "end_line": 1168, + "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": 1172, + "end_line": 1200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Concatenate", + "long_name": "PyArray_Concatenate( PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1212, + "end_line": 1318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SwapAxes", + "long_name": "PyArray_SwapAxes( PyArrayObject * ap , int a1 , int a2)", + "filename": "multiarraymodule.c", + "nloc": 38, + "complexity": 12, + "token_count": 227, + "parameters": [ + "ap", + "a1", + "a2" + ], + "start_line": 1324, + "end_line": 1365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Transpose", + "long_name": "PyArray_Transpose( PyArrayObject * ap , PyArray_Dims * permute)", + "filename": "multiarraymodule.c", + "nloc": 46, + "complexity": 10, + "token_count": 309, + "parameters": [ + "ap", + "permute" + ], + "start_line": 1371, + "end_line": 1424, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Repeat", + "long_name": "PyArray_Repeat( PyArrayObject * aop , PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 78, + "complexity": 15, + "token_count": 523, + "parameters": [ + "aop", + "op", + "axis" + ], + "start_line": 1430, + "end_line": 1525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "_signbit_set", + "long_name": "_signbit_set( PyArrayObject * arr)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 89, + "parameters": [ + "arr" + ], + "start_line": 1529, + "end_line": 1546, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ScalarKind", + "long_name": "PyArray_ScalarKind( int typenum , PyArrayObject ** arr)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 8, + "token_count": 80, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 1551, + "end_line": 1563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCoerceScalar", + "long_name": "PyArray_CanCoerceScalar( char thistype , char neededtype , PyArray_SCALARKIND scalar)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 9, + "token_count": 101, + "parameters": [ + "thistype", + "neededtype", + "scalar" + ], + "start_line": 1567, + "end_line": 1589, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 73, + "complexity": 15, + "token_count": 482, + "parameters": [ + "op", + "retn" + ], + "start_line": 1597, + "end_line": 1676, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Choose", + "long_name": "PyArray_Choose( PyArrayObject * ip , PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 15, + "token_count": 518, + "parameters": [ + "ip", + "op" + ], + "start_line": 1683, + "end_line": 1764, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 82, + "top_nesting_level": 0 + }, + { + "name": "_strided_copy", + "long_name": "_strided_copy( char * dst , intp dststride , char * src , intp srcstride , intp num , int elsize)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 48, + "parameters": [ + "dst", + "dststride", + "src", + "srcstride", + "num", + "elsize" + ], + "start_line": 1767, + "end_line": 1774, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "_new_sort", + "long_name": "_new_sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 8, + "token_count": 284, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1785, + "end_line": 1839, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "_new_argsort", + "long_name": "_new_argsort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 67, + "complexity": 13, + "token_count": 498, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1842, + "end_line": 1920, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "qsortCompare", + "long_name": "qsortCompare( const * a , const * b)", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "a", + "b" + ], + "start_line": 1928, + "end_line": 1931, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sort", + "long_name": "PyArray_Sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 52, + "complexity": 14, + "token_count": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1986, + "end_line": 2052, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "argsort_static_compare", + "long_name": "argsort_static_compare( const * ip1 , const * ip2)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 1, + "token_count": 67, + "parameters": [ + "ip1", + "ip2" + ], + "start_line": 2058, + "end_line": 2066, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgSort", + "long_name": "PyArray_ArgSort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 15, + "token_count": 493, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 2072, + "end_line": 2152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_LexSort", + "long_name": "PyArray_LexSort( PyObject * sort_keys , int axis)", + "filename": "multiarraymodule.c", + "nloc": 132, + "complexity": 36, + "token_count": 1162, + "parameters": [ + "sort_keys", + "axis" + ], + "start_line": 2164, + "end_line": 2308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 145, + "top_nesting_level": 0 + }, + { + "name": "local_where", + "long_name": "local_where( PyArrayObject * ap1 , PyArrayObject * ap2 , PyArrayObject * ret)", + "filename": "multiarraymodule.c", + "nloc": 35, + "complexity": 7, + "token_count": 243, + "parameters": [ + "ap1", + "ap2", + "ret" + ], + "start_line": 2312, + "end_line": 2347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SearchSorted", + "long_name": "PyArray_SearchSorted( PyArrayObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 5, + "token_count": 231, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2353, + "end_line": 2398, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2405, + "end_line": 2429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 79, + "complexity": 15, + "token_count": 624, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2438, + "end_line": 2536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 89, + "complexity": 17, + "token_count": 680, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2544, + "end_line": 2655, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 286, + "parameters": [ + "op" + ], + "start_line": 2661, + "end_line": 2715, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Correlate", + "long_name": "PyArray_Correlate( PyObject * op1 , PyObject * op2 , int mode)", + "filename": "multiarraymodule.c", + "nloc": 86, + "complexity": 13, + "token_count": 601, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2721, + "end_line": 2818, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgMin", + "long_name": "PyArray_ArgMin( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 5, + "token_count": 141, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2825, + "end_line": 2849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Max", + "long_name": "PyArray_Max( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 71, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2855, + "end_line": 2866, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Min", + "long_name": "PyArray_Min( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 71, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2872, + "end_line": 2883, + "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": 2889, + "end_line": 2912, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgMax", + "long_name": "PyArray_ArgMax( PyArrayObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 7, + "token_count": 326, + "parameters": [ + "op", + "axis" + ], + "start_line": 2919, + "end_line": 2976, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Take", + "long_name": "PyArray_Take( PyArrayObject * self0 , PyObject * indices0 , int axis)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 473, + "parameters": [ + "self0", + "indices0", + "axis" + ], + "start_line": 2983, + "end_line": 3058, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Put", + "long_name": "PyArray_Put( PyArrayObject * self , PyObject * values0 , PyObject * indices0)", + "filename": "multiarraymodule.c", + "nloc": 64, + "complexity": 15, + "token_count": 479, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 3064, + "end_line": 3134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PutMask", + "long_name": "PyArray_PutMask( PyArrayObject * self , PyObject * values0 , PyObject * mask0)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 422, + "parameters": [ + "self", + "values0", + "mask0" + ], + "start_line": 3140, + "end_line": 3211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Converter", + "long_name": "PyArray_Converter( PyObject * object , PyObject ** address)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3227, + "end_line": 3239, + "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": 3245, + "end_line": 3253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_TypestrConvert", + "long_name": "PyArray_TypestrConvert( int itemsize , int gentype)", + "filename": "multiarraymodule.c", + "nloc": 96, + "complexity": 35, + "token_count": 308, + "parameters": [ + "itemsize", + "gentype" + ], + "start_line": 3260, + "end_line": 3375, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BufferConverter", + "long_name": "PyArray_BufferConverter( PyObject * obj , PyArray_Chunk * buf)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 6, + "token_count": 147, + "parameters": [ + "obj", + "buf" + ], + "start_line": 3393, + "end_line": 3418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpConverter", + "long_name": "PyArray_IntpConverter( PyObject * obj , PyArray_Dims * seq)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 10, + "token_count": 189, + "parameters": [ + "obj", + "seq" + ], + "start_line": 3433, + "end_line": 3469, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "_use_inherit", + "long_name": "_use_inherit( PyArray_Descr * type , PyObject * newobj , int * errflag)", + "filename": "multiarraymodule.c", + "nloc": 35, + "complexity": 7, + "token_count": 171, + "parameters": [ + "type", + "newobj", + "errflag" + ], + "start_line": 3487, + "end_line": 3525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_tuple", + "long_name": "_convert_from_tuple( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 400, + "parameters": [ + "obj" + ], + "start_line": 3528, + "end_line": 3606, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 93, + "complexity": 24, + "token_count": 596, + "parameters": [ + "obj" + ], + "start_line": 3614, + "end_line": 3709, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3720, + "end_line": 3791, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_commastring", + "long_name": "_convert_from_commastring( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 92, + "parameters": [ + "obj", + "align" + ], + "start_line": 3804, + "end_line": 3820, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_use_fields_dict", + "long_name": "_use_fields_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 1, + "token_count": 29, + "parameters": [ + "obj", + "align" + ], + "start_line": 3857, + "end_line": 3862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_dict", + "long_name": "_convert_from_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 117, + "complexity": 30, + "token_count": 752, + "parameters": [ + "obj", + "align" + ], + "start_line": 3865, + "end_line": 3991, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter2", + "long_name": "PyArray_DescrConverter2( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 37, + "parameters": [ + "obj", + "at" + ], + "start_line": 4009, + "end_line": 4016, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter", + "long_name": "PyArray_DescrConverter( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 141, + "complexity": 55, + "token_count": 886, + "parameters": [ + "obj", + "at" + ], + "start_line": 4033, + "end_line": 4213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 181, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ByteorderConverter", + "long_name": "PyArray_ByteorderConverter( PyObject * obj , char * endian)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 16, + "token_count": 218, + "parameters": [ + "obj", + "endian" + ], + "start_line": 4219, + "end_line": 4251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SortkindConverter", + "long_name": "PyArray_SortkindConverter( PyObject * obj , PyArray_SORTKIND * sortkind)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 11, + "token_count": 162, + "parameters": [ + "obj", + "sortkind" + ], + "start_line": 4257, + "end_line": 4283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EquivTypes", + "long_name": "PyArray_EquivTypes( PyArray_Descr * typ1 , PyArray_Descr * typ2)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 8, + "token_count": 138, + "parameters": [ + "typ1", + "typ2" + ], + "start_line": 4292, + "end_line": 4311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_prepend_ones", + "long_name": "_prepend_ones( PyArrayObject * arr , int nd , int ndmin)", + "filename": "multiarraymodule.c", + "nloc": 23, + "complexity": 3, + "token_count": 175, + "parameters": [ + "arr", + "nd", + "ndmin" + ], + "start_line": 4316, + "end_line": 4341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 15, + "token_count": 373, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4363, + "end_line": 4438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Empty", + "long_name": "PyArray_Empty( int nd , intp * dims , PyArray_Descr * type , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 14, + "complexity": 4, + "token_count": 96, + "parameters": [ + "nd", + "dims", + "type", + "fortran" + ], + "start_line": 4446, + "end_line": 4461, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_empty", + "long_name": "array_empty( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 2, + "token_count": 130, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4467, + "end_line": 4491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_scalar", + "long_name": "array_scalar( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 10, + "token_count": 254, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4496, + "end_line": 4554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zeros", + "long_name": "PyArray_Zeros( int nd , intp * dims , PyArray_Descr * type , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 4, + "token_count": 134, + "parameters": [ + "nd", + "dims", + "type", + "fortran" + ], + "start_line": 4563, + "end_line": 4587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_zeros", + "long_name": "array_zeros( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 2, + "token_count": 133, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4593, + "end_line": 4617, + "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": 4624, + "end_line": 4633, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_skip_sep", + "long_name": "_skip_sep( char ** ptr , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 78, + "parameters": [ + "ptr", + "sep" + ], + "start_line": 4636, + "end_line": 4647, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 133, + "complexity": 22, + "token_count": 711, + "parameters": [ + "data", + "slen", + "dtype", + "n", + "sep" + ], + "start_line": 4652, + "end_line": 4794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 143, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 2, + "token_count": 116, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4799, + "end_line": 4816, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 114, + "complexity": 22, + "token_count": 664, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4830, + "end_line": 4958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "top_nesting_level": 0 + }, + { + "name": "array_fromfile", + "long_name": "array_fromfile( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 7, + "token_count": 225, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4976, + "end_line": 5014, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromBuffer", + "long_name": "PyArray_FromBuffer( PyObject * buf , PyArray_Descr * type , intp count , intp offset)", + "filename": "multiarraymodule.c", + "nloc": 83, + "complexity": 16, + "token_count": 446, + "parameters": [ + "buf", + "type", + "count", + "offset" + ], + "start_line": 5018, + "end_line": 5111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "array_frombuffer", + "long_name": "array_frombuffer( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 121, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 5127, + "end_line": 5144, + "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": 5150, + "end_line": 5161, + "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": 5168, + "end_line": 5174, + "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": 5181, + "end_line": 5187, + "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": 5191, + "end_line": 5197, + "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": 5201, + "end_line": 5210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Arange", + "long_name": "PyArray_Arange( double start , double stop , double step , int type_num)", + "filename": "multiarraymodule.c", + "nloc": 40, + "complexity": 9, + "token_count": 300, + "parameters": [ + "start", + "stop", + "step", + "type_num" + ], + "start_line": 5217, + "end_line": 5268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "_calc_length", + "long_name": "_calc_length( PyObject * start , PyObject * stop , PyObject * step , PyObject ** next , int cmplx)", + "filename": "multiarraymodule.c", + "nloc": 31, + "complexity": 10, + "token_count": 235, + "parameters": [ + "start", + "stop", + "step", + "next", + "cmplx" + ], + "start_line": 5274, + "end_line": 5306, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArangeObj", + "long_name": "PyArray_ArangeObj( PyObject * start , PyObject * stop , PyObject * step , PyArray_Descr * dtype)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 19, + "token_count": 461, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 5313, + "end_line": 5397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "array_arange", + "long_name": "array_arange( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 100, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 5410, + "end_line": 5422, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNDArrayCVersion", + "long_name": "PyArray_GetNDArrayCVersion()", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [], + "start_line": 5428, + "end_line": 5431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array__get_ndarray_c_version", + "long_name": "array__get_ndarray_c_version( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5437, + "end_line": 5443, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_set_string_function", + "long_name": "array_set_string_function( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 98, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5449, + "end_line": 5465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "array_set_ops_function", + "long_name": "array_set_ops_function( PyObject * self , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 5471, + "end_line": 5488, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Where", + "long_name": "PyArray_Where( PyObject * condition , PyObject * x , PyObject * y)", + "filename": "multiarraymodule.c", + "nloc": 31, + "complexity": 8, + "token_count": 233, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5495, + "end_line": 5535, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_where", + "long_name": "array_where( PyObject * ignored , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 60, + "parameters": [ + "ignored", + "args" + ], + "start_line": 5543, + "end_line": 5551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_lexsort", + "long_name": "array_lexsort( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 5563, + "end_line": 5573, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_register_dtype", + "long_name": "array_register_dtype( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 3, + "token_count": 64, + "parameters": [ + "dummy", + "args" + ], + "start_line": 5582, + "end_line": 5593, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_can_cast_safely", + "long_name": "array_can_cast_safely( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 5, + "token_count": 128, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5600, + "end_line": 5623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "new_buffer", + "long_name": "new_buffer( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 7, + "complexity": 2, + "token_count": 37, + "parameters": [ + "dummy", + "args" + ], + "start_line": 5630, + "end_line": 5638, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "buffer_buffer", + "long_name": "buffer_buffer( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 120, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5647, + "end_line": 5665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "setup_scalartypes", + "long_name": "setup_scalartypes( PyObject * dict)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 10, + "token_count": 351, + "parameters": [ + "dict" + ], + "start_line": 5731, + "end_line": 5844, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 114, + "top_nesting_level": 0 + }, + { + "name": "set_flaginfo", + "long_name": "set_flaginfo( PyObject * d)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 1, + "token_count": 152, + "parameters": [ + "d" + ], + "start_line": 5849, + "end_line": 5873, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "initmultiarray", + "long_name": "initmultiarray()", + "filename": "multiarraymodule.c", + "nloc": 57, + "complexity": 16, + "token_count": 392, + "parameters": [], + "start_line": 5878, + "end_line": 5953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "_arraydescr_fromobj", + "long_name": "_arraydescr_fromobj( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 15, + "complexity": 3, + "token_count": 67, + "parameters": [ + "obj" + ], + "start_line": 34, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyIntList", + "long_name": "PyArray_MultiplyIntList( register int * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 74, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyList", + "long_name": "PyArray_MultiplyList( register intp * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 85, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPtr", + "long_name": "PyArray_GetPtr( PyArrayObject * obj , register intp * ind)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "obj", + "ind" + ], + "start_line": 96, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AxisConverter", + "long_name": "PyArray_AxisConverter( PyObject * obj , int * axis)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 53, + "parameters": [ + "obj", + "axis" + ], + "start_line": 110, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CompareLists", + "long_name": "PyArray_CompareLists( intp * l1 , intp * l2 , int n)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 3, + "token_count": 51, + "parameters": [ + "l1", + "l2", + "n" + ], + "start_line": 128, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_View", + "long_name": "PyArray_View( PyArrayObject * self , PyArray_Descr * type , PyTypeObject * pytype)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self", + "type", + "pytype" + ], + "start_line": 142, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ravel", + "long_name": "PyArray_Ravel( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 102, + "parameters": [ + "a", + "fortran" + ], + "start_line": 178, + "end_line": 195, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "power_of_ten", + "long_name": "power_of_ten( int n)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 72, + "parameters": [ + "n" + ], + "start_line": 198, + "end_line": 210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Round", + "long_name": "PyArray_Round( PyArrayObject * a , int decimals)", + "filename": "multiarraymodule.c", + "nloc": 85, + "complexity": 19, + "token_count": 614, + "parameters": [ + "a", + "decimals" + ], + "start_line": 216, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Flatten", + "long_name": "PyArray_Flatten( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 6, + "token_count": 176, + "parameters": [ + "a", + "fortran" + ], + "start_line": 315, + "end_line": 350, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Reshape", + "long_name": "PyArray_Reshape( PyArrayObject * self , PyObject * shape)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "shape" + ], + "start_line": 361, + "end_line": 370, + "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": 373, + "end_line": 399, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Newshape", + "long_name": "PyArray_Newshape( PyArrayObject * self , PyArray_Dims * newdims)", + "filename": "multiarraymodule.c", + "nloc": 72, + "complexity": 17, + "token_count": 409, + "parameters": [ + "self", + "newdims" + ], + "start_line": 410, + "end_line": 497, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Squeeze", + "long_name": "PyArray_Squeeze( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 34, + "complexity": 5, + "token_count": 204, + "parameters": [ + "self" + ], + "start_line": 506, + "end_line": 541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Mean", + "long_name": "PyArray_Mean( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 19, + "complexity": 4, + "token_count": 139, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 548, + "end_line": 569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Std", + "long_name": "PyArray_Std( PyArrayObject * self , int axis , int rtype , int variance)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 13, + "token_count": 450, + "parameters": [ + "self", + "axis", + "rtype", + "variance" + ], + "start_line": 576, + "end_line": 635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sum", + "long_name": "PyArray_Sum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 642, + "end_line": 652, + "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": 658, + "end_line": 668, + "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": 674, + "end_line": 684, + "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": 690, + "end_line": 701, + "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": 707, + "end_line": 718, + "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": 724, + "end_line": 735, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Compress", + "long_name": "PyArray_Compress( PyArrayObject * self , PyObject * condition , int axis)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 3, + "token_count": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 742, + "end_line": 762, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Nonzero", + "long_name": "PyArray_Nonzero( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 13, + "token_count": 414, + "parameters": [ + "self" + ], + "start_line": 768, + "end_line": 827, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Clip", + "long_name": "PyArray_Clip( PyArrayObject * self , PyObject * min , PyObject * max)", + "filename": "multiarraymodule.c", + "nloc": 28, + "complexity": 6, + "token_count": 237, + "parameters": [ + "self", + "min", + "max" + ], + "start_line": 833, + "end_line": 863, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Conjugate", + "long_name": "PyArray_Conjugate( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 9, + "token_count": 228, + "parameters": [ + "self" + ], + "start_line": 869, + "end_line": 905, + "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": 911, + "end_line": 921, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Diagonal", + "long_name": "PyArray_Diagonal( PyArrayObject * self , int offset , int axis1 , int axis2)", + "filename": "multiarraymodule.c", + "nloc": 104, + "complexity": 23, + "token_count": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 927, + "end_line": 1046, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AsCArray", + "long_name": "PyArray_AsCArray( PyObject ** op , * ptr , intp * dims , int nd , PyArray_Descr * typedescr)", + "filename": "multiarraymodule.c", + "nloc": 50, + "complexity": 12, + "token_count": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 1062, + "end_line": 1113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As1D", + "long_name": "PyArray_As1D( PyObject ** op , char ** ptr , int * d1 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 71, + "parameters": [ + "op", + "ptr", + "d1", + "typecode" + ], + "start_line": 1121, + "end_line": 1131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As2D", + "long_name": "PyArray_As2D( PyObject ** op , char ** * ptr , int * d1 , int * d2 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 92, + "parameters": [ + "op", + "ptr", + "d1", + "d2", + "typecode" + ], + "start_line": 1137, + "end_line": 1149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Free", + "long_name": "PyArray_Free( PyObject * op , * ptr)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 4, + "token_count": 67, + "parameters": [ + "op", + "ptr" + ], + "start_line": 1157, + "end_line": 1168, + "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": 1172, + "end_line": 1200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Concatenate", + "long_name": "PyArray_Concatenate( PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1212, + "end_line": 1318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SwapAxes", + "long_name": "PyArray_SwapAxes( PyArrayObject * ap , int a1 , int a2)", + "filename": "multiarraymodule.c", + "nloc": 38, + "complexity": 12, + "token_count": 227, + "parameters": [ + "ap", + "a1", + "a2" + ], + "start_line": 1324, + "end_line": 1365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Transpose", + "long_name": "PyArray_Transpose( PyArrayObject * ap , PyArray_Dims * permute)", + "filename": "multiarraymodule.c", + "nloc": 46, + "complexity": 10, + "token_count": 309, + "parameters": [ + "ap", + "permute" + ], + "start_line": 1371, + "end_line": 1424, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Repeat", + "long_name": "PyArray_Repeat( PyArrayObject * aop , PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 78, + "complexity": 15, + "token_count": 523, + "parameters": [ + "aop", + "op", + "axis" + ], + "start_line": 1430, + "end_line": 1525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "_signbit_set", + "long_name": "_signbit_set( PyArrayObject * arr)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 89, + "parameters": [ + "arr" + ], + "start_line": 1529, + "end_line": 1546, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ScalarKind", + "long_name": "PyArray_ScalarKind( int typenum , PyArrayObject ** arr)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 8, + "token_count": 80, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 1551, + "end_line": 1563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCoerceScalar", + "long_name": "PyArray_CanCoerceScalar( char thistype , char neededtype , PyArray_SCALARKIND scalar)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 9, + "token_count": 101, + "parameters": [ + "thistype", + "neededtype", + "scalar" + ], + "start_line": 1567, + "end_line": 1589, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 73, + "complexity": 15, + "token_count": 482, + "parameters": [ + "op", + "retn" + ], + "start_line": 1597, + "end_line": 1676, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Choose", + "long_name": "PyArray_Choose( PyArrayObject * ip , PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 15, + "token_count": 518, + "parameters": [ + "ip", + "op" + ], + "start_line": 1683, + "end_line": 1764, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 82, + "top_nesting_level": 0 + }, + { + "name": "_strided_copy", + "long_name": "_strided_copy( char * dst , intp dststride , char * src , intp srcstride , intp num , int elsize)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 48, + "parameters": [ + "dst", + "dststride", + "src", + "srcstride", + "num", + "elsize" + ], + "start_line": 1767, + "end_line": 1774, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "_new_sort", + "long_name": "_new_sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 8, + "token_count": 284, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1785, + "end_line": 1839, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "_new_argsort", + "long_name": "_new_argsort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 67, + "complexity": 13, + "token_count": 498, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1842, + "end_line": 1920, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "qsortCompare", + "long_name": "qsortCompare( const * a , const * b)", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "a", + "b" + ], + "start_line": 1928, + "end_line": 1931, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sort", + "long_name": "PyArray_Sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 52, + "complexity": 14, + "token_count": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1986, + "end_line": 2052, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "argsort_static_compare", + "long_name": "argsort_static_compare( const * ip1 , const * ip2)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 1, + "token_count": 67, + "parameters": [ + "ip1", + "ip2" + ], + "start_line": 2058, + "end_line": 2066, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgSort", + "long_name": "PyArray_ArgSort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 15, + "token_count": 493, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 2072, + "end_line": 2152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_LexSort", + "long_name": "PyArray_LexSort( PyObject * sort_keys , int axis)", + "filename": "multiarraymodule.c", + "nloc": 132, + "complexity": 36, + "token_count": 1162, + "parameters": [ + "sort_keys", + "axis" + ], + "start_line": 2164, + "end_line": 2308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 145, + "top_nesting_level": 0 + }, + { + "name": "local_where", + "long_name": "local_where( PyArrayObject * ap1 , PyArrayObject * ap2 , PyArrayObject * ret)", + "filename": "multiarraymodule.c", + "nloc": 35, + "complexity": 7, + "token_count": 243, + "parameters": [ + "ap1", + "ap2", + "ret" + ], + "start_line": 2312, + "end_line": 2347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SearchSorted", + "long_name": "PyArray_SearchSorted( PyArrayObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 5, + "token_count": 231, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2353, + "end_line": 2398, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2405, + "end_line": 2429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 79, + "complexity": 15, + "token_count": 624, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2438, + "end_line": 2536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 89, + "complexity": 17, + "token_count": 680, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2544, + "end_line": 2655, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 286, + "parameters": [ + "op" + ], + "start_line": 2661, + "end_line": 2715, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Correlate", + "long_name": "PyArray_Correlate( PyObject * op1 , PyObject * op2 , int mode)", + "filename": "multiarraymodule.c", + "nloc": 86, + "complexity": 13, + "token_count": 601, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2721, + "end_line": 2818, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgMin", + "long_name": "PyArray_ArgMin( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 5, + "token_count": 141, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2825, + "end_line": 2849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Max", + "long_name": "PyArray_Max( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 71, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2855, + "end_line": 2866, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Min", + "long_name": "PyArray_Min( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 71, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2872, + "end_line": 2883, + "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": 2889, + "end_line": 2912, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgMax", + "long_name": "PyArray_ArgMax( PyArrayObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 7, + "token_count": 326, + "parameters": [ + "op", + "axis" + ], + "start_line": 2919, + "end_line": 2976, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Take", + "long_name": "PyArray_Take( PyArrayObject * self0 , PyObject * indices0 , int axis)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 473, + "parameters": [ + "self0", + "indices0", + "axis" + ], + "start_line": 2983, + "end_line": 3058, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Put", + "long_name": "PyArray_Put( PyArrayObject * self , PyObject * values0 , PyObject * indices0)", + "filename": "multiarraymodule.c", + "nloc": 64, + "complexity": 15, + "token_count": 479, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 3064, + "end_line": 3134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PutMask", + "long_name": "PyArray_PutMask( PyArrayObject * self , PyObject * values0 , PyObject * mask0)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 422, + "parameters": [ + "self", + "values0", + "mask0" + ], + "start_line": 3140, + "end_line": 3211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Converter", + "long_name": "PyArray_Converter( PyObject * object , PyObject ** address)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3227, + "end_line": 3239, + "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": 3245, + "end_line": 3253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_TypestrConvert", + "long_name": "PyArray_TypestrConvert( int itemsize , int gentype)", + "filename": "multiarraymodule.c", + "nloc": 96, + "complexity": 35, + "token_count": 308, + "parameters": [ + "itemsize", + "gentype" + ], + "start_line": 3260, + "end_line": 3375, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BufferConverter", + "long_name": "PyArray_BufferConverter( PyObject * obj , PyArray_Chunk * buf)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 6, + "token_count": 147, + "parameters": [ + "obj", + "buf" + ], + "start_line": 3393, + "end_line": 3418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpConverter", + "long_name": "PyArray_IntpConverter( PyObject * obj , PyArray_Dims * seq)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 10, + "token_count": 189, + "parameters": [ + "obj", + "seq" + ], + "start_line": 3433, + "end_line": 3469, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "_use_inherit", + "long_name": "_use_inherit( PyArray_Descr * type , PyObject * newobj , int * errflag)", + "filename": "multiarraymodule.c", + "nloc": 35, + "complexity": 7, + "token_count": 171, + "parameters": [ + "type", + "newobj", + "errflag" + ], + "start_line": 3487, + "end_line": 3525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_tuple", + "long_name": "_convert_from_tuple( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 400, + "parameters": [ + "obj" + ], + "start_line": 3528, + "end_line": 3606, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 93, + "complexity": 24, + "token_count": 596, + "parameters": [ + "obj" + ], + "start_line": 3614, + "end_line": 3709, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3720, + "end_line": 3791, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_commastring", + "long_name": "_convert_from_commastring( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 92, + "parameters": [ + "obj", + "align" + ], + "start_line": 3804, + "end_line": 3820, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_use_fields_dict", + "long_name": "_use_fields_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 1, + "token_count": 29, + "parameters": [ + "obj", + "align" + ], + "start_line": 3857, + "end_line": 3862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_dict", + "long_name": "_convert_from_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 117, + "complexity": 30, + "token_count": 752, + "parameters": [ + "obj", + "align" + ], + "start_line": 3865, + "end_line": 3991, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter2", + "long_name": "PyArray_DescrConverter2( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 37, + "parameters": [ + "obj", + "at" + ], + "start_line": 4009, + "end_line": 4016, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter", + "long_name": "PyArray_DescrConverter( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 141, + "complexity": 55, + "token_count": 886, + "parameters": [ + "obj", + "at" + ], + "start_line": 4033, + "end_line": 4213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 181, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ByteorderConverter", + "long_name": "PyArray_ByteorderConverter( PyObject * obj , char * endian)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 16, + "token_count": 218, + "parameters": [ + "obj", + "endian" + ], + "start_line": 4219, + "end_line": 4251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SortkindConverter", + "long_name": "PyArray_SortkindConverter( PyObject * obj , PyArray_SORTKIND * sortkind)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 11, + "token_count": 162, + "parameters": [ + "obj", + "sortkind" + ], + "start_line": 4257, + "end_line": 4283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EquivTypes", + "long_name": "PyArray_EquivTypes( PyArray_Descr * typ1 , PyArray_Descr * typ2)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 8, + "token_count": 138, + "parameters": [ + "typ1", + "typ2" + ], + "start_line": 4292, + "end_line": 4311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_prepend_ones", + "long_name": "_prepend_ones( PyArrayObject * arr , int nd , int ndmin)", + "filename": "multiarraymodule.c", + "nloc": 23, + "complexity": 3, + "token_count": 175, + "parameters": [ + "arr", + "nd", + "ndmin" + ], + "start_line": 4316, + "end_line": 4341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 15, + "token_count": 373, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4363, + "end_line": 4438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Empty", + "long_name": "PyArray_Empty( int nd , intp * dims , PyArray_Descr * type , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 14, + "complexity": 4, + "token_count": 96, + "parameters": [ + "nd", + "dims", + "type", + "fortran" + ], + "start_line": 4446, + "end_line": 4461, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_empty", + "long_name": "array_empty( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 2, + "token_count": 130, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4467, + "end_line": 4491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_scalar", + "long_name": "array_scalar( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 10, + "token_count": 254, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4496, + "end_line": 4554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zeros", + "long_name": "PyArray_Zeros( int nd , intp * dims , PyArray_Descr * type , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 4, + "token_count": 134, + "parameters": [ + "nd", + "dims", + "type", + "fortran" + ], + "start_line": 4563, + "end_line": 4587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_zeros", + "long_name": "array_zeros( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 2, + "token_count": 133, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4593, + "end_line": 4617, + "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": 4624, + "end_line": 4633, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_skip_sep", + "long_name": "_skip_sep( char ** ptr , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 78, + "parameters": [ + "ptr", + "sep" + ], + "start_line": 4636, + "end_line": 4647, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 133, + "complexity": 22, + "token_count": 711, + "parameters": [ + "data", + "slen", + "dtype", + "n", + "sep" + ], + "start_line": 4652, + "end_line": 4794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 143, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 2, + "token_count": 116, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4799, + "end_line": 4816, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 114, + "complexity": 22, + "token_count": 664, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4830, + "end_line": 4958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "top_nesting_level": 0 + }, + { + "name": "array_fromfile", + "long_name": "array_fromfile( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 7, + "token_count": 225, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4976, + "end_line": 5014, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromBuffer", + "long_name": "PyArray_FromBuffer( PyObject * buf , PyArray_Descr * type , intp count , intp offset)", + "filename": "multiarraymodule.c", + "nloc": 83, + "complexity": 16, + "token_count": 446, + "parameters": [ + "buf", + "type", + "count", + "offset" + ], + "start_line": 5018, + "end_line": 5111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "array_frombuffer", + "long_name": "array_frombuffer( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 121, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 5127, + "end_line": 5144, + "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": 5150, + "end_line": 5161, + "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": 5168, + "end_line": 5174, + "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": 5181, + "end_line": 5187, + "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": 5191, + "end_line": 5197, + "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": 5201, + "end_line": 5210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Arange", + "long_name": "PyArray_Arange( double start , double stop , double step , int type_num)", + "filename": "multiarraymodule.c", + "nloc": 40, + "complexity": 9, + "token_count": 300, + "parameters": [ + "start", + "stop", + "step", + "type_num" + ], + "start_line": 5217, + "end_line": 5268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "_calc_length", + "long_name": "_calc_length( PyObject * start , PyObject * stop , PyObject * step , PyObject ** next , int cmplx)", + "filename": "multiarraymodule.c", + "nloc": 31, + "complexity": 10, + "token_count": 235, + "parameters": [ + "start", + "stop", + "step", + "next", + "cmplx" + ], + "start_line": 5274, + "end_line": 5306, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArangeObj", + "long_name": "PyArray_ArangeObj( PyObject * start , PyObject * stop , PyObject * step , PyArray_Descr * dtype)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 19, + "token_count": 461, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 5313, + "end_line": 5397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "array_arange", + "long_name": "array_arange( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 100, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 5410, + "end_line": 5422, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNDArrayCVersion", + "long_name": "PyArray_GetNDArrayCVersion()", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [], + "start_line": 5428, + "end_line": 5431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array__get_ndarray_c_version", + "long_name": "array__get_ndarray_c_version( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5437, + "end_line": 5443, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_set_string_function", + "long_name": "array_set_string_function( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 98, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5449, + "end_line": 5465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "array_set_ops_function", + "long_name": "array_set_ops_function( PyObject * self , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 5471, + "end_line": 5488, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Where", + "long_name": "PyArray_Where( PyObject * condition , PyObject * x , PyObject * y)", + "filename": "multiarraymodule.c", + "nloc": 31, + "complexity": 8, + "token_count": 233, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5495, + "end_line": 5535, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_where", + "long_name": "array_where( PyObject * ignored , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 60, + "parameters": [ + "ignored", + "args" + ], + "start_line": 5543, + "end_line": 5551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_lexsort", + "long_name": "array_lexsort( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 5563, + "end_line": 5573, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_register_dtype", + "long_name": "array_register_dtype( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 3, + "token_count": 64, + "parameters": [ + "dummy", + "args" + ], + "start_line": 5582, + "end_line": 5593, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_can_cast_safely", + "long_name": "array_can_cast_safely( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 5, + "token_count": 128, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5600, + "end_line": 5623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "new_buffer", + "long_name": "new_buffer( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 7, + "complexity": 2, + "token_count": 37, + "parameters": [ + "dummy", + "args" + ], + "start_line": 5630, + "end_line": 5638, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "buffer_buffer", + "long_name": "buffer_buffer( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 120, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5647, + "end_line": 5665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "setup_scalartypes", + "long_name": "setup_scalartypes( PyObject * dict)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 10, + "token_count": 351, + "parameters": [ + "dict" + ], + "start_line": 5731, + "end_line": 5844, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 114, + "top_nesting_level": 0 + }, + { + "name": "set_flaginfo", + "long_name": "set_flaginfo( PyObject * d)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 1, + "token_count": 152, + "parameters": [ + "d" + ], + "start_line": 5849, + "end_line": 5873, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "initmultiarray", + "long_name": "initmultiarray()", + "filename": "multiarraymodule.c", + "nloc": 53, + "complexity": 15, + "token_count": 360, + "parameters": [], + "start_line": 5878, + "end_line": 5947, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "initmultiarray", + "long_name": "initmultiarray()", + "filename": "multiarraymodule.c", + "nloc": 57, + "complexity": 16, + "token_count": 392, + "parameters": [], + "start_line": 5878, + "end_line": 5953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + } + ], + "nloc": 4541, + "complexity": 1001, + "token_count": 29414, + "diff_parsed": { + "added": [ + "\tif (PyType_Ready(&PyArrayFlags_Type) < 0)", + "\t\treturn;", + "", + "\tPy_INCREF(&PyArrayFlags_Type);", + "\tPyDict_SetItemString(d, \"flagsobj\", (PyObject *)&PyArrayFlags_Type);", + "" + ], + "deleted": [] + } + }, + { + "old_path": "numpy/core/src/scalartypes.inc.src", + "new_path": "numpy/core/src/scalartypes.inc.src", + "filename": "scalartypes.inc.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -625,10 +625,7 @@ gentype_ndim_get(PyObject *self)\n static PyObject *\n gentype_flags_get(PyObject *self)\n {\n-\tstatic int flags=CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n-\n- return PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n- self, flags, 1);\n+ return PyArray_NewFlagsObject(NULL);\n }\n \n static PyObject *\n", + "added_lines": 1, + "deleted_lines": 4, + "source_code": "/* -*- c -*- */\n\nstatic int PyArrayScalar_Offset[PyArray_NTYPES+1];\n/* to be exposed in C-API */\n#define PyArrayScalar_False ((PyObject *)&_PyArrayScalar_BoolValues[0])\n#define PyArrayScalar_True ((PyObject *)&_PyArrayScalar_BoolValues[1])\n#define PyArrayScalar_RETURN_BOOL_FROM_LONG(i)\t\t\t\\\n\treturn Py_INCREF(&_PyArrayScalar_BoolValues[((i)!=0)]),\t\\\n\t\t(PyObject *)&_PyArrayScalar_BoolValues[((i)!=0)]\n#define PyArrayScalar_RETURN_FALSE\t\t\\\n\treturn Py_INCREF(PyArrayScalar_False),\t\\\n\t\tPyArrayScalar_False\n#define PyArrayScalar_RETURN_TRUE\t\t\\\n\treturn Py_INCREF(PyArrayScalar_True),\t\\\n\t\tPyArrayScalar_True\n/* end to be exposed in C-API */\n\n#define _SOFFSET_(obj, type_num) ((char *)(obj) + PyArrayScalar_Offset[(type_num)])\n\n/**begin repeat\n#name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,#\n#type=Bool, signed char, short, int, long, longlong, unsigned char, unsigned short, unsigned int, unsigned long, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, PyObject *,char#\n*/\ntypedef struct {\n\tPyObject_HEAD\n\t@type@ obval;\n} Py@name@ScalarObject;\n/**end repeat**/\n\nstatic PyBoolScalarObject _PyArrayScalar_BoolValues[] = {\n\t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 0},\n\t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 1},\n};\n\n/* Inheritance established later when tp_bases is set (or tp_base for \n single inheritance) */\n\n/**begin repeat\n\n#name=number, integer, signedinteger, unsignedinteger, inexact, floating, complexfloating, flexible, \ncharacter#\n#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating, ComplexFloating, Flexible, Character#\n*/\n\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@scalar\",\t\t /*tp_name*/\n sizeof(PyObject),\t\t /*tp_basicsize*/\n};\n/**end repeat**/\n\n\n#define PyStringScalarObject PyStringObject\n#define PyUnicodeScalarObject PyUnicodeObject\n\ntypedef struct {\n\tPyObject_VAR_HEAD\n\tchar *obval;\n\tPyArray_Descr *descr;\n\tint flags;\n\tPyObject *base;\n} PyVoidScalarObject;\n\n/* no error checking is performed -- ctypeptr must be same type as scalar */\n/* in case of flexible type, the data is not copied \n into ctypeptr which is expected to be a pointer to pointer */\n/*OBJECT_API\n Convert to c-type\n*/\nstatic void\nPyArray_ScalarAsCtype(PyObject *scalar, void *ctypeptr)\n{\n\tPyArray_Descr *typecode;\n\ttypecode = PyArray_DescrFromScalar(scalar);\n\t\n\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\tvoid **newptr = (void **)ctypeptr;\n\t\tswitch(typecode->type_num) {\n\t\tcase PyArray_STRING:\n\t\t\t*newptr = (void *)PyString_AS_STRING(scalar);\n break;\n\t\tcase PyArray_UNICODE:\n\t\t\t*newptr = (void *)PyUnicode_AS_DATA(scalar);\n break;\n\t\tdefault:\n\t\t\t*newptr = ((PyVoidScalarObject *)scalar)->obval;\n break;\n\t\t}\n\t\treturn;\n\t}\n\tmemcpy(ctypeptr, _SOFFSET_(scalar, typecode->type_num),\n\t typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn;\n}\n\n/* The output buffer must be large-enough to receive the value */\n/* Even for flexible types which is different from ScalarAsCtype\n where only a reference for flexible types is returned \n*/\n\n/*OBJECT_API\n Cast Scalar to c-type\n*/\nstatic int\nPyArray_CastScalarToCtype(PyObject *scalar, void *ctypeptr, \n\t\t\t PyArray_Descr *outcode)\n{\n\tPyArray_Descr* descr;\n\t\n\tdescr = PyArray_DescrFromScalar(scalar);\n\tif (PyTypeNum_ISEXTENDED(descr->type_num) ||\n\t PyTypeNum_ISEXTENDED(outcode->type_num)) {\n\t\tPyArrayObject *ain, *aout;\n\n\t\tain = (PyArrayObject *)PyArray_FromScalar(scalar, NULL);\n\t\tif (ain == NULL) {Py_DECREF(descr); return -1;}\n\t\taout = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t outcode,\n\t\t\t\t\t 0, NULL, \n\t\t\t\t\t NULL, ctypeptr, \n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\t\tif (aout == NULL) {Py_DECREF(ain); return -1;}\n\t\tdescr->f->cast[outcode->type_num](ain->data, \n\t\t\t\t\t aout->data, 1, ain, aout);\n\t\tPy_DECREF(ain);\n\t\tPy_DECREF(aout);\n\t}\n\telse {\n\t\tdescr->f->cast[outcode->type_num](_SOFFSET_(scalar, \n\t\t\t\t\t\t\t descr->type_num), \n\t\t\t\t\t ctypeptr, 1, NULL, NULL);\n\t}\n\tPy_DECREF(descr);\n\treturn 0;\n}\n\n/* 0-dim array from array-scalar object */\n/* always contains a copy of the data \n unless outcode is NULL, it is of void type and the referrer does\n not own it either.\n*/\n\n/* steals reference to outcode */\n/*OBJECT_API\n Get 0-dim array from scalar\n*/\nstatic PyObject *\nPyArray_FromScalar(PyObject *scalar, PyArray_Descr *outcode)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *r;\n\tchar *memptr;\n\tPyObject *ret;\n\n\t/* convert to 0-dim array of scalar typecode */\n\ttypecode = PyArray_DescrFromScalar(scalar);\n\tif ((typecode->type_num == PyArray_VOID) &&\t\t\t\\\n\t !(((PyVoidScalarObject *)scalar)->flags & OWNDATA) &&\t\\\n\t outcode == NULL) {\n\t\tr = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t typecode,\n\t\t\t\t\t 0, NULL, NULL,\n\t\t\t\t\t ((PyVoidScalarObject *)scalar)->obval,\n\t\t\t\t\t ((PyVoidScalarObject *)scalar)->flags,\n\t\t\t\t\t NULL);\n\t\tPyArray_BASE(r) = (PyObject *)scalar;\n\t\tPy_INCREF(scalar);\n\t\treturn r;\n\t}\n\tr = PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t typecode,\n\t\t\t\t 0, NULL, \n\t\t\t\t NULL, NULL, 0, NULL);\n\tif (r==NULL) {Py_XDECREF(outcode); return NULL;}\n\n\tswitch(typecode->type_num) {\n\tcase PyArray_STRING:\n\t\tmemptr = PyString_AS_STRING(scalar);\n\t\tbreak;\n\tcase PyArray_UNICODE:\n\t\tmemptr = (char *)PyUnicode_AS_DATA(scalar);\n#ifdef Py_UNICODE_WIDE\n\t\tbreak;\n#else\n\t\tPyUCS2Buffer_AsUCS4((Py_UNICODE *)memptr, \n\t\t\t\t (PyArray_UCS4 *)PyArray_DATA(r),\n\t\t\t\t PyUnicode_GET_SIZE(scalar),\n\t\t\t\t PyArray_ITEMSIZE(r) >> 2);\n goto finish;\n#endif\n\tdefault:\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tmemptr = (((PyVoidScalarObject *)scalar)->obval);\n\t\t}\n\t\telse {\n\t\t\tmemptr = _SOFFSET_(scalar, typecode->type_num);\n\t\t}\n\t\tbreak;\n\t}\n\n\tmemcpy(PyArray_DATA(r), memptr, PyArray_ITEMSIZE(r));\n\tif (PyArray_ISOBJECT(r)) {\n\t\tPy_INCREF(*((PyObject **)memptr));\n\t}\n#ifndef Py_UNICODE_WIDE\n finish:\t\n#endif\n\tif (outcode == NULL) return r;\n\t\n\tif (outcode->type_num == typecode->type_num) {\n\t\tif (!PyTypeNum_ISEXTENDED(typecode->type_num))\n\t\t\treturn r;\n\t\tif (outcode->elsize == typecode->elsize);\n\t\treturn r;\t\t\t\n\t}\n\t\n\t/* cast if necessary to desired output typecode */\n\tret = PyArray_CastToType((PyArrayObject *)r, outcode, 0);\n\tPy_DECREF(r);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n const size_t size = _PyObject_VAR_SIZE(type, nitems+1);\n\n obj = (PyObject *)_pya_malloc(size);\n\tmemset(obj, 0, size);\n\tif (type->tp_itemsize == 0)\n PyObject_INIT(obj, type);\n else\n (void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems);\n return obj;\n}\n\nstatic void\ngentype_dealloc(PyObject *v) \n{\n\tv->ob_type->tp_free(v);\n}\n\n\nstatic PyObject *\ngentype_power(PyObject *m1, PyObject *m2, PyObject *m3)\n{\n\tPyObject *arr, *ret, *arg2;\n\tchar *msg=\"unsupported operand type(s) for ** or pow()\";\n\t\n\tif (!PyArray_IsScalar(m1,Generic)) {\n\t\tif (PyArray_Check(m1)) {\n\t\t\tret = m1->ob_type->tp_as_number->nb_power(m1,m2, \n\t\t\t\t\t\t\t\t Py_None);\n\t\t}\n\t\telse {\n\t\t\tif (!PyArray_IsScalar(m2,Generic)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tarr = PyArray_FromScalar(m2, NULL);\n\t\t\tif (arr == NULL) return NULL;\n\t\t\tret = arr->ob_type->tp_as_number->nb_power(m1, arr,\n\t\t\t\t\t\t\t\t Py_None);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t\treturn ret;\n\t}\n\tif (!PyArray_IsScalar(m2, Generic)) {\n\t\tif (PyArray_Check(m2)) {\n\t\t\tret = m2->ob_type->tp_as_number->nb_power(m1,m2, \n\t\t\t\t\t\t\t\t Py_None);\n\t\t}\n\t\telse {\n\t\t\tif (!PyArray_IsScalar(m1, Generic)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tarr = PyArray_FromScalar(m1, NULL);\n\t\t\tif (arr == NULL) return NULL;\n\t\t\tret = arr->ob_type->tp_as_number->nb_power(arr, m2,\n\t\t\t\t\t\t\t\t Py_None);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t\treturn ret;\n\t}\n\tarr=arg2=NULL;\n\tarr = PyArray_FromScalar(m1, NULL);\n\targ2 = PyArray_FromScalar(m2, NULL);\t\n\tif (arr == NULL || arg2 == NULL) {\n\t\tPy_XDECREF(arr); Py_XDECREF(arg2); return NULL;\n\t}\n\tret = arr->ob_type->tp_as_number->nb_power(arr, arg2, Py_None);\n\tPy_DECREF(arr);\n\tPy_DECREF(arg2);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_generic_method(PyObject *self, PyObject *args, PyObject *kwds, \n\t\t char *str)\n{\n\tPyObject *arr, *meth, *ret;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tmeth = PyObject_GetAttrString(arr, str);\n\tif (meth == NULL) {Py_DECREF(arr); return NULL;}\n\tif (kwds == NULL) \n\t\tret = PyObject_CallObject(meth, args);\n\telse\n\t\tret = PyObject_Call(meth, args, kwds);\n\tPy_DECREF(meth);\n\tPy_DECREF(arr);\n if (ret && PyArray_Check(ret))\n return PyArray_Return((PyArrayObject *)ret);\n else\n return ret;\n}\n\n/**begin repeat\n\n#name=add, subtract, divide, remainder, divmod, lshift, rshift, and, xor, or, floor_divide, true_divide#\n#PYNAME=Add, Subtract, Divide, Remainder, Divmod, Lshift, Rshift, And, Xor, Or, FloorDivide, TrueDivide#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *m1, PyObject *m2)\n{\n\treturn PyArray_Type.tp_as_number->nb_@name@(m1, m2);\n}\n/**end repeat**/\n\n\nstatic PyObject *\ngentype_multiply(PyObject *m1, PyObject *m2)\n{\n\tPyObject *ret=NULL;\n\tlong repeat;\n\n\tif (!PyArray_IsScalar(m1, Generic) && \n\t ((m1->ob_type->tp_as_number == NULL) ||\n\t (m1->ob_type->tp_as_number->nb_multiply == NULL))) {\n\t\t/* Try to convert m2 to an int and try sequence\n\t\t repeat */\n\t\trepeat = PyInt_AsLong(m2);\n\t\tif (repeat == -1 && PyErr_Occurred()) return NULL;\n\t\tret = PySequence_Repeat(m1, (int) repeat);\n\t}\n\telse if (!PyArray_IsScalar(m2, Generic) && \n\t\t ((m2->ob_type->tp_as_number == NULL) ||\n\t\t (m2->ob_type->tp_as_number->nb_multiply == NULL))) {\n\t\t/* Try to convert m1 to an int and try sequence\n\t\t repeat */\n\t\trepeat = PyInt_AsLong(m1);\n\t\tif (repeat == -1 && PyErr_Occurred()) return NULL;\n\t\tret = PySequence_Repeat(m2, (int) repeat);\n\t}\n\tif (ret==NULL) {\n\t\tPyErr_Clear(); /* no effect if not set */\n\t\tret = PyArray_Type.tp_as_number->nb_multiply(m1, m2);\n\t}\n\treturn ret;\n}\n\n/**begin repeat\n\n#name=positive, negative, absolute, invert, int, long, float, oct, hex#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *m1)\n{\n\tPyObject *arr, *ret;\n\n\tarr = PyArray_FromScalar(m1, NULL);\n\tif (arr == NULL) return NULL;\n\tret = arr->ob_type->tp_as_number->nb_@name@(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n/**end repeat**/\n\nstatic int\ngentype_nonzero_number(PyObject *m1)\n{\n\tPyObject *arr;\n\tint ret;\n\n\tarr = PyArray_FromScalar(m1, NULL);\n\tif (arr == NULL) return -1;\n\tret = arr->ob_type->tp_as_number->nb_nonzero(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_str(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret, *tmp;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tif (arr==NULL) return NULL;\n\tret = PyObject_Str((tmp=arr->descr->f->getitem(arr->data, arr)));\n\tPy_DECREF(arr);\n\tPy_XDECREF(tmp);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_repr(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret, *tmp ;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tif (arr==NULL) return NULL;\n\tret = PyObject_Repr((tmp=arr->descr->f->getitem(arr->data, arr)));\n\tPy_DECREF(arr);\n\tPy_XDECREF(tmp);\n\treturn ret;\n}\n\nstatic void\nformat_longdouble(char *buf, size_t buflen, longdouble val, int precision)\n{\n register char *cp;\n\n PyOS_snprintf(buf, buflen, \"%.*\" LONGDOUBLE_FMT, precision, val);\n cp = buf;\n if (*cp == '-')\n cp++;\n for (; *cp != '\\0'; cp++) {\n if (!isdigit(Py_CHARMASK(*cp)))\n break;\n }\n if (*cp == '\\0') {\n *cp++ = '.';\n *cp++ = '0';\n *cp++ = '\\0';\n }\n}\n\n/* over-ride repr and str of array-scalar strings and unicode to \n remove NULL bytes and then call the corresponding functions \n of string and unicode. \n */\n\n/**begin repeat\n#name=string*2,unicode*2#\n#form=(repr,str)*2#\n#Name=String*2,Unicode*2#\n#NAME=STRING*2,UNICODE*2#\n#extra=AndSize*2,,#\n#type=char*2, Py_UNICODE*2#\n*/\nstatic PyObject *\n@name@type_@form@(PyObject *self)\n{\n\tconst @type@ *dptr, *ip;\n\tint len;\n\tPyObject *new;\n\tPyObject *ret;\n\n\tip = dptr = Py@Name@_AS_@NAME@(self);\n\tlen = Py@Name@_GET_SIZE(self);\n\tdptr += len-1;\n\twhile(len > 0 && *dptr-- == 0) len--;\n\tnew = Py@Name@_From@Name@@extra@(ip, len);\n\tif (new == NULL) return PyString_FromString(\"\");\n\tret = Py@Name@_Type.tp_@form@(new);\n\tPy_DECREF(new);\n\treturn ret;\n}\n/**end repeat**/\n\n\n\n#if SIZEOF_LONGDOUBLE == SIZEOF_DOUBLE\n#define PREC_REPR 17\n#define PREC_STR 17\n#else\n#define PREC_REPR 21\n#define PREC_STR 21\n#endif\n\nstatic PyObject *\nlongdoubletype_repr(PyObject *self)\n{\n static char buf[100];\n format_longdouble(buf, sizeof(buf), ((PyLongDoubleScalarObject *)self)->obval, PREC_REPR);\n return PyString_FromString(buf);\n}\n\nstatic PyObject *\nclongdoubletype_repr(PyObject *self)\n{\n static char buf1[100];\n static char buf2[100];\n\tstatic char buf3[202];\n clongdouble x;\n x = ((PyCLongDoubleScalarObject *)self)->obval;\n format_longdouble(buf1, sizeof(buf1), x.real, PREC_REPR);\n format_longdouble(buf2, sizeof(buf2), x.imag, PREC_REPR);\n\n\tsnprintf(buf3, sizeof(buf3), \"(%s+%sj)\", buf1, buf2);\n\treturn PyString_FromString(buf3);\n}\n\n#define longdoubletype_str longdoubletype_repr\n#define clongdoubletype_str clongdoubletype_repr\n\n/** Could improve this with a PyLong_FromLongDouble(longdouble ldval)\n but this would need some more work...\n**/\n\n/**begin repeat\n\n#name=(int, long, hex, oct, float)*2#\n#KIND=(Long*4, Float)*2#\n#char=,,,,,c*5#\n#CHAR=,,,,,C*5#\n#POST=,,,,,.real*5#\n*/\nstatic PyObject *\n@char@longdoubletype_@name@(PyObject *self)\n{\n\tdouble dval;\n\tPyObject *obj, *ret;\n\t\n\tdval = (double)(((Py@CHAR@LongDoubleScalarObject *)self)->obval)@POST@;\n\tobj = Py@KIND@_FromDouble(dval);\n\tret = obj->ob_type->tp_as_number->nb_@name@(obj);\n\tPy_DECREF(obj);\n\treturn ret;\n}\n/**end repeat**/\n\n#if PY_VERSION_HEX >= 0x02050000\n/* This needs a better implementation */\nstatic Py_ssize_t\ngentype_index(PyObject *self)\n{\n\tPyObject *obj;\n\tif (!(PyArray_IsScalar(self, Integer))) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"not an integer type.\");\n\t\treturn -1;\n\t}\n\tobj = gentype_int(self);\n\tif (obj == NULL) return -1;\n\treturn PyInt_AsSsize_t(obj);\t\n}\n#endif\n\n\nstatic PyNumberMethods gentype_as_number = {\n (binaryfunc)gentype_add,\t\t /*nb_add*/\n (binaryfunc)gentype_subtract,\t\t /*nb_subtract*/\n (binaryfunc)gentype_multiply,\t\t /*nb_multiply*/\n (binaryfunc)gentype_divide,\t\t /*nb_divide*/\n (binaryfunc)gentype_remainder,\t /*nb_remainder*/\n (binaryfunc)gentype_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)gentype_power,\t\t /*nb_power*/\n (unaryfunc)gentype_negative,\t \n (unaryfunc)gentype_positive, \t /*nb_pos*/ \n (unaryfunc)gentype_absolute,\t\t /*(unaryfunc)gentype_abs,*/\n (inquiry)gentype_nonzero_number,\t\t /*nb_nonzero*/\n (unaryfunc)gentype_invert,\t\t /*nb_invert*/\n (binaryfunc)gentype_lshift,\t /*nb_lshift*/\n (binaryfunc)gentype_rshift,\t /*nb_rshift*/\n (binaryfunc)gentype_and,\t /*nb_and*/\n (binaryfunc)gentype_xor,\t /*nb_xor*/\n (binaryfunc)gentype_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)gentype_int,\t\t /*nb_int*/\n (unaryfunc)gentype_long,\t\t /*nb_long*/\n (unaryfunc)gentype_float,\t\t /*nb_float*/\n (unaryfunc)gentype_oct,\t\t /*nb_oct*/\n (unaryfunc)gentype_hex,\t\t /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)gentype_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)gentype_true_divide,\t /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n\t(lenfunc)gentype_index, /* nb_index */\n#endif\n};\n\n\nstatic PyObject *\ngentype_richcompare(PyObject *self, PyObject *other, int cmp_op) \n{\n\n\tPyObject *arr, *ret;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tret = arr->ob_type->tp_richcompare(arr, other, cmp_op);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_ndim_get(PyObject *self)\n{\n\treturn PyInt_FromLong(0);\n}\n\nstatic PyObject *\ngentype_flags_get(PyObject *self)\n{\n return PyArray_NewFlagsObject(NULL);\n}\n\nstatic PyObject *\nvoidtype_flags_get(PyVoidScalarObject *self)\n{\n\treturn PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 1);\n}\n\nstatic PyObject *\nvoidtype_dtypedescr_get(PyVoidScalarObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n\nstatic PyObject *\ngentype_shape_get(PyObject *self)\n{\n\treturn PyTuple_New(0);\n}\n\n/*\nstatic int\ngentype_shape_set(PyObject *self, PyObject *val)\n{\n\tif (!PyTuple_Check(val) || PyTuple_GET_SIZE(val) > 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \\\n\t\t\t\t\"invalid shape for scalar\");\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n*/\n\nstatic PyObject *\ngentype_dataptr_get(PyObject *self)\n{\n\treturn Py_BuildValue(\"NO\",PyString_FromString(\"\"),Py_True);\n}\n\n\nstatic PyObject *\ngentype_data_get(PyObject *self)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\n\ttypecode = PyArray_DescrFromScalar(self);\n\tret = PyBuffer_FromObject(self, 0, typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\n\nstatic PyObject *\ngentype_itemsize_get(PyObject *self)\n{\t\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\n\ttypecode = PyArray_DescrFromScalar(self);\n\tret = PyInt_FromLong((long) typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_size_get(PyObject *self)\n{\n\treturn PyInt_FromLong(1);\n}\n\nstatic void\ngentype_struct_free(void *ptr, void *arr)\n{\n Py_DECREF((PyObject *)arr);\n _pya_free(ptr);\n}\n\nstatic PyObject *\ngentype_struct_get(PyObject *self)\n{\n PyArrayObject *arr;\n PyArrayInterface *inter;\n \n arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = 0;\n inter->flags = arr->flags;\n inter->typekind = arr->descr->kind;\n inter->itemsize = arr->descr->elsize;\n inter->strides = NULL;\n inter->shape = NULL;\n inter->data = arr->data;\n return PyCObject_FromVoidPtrAndDesc(inter, arr, gentype_struct_free);\n}\n\nstatic PyObject *\ngentype_typestr_get(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tret = PyObject_GetAttrString((PyObject *)arr->descr, \"str\");\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_descr_get(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tret = PyObject_GetAttrString((PyObject *)arr, \"__array_descr__\");\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\n\nstatic PyObject *\ngentype_typedescr_get(PyObject *self)\n{\n\treturn (PyObject *)PyArray_DescrFromScalar(self);\n}\n\n\nstatic PyObject *\ngentype_base_get(PyObject *self)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic PyArray_Descr *\n_realdescr_fromcomplexscalar(PyObject *self, int *typenum)\n{\n\tif PyArray_IsScalar(self, CDouble) {\n\t\t*typenum = PyArray_CDOUBLE;\n\t\treturn PyArray_DescrFromType(PyArray_DOUBLE);\n\t}\n\tif PyArray_IsScalar(self, CFloat) {\n\t\t*typenum = PyArray_CFLOAT;\n\t\treturn PyArray_DescrFromType(PyArray_FLOAT);\n\t}\n\tif PyArray_IsScalar(self, CLongDouble) {\n\t\t*typenum = PyArray_CLONGDOUBLE;\n\t\treturn PyArray_DescrFromType(PyArray_LONGDOUBLE);\n\t}\n\treturn NULL;\n}\n\nstatic PyObject *\ngentype_real_get(PyObject *self)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\tint typenum;\n\n\tif (PyArray_IsScalar(self, ComplexFloating)) {\n\t\ttypecode = _realdescr_fromcomplexscalar(self, &typenum);\n\t\tret = PyArray_Scalar(_SOFFSET_(self, typenum), typecode,\n\t\t\t\t NULL);\n\t\tPy_DECREF(typecode);\n\t\treturn ret;\n\t}\n\telse if PyArray_IsScalar(self, Object) {\n\t\tPyObject *obj = ((PyObjectScalarObject *)self)->obval;\n\t\tret = PyObject_GetAttrString(obj, \"real\");\n\t\tif (ret != NULL) return ret;\n\t\tPyErr_Clear();\n\t}\n\tPy_INCREF(self);\n\treturn (PyObject *)self;\n}\n\nstatic PyObject *\ngentype_imag_get(PyObject *self)\n{\t\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\t\n\tint typenum;\n\t\n\ttypecode = _realdescr_fromcomplexscalar(self, &typenum);\n\tif (PyArray_IsScalar(self, ComplexFloating)) {\n\t\tret = PyArray_Scalar(_SOFFSET_(self, typenum)\t\t\\\n\t\t\t\t + typecode->elsize, typecode, NULL);\n\t}\n\telse if PyArray_IsScalar(self, Object) {\n\t\tPyObject *obj = ((PyObjectScalarObject *)self)->obval;\n\t\tPyArray_Descr *newtype;\n\t\tret = PyObject_GetAttrString(obj, \"imag\");\n\t\tif (ret == NULL) {\n\t\t\tPyErr_Clear();\n\t\t\tobj = PyInt_FromLong(0);\n\t\t\tnewtype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\t\tret = PyArray_Scalar((char *)&obj, newtype, NULL);\n\t\t\tPy_DECREF(newtype);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tchar *temp;\n\t\ttemp = PyDataMem_NEW(typecode->elsize);\n\t\tmemset(temp, '\\0', typecode->elsize);\n\t\tret = PyArray_Scalar(temp, typecode, NULL);\n\t\tPyDataMem_FREE(temp);\n\t}\n\t\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_flat_get(PyObject *self)\n{\n\tPyObject *ret, *arr;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tret = PyArray_IterNew(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyGetSetDef gentype_getsets[] = {\n {\"ndim\", \n\t (getter)gentype_ndim_get, \n\t (setter) 0, \n\t \"number of array dimensions\"},\n {\"flags\", \n\t (getter)gentype_flags_get, \n\t (setter)0, \n\t \"integer value of flags\"},\n {\"shape\", \n\t (getter)gentype_shape_get, \n\t (setter)0, \n\t \"tuple of array dimensions\"},\n {\"strides\", \n\t (getter)gentype_shape_get, \n\t (setter) 0, \n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)gentype_data_get, \n\t (setter) 0, \n\t \"pointer to start of data\"},\n {\"itemsize\", \n\t (getter)gentype_itemsize_get, \n\t (setter)0, \n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)gentype_size_get,\n (setter)0,\n \"number of elements in the gentype\"},\n {\"nbytes\",\n (getter)gentype_itemsize_get,\n (setter)0,\n \"length of item in bytes\"},\n\t{\"base\",\n\t (getter)gentype_base_get,\n\t (setter)0,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)gentype_typedescr_get,\n\t NULL,\n\t \"get array data-descriptor\"},\n {\"real\", \n\t (getter)gentype_real_get, \n\t (setter)0,\n\t \"real part of scalar\"},\n {\"imag\", \n\t (getter)gentype_imag_get, \n\t (setter)0, \n\t \"imaginary part of scalar\"},\n\t{\"flat\", \n\t (getter)gentype_flat_get, \n\t (setter)0, \n\t \"a 1-d view of scalar\"}, \n\t{\"__array_data__\", \n\t (getter)gentype_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)gentype_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)gentype_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)gentype_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)gentype_shape_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)gentype_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t/* Does not have __array_priority__ because it is not a subtype.\n\t */\n \t{NULL, NULL, NULL, NULL} /* Sentinel */\n};\n\n\n/* 0-dim array from scalar object */\n\nstatic char doc_getarray[] = \"sc.__array__(|type) return 0-dim array\";\n\nstatic PyObject *\ngentype_getarray(PyObject *scalar, PyObject *args) \n{\n\tPyArray_Descr *outcode=NULL;\n\tPyObject *ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", &PyArray_DescrConverter,\n\t\t\t &outcode)) return NULL;\n\tret = PyArray_FromScalar(scalar, outcode);\n\treturn ret;\n}\n\nstatic char doc_sc_wraparray[] = \"sc.__array_wrap__(obj) return scalar from array\";\n\nstatic PyObject *\ngentype_wraparray(PyObject *scalar, PyObject *args)\n{\n\tPyObject *arr;\n\n\tif (PyTuple_Size(args) < 1) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"only accepts 1 argument.\");\n\t\treturn NULL;\n\t}\n\tarr = PyTuple_GET_ITEM(args, 0);\n\tif (!PyArray_Check(arr)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"can only be called with ndarray object\");\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_Scalar(PyArray_DATA(arr), PyArray_DESCR(arr), arr);\n}\n\n\n/**begin repeat\n\n#name=tolist, item, tostring, astype, copy, __deepcopy__, choose, searchsorted, reshape, view, swapaxes, conj, conjugate, nonzero, flatten, ravel, fill, transpose, newbyteorder#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *self, PyObject *args)\n{\n\treturn gentype_generic_method(self, args, NULL, \"@name@\");\n}\n/**end repeat**/\n\nstatic PyObject *\ngentype_squeeze(PyObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\tPy_INCREF(self);\n\treturn self;\n}\n\nstatic int\ngentype_getreadbuf(PyObject *, int, void **);\n\nstatic PyObject *\ngentype_byteswap(PyObject *self, PyObject *args)\n{\n\tBool inplace=FALSE;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter, &inplace))\n\t\treturn NULL;\n\t\n\tif (inplace) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot byteswap a scalar in-place\");\n\t\treturn NULL;\n\t}\n\telse {\n\t\t/* get the data, copyswap it and pass it to a new Array scalar\n\t\t */\n\t\tchar *data;\n\t\tint numbytes;\n\t\tPyArray_Descr *descr;\n\t\tPyObject *new;\n\t\tchar *newmem;\n\n\t\tnumbytes = gentype_getreadbuf(self, 0, (void **)&data);\n\t\tdescr = PyArray_DescrFromScalar(self);\n\t\tnewmem = _pya_malloc(descr->elsize);\n\t\tif (newmem == NULL) {Py_DECREF(descr); return PyErr_NoMemory();}\n\t\telse memcpy(newmem, data, descr->elsize);\n\t\tdescr->f->copyswap(newmem, NULL, 1, descr->elsize);\n\t\tnew = PyArray_Scalar(newmem, descr, NULL);\n\t\t_pya_free(newmem);\n\t\tPy_DECREF(descr);\n\t\treturn new;\n\t}\n}\n\n\n/**begin repeat\n\n#name=take, getfield, put, putmask, repeat, tofile, mean, trace, diagonal, clip, std, var, sum, cumsum, prod, cumprod, compress, sort, argsort, round, argmax, argmin, max, min, ptp, any, all, resize#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\treturn gentype_generic_method(self, args, kwds, \"@name@\");\n}\n/**end repeat**/\n\nstatic PyObject *\nvoidtype_getfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyObject *ret;\n\n\tret = gentype_generic_method((PyObject *)self, args, kwds, \"getfield\");\n\tif (!ret) return ret;\n\tif (PyArray_IsScalar(ret, Generic) &&\t\\\n\t (!PyArray_IsScalar(ret, Void))) {\n\t\tPyArray_Descr *new;\n\t\tif (!PyArray_ISNBO(self->descr->byteorder)) {\n\t\t\tnew = PyArray_DescrFromScalar(ret);\n\t\t\tnew->f->copyswap(_SOFFSET_(ret, \n\t\t\t\t\t\t new->type_num),\n\t\t\t\t\t NULL, 1, new->elsize);\n\t\t\tPy_DECREF(new);\n\t\t}\n\t}\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_setfield(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\t\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"Can't set fields in a non-void array scalar.\");\n\treturn NULL;\n}\t\n\nstatic PyObject *\nvoidtype_setfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *typecode;\n\tint offset = 0;\n\tPyObject *value, *src;\n\tint mysize;\n\tchar *dptr;\n\tstatic char *kwlist[] = {\"value\", \"dtype\", \"offset\", 0};/* XXX ? */\n\t\n\tif ((self->flags & WRITEABLE) != WRITEABLE) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"Can't write to memory\");\n\t\treturn NULL;\n\t}\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO&|i\", kwlist,\n\t\t\t\t\t &value,\n\t\t\t\t\t PyArray_DescrConverter, \n\t\t\t\t\t &typecode, &offset)) return NULL;\n\n\tmysize = self->ob_size;\n\t\n\tif (offset < 0 || (offset + typecode->elsize) > mysize) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need 0 <= offset <= %d for requested type \" \\\n\t\t\t \"but received offset = %d\",\n\t\t\t mysize-typecode->elsize, offset);\n\t\tPy_DECREF(typecode);\n\t\treturn NULL;\n\t}\t\n\n\tdptr = self->obval + offset;\n\n\t/* Copy data from value to correct place in dptr */\n src = PyArray_FromAny(value, typecode, 0, 0, CARRAY_FLAGS, NULL);\n if (src == NULL) return NULL;\n\ttypecode->f->copyswap(dptr, PyArray_DATA(src), \n\t\t\t !PyArray_ISNBO(self->descr->byteorder),\n\t\t\t PyArray_ITEMSIZE(src));\n\tPy_DECREF(src);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic PyObject *\ngentype_reduce(PyObject *self, PyObject *args)\n{\n\tPyObject *ret=NULL, *obj=NULL, *mod=NULL;\n\tconst char *buffer; \n\tint buflen;\n\n\t/* Return a tuple of (callable object, arguments) */\n\n\tret = PyTuple_New(2);\n\tif (ret == NULL) return NULL;\t\n\tif (PyObject_AsReadBuffer(self, (const void **)&buffer, &buflen)<0) {\n\t\tPy_DECREF(ret); return NULL;\n\t}\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) return NULL;\n\tobj = PyObject_GetAttrString(mod, \"scalar\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) return NULL;\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tobj = PyObject_GetAttrString((PyObject *)self, \"dtype\");\n\tif PyArray_IsScalar(self, Object) {\n\t\tmod = ((PyObjectScalarObject *)self)->obval;\n\t\tPyTuple_SET_ITEM(ret, 1,\n\t\t\t\t Py_BuildValue(\"NO\", obj, mod));\n\t}\n\telse {\n\t\tmod = PyString_FromStringAndSize(buffer, buflen);\n\t\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t\t Py_BuildValue(\"NN\", obj, mod));\n\t}\n\treturn ret;\n}\n\n/* ignores everything */\nstatic PyObject *\ngentype_setstate(PyObject *self, PyObject *args)\n{\n\tPy_INCREF(Py_None);\n\treturn (Py_None);\n}\n\nstatic PyObject *\ngentype_dump(PyObject *self, PyObject *args)\n{\n\tPyObject *file=NULL;\n\tint ret;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &file))\n\t\treturn NULL;\n\tret = PyArray_Dump(self, file, 2);\n\tif (ret < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyObject *\ngentype_dumps(PyObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\"))\n\t\treturn NULL;\n\treturn PyArray_Dumps(self, 2);\n}\n\n\n/* setting flags cannot be done for scalars */\nstatic PyObject *\ngentype_setflags(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* need to fill in doc-strings for these methods on import -- copy from \n array docstrings \n*/\nstatic PyMethodDef gentype_methods[] = {\n {\"tolist\",\t (PyCFunction)gentype_tolist,\t1, NULL},\n {\"item\", (PyCFunction)gentype_item, METH_VARARGS, NULL},\n\t{\"tofile\", (PyCFunction)gentype_tofile, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"tostring\", (PyCFunction)gentype_tostring, METH_VARARGS, NULL},\n {\"byteswap\", (PyCFunction)gentype_byteswap,1, NULL},\n {\"astype\", (PyCFunction)gentype_astype, 1, NULL},\n\t{\"getfield\", (PyCFunction)gentype_getfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{\"setfield\", (PyCFunction)gentype_setfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n {\"copy\", (PyCFunction)gentype_copy, 1, NULL}, \n {\"resize\", (PyCFunction)gentype_resize, 1, NULL}, \n\n\t{\"__array__\", (PyCFunction)gentype_getarray, 1, doc_getarray},\n\t{\"__array_wrap__\", (PyCFunction)gentype_wraparray, 1, doc_sc_wraparray},\n\n /* for the copy module */\n {\"__copy__\", (PyCFunction)gentype_copy, 1, NULL},\n {\"__deepcopy__\", (PyCFunction)gentype___deepcopy__, 1, NULL},\n\n\n {\"__reduce__\", (PyCFunction) gentype_reduce, 1, NULL},\t\n\t/* For consistency does nothing */\n\t{\"__setstate__\", (PyCFunction) gentype_setstate, 1, NULL},\n\n\t{\"dumps\", (PyCFunction) gentype_dumps, 1, NULL},\n\t{\"dump\", (PyCFunction) gentype_dump, 1, NULL},\n\n\t/* Methods for array */\n\t{\"fill\", (PyCFunction)gentype_fill,\n\t METH_VARARGS, NULL},\n\t{\"transpose\",\t(PyCFunction)gentype_transpose, \n\t METH_VARARGS, NULL},\n\t{\"take\",\t(PyCFunction)gentype_take, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"put\",\t(PyCFunction)gentype_put, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"putmask\",\t(PyCFunction)gentype_putmask, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"repeat\",\t(PyCFunction)gentype_repeat, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"choose\",\t(PyCFunction)gentype_choose, \n\t METH_VARARGS, NULL},\t\n\t{\"sort\",\t(PyCFunction)gentype_sort, \n\t METH_VARARGS, NULL},\n\t{\"argsort\",\t(PyCFunction)gentype_argsort, \n\t METH_VARARGS, NULL},\n\t{\"searchsorted\", (PyCFunction)gentype_searchsorted, \n\t METH_VARARGS, NULL},\t\n\t{\"argmax\",\t(PyCFunction)gentype_argmax, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"argmin\", (PyCFunction)gentype_argmin,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"reshape\",\t(PyCFunction)gentype_reshape, \n\t METH_VARARGS, NULL},\n\t{\"squeeze\",\t(PyCFunction)gentype_squeeze, \n\t METH_VARARGS, NULL},\n\t{\"view\", (PyCFunction)gentype_view, \n\t METH_VARARGS, NULL},\n\t{\"swapaxes\", (PyCFunction)gentype_swapaxes,\n\t METH_VARARGS, NULL},\n\t{\"max\", (PyCFunction)gentype_max,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"min\", (PyCFunction)gentype_min,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"ptp\", (PyCFunction)gentype_ptp,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"mean\", (PyCFunction)gentype_mean,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"trace\", (PyCFunction)gentype_trace,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"diagonal\", (PyCFunction)gentype_diagonal,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"clip\", (PyCFunction)gentype_clip,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"conj\", (PyCFunction)gentype_conj,\n\t METH_VARARGS, NULL},\n\t{\"conjugate\", (PyCFunction)gentype_conjugate,\n\t METH_VARARGS, NULL},\n\t{\"nonzero\", (PyCFunction)gentype_nonzero,\n\t METH_VARARGS, NULL},\n\t{\"std\", (PyCFunction)gentype_std,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"var\", (PyCFunction)gentype_var,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"sum\", (PyCFunction)gentype_sum,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"cumsum\", (PyCFunction)gentype_cumsum,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"prod\", (PyCFunction)gentype_prod,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"cumprod\", (PyCFunction)gentype_cumprod,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"all\", (PyCFunction)gentype_all,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"any\", (PyCFunction)gentype_any,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"compress\", (PyCFunction)gentype_compress,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"flatten\", (PyCFunction)gentype_flatten,\n\t METH_VARARGS, NULL},\n\t{\"ravel\", (PyCFunction)gentype_ravel,\n\t METH_VARARGS, NULL},\n\t{\"round\", (PyCFunction)gentype_round,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"setflags\", (PyCFunction)gentype_setflags,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"newbyteorder\", (PyCFunction)gentype_newbyteorder,\n\t METH_VARARGS, NULL},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\nstatic PyGetSetDef voidtype_getsets[] = {\n {\"flags\", \n\t (getter)voidtype_flags_get, \n\t (setter)0, \n\t \"integer value of flags\"},\n\t{\"dtype\",\n\t (getter)voidtype_dtypedescr_get,\n\t (setter)0,\n\t \"dtype object\"},\n\t{NULL, NULL}\n};\n\nstatic PyMethodDef voidtype_methods[] = {\n\t{\"getfield\", (PyCFunction)voidtype_getfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{\"setfield\", (PyCFunction)voidtype_setfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{NULL, NULL}\n};\n\n/************* As_mapping functions for void array scalar ************/\n\nstatic int\nvoidtype_length(PyVoidScalarObject *self) \n{\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\treturn 0;\n\t}\n\telse { /* return the number of fields */\n\t\tPyObject *key;\n\t\tPyObject *flist;\n\t\tkey = PyInt_FromLong(-1);\n\t\tflist = PyDict_GetItem(self->descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!flist) return 0;\n\t\treturn PyTuple_GET_SIZE(flist);\n\t}\n}\n\n/* get field by name or number */\nstatic PyObject *\nvoidtype_subscript(PyVoidScalarObject *self, PyObject *ind)\n{\n\tint n, m;\n\tchar *msg = \"invalid index\";\n\tPyObject *flist=NULL, *key, *fieldinfo;\n\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"can't index void scalar without fields\");\n\t\treturn NULL;\n\t}\n\n\tif (PyString_Check(ind) || PyUnicode_Check(ind)) {\n\t\t/* look up in fields */\n\t\tfieldinfo = PyDict_GetItem(self->descr->fields, ind);\n\t\tif (!fieldinfo) {\n\t\t\tPyErr_SetString(PyExc_IndexError, msg);\n\t\t\treturn NULL;\n\t\t}\n\t\treturn voidtype_getfield(self, fieldinfo, NULL);\n\t}\n\t\n\t/* try to convert it to a number */\n\tn = PyArray_PyIntAsIntp(ind);\n\tif (error_converting(n)) {\n\t\tPyErr_Clear();\n\t\tgoto fail;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tflist = PyDict_GetItem(self->descr->fields, key);\n\tPy_DECREF(key);\n\tif (!flist) m = 0; \n\tm = PyTuple_GET_SIZE(flist);\n\tif (n < 0) n += m;\n\tif (n < 0 || n >= m) goto fail;\n\tfieldinfo = PyDict_GetItem(self->descr->fields, \n\t\t\t\t PyTuple_GET_ITEM(flist, n));\n\treturn voidtype_getfield(self, fieldinfo, NULL);\n\n fail:\n\tPyErr_SetString(PyExc_IndexError, msg);\n\treturn NULL;\n}\n\nstatic int\nvoidtype_ass_subscript(PyVoidScalarObject *self, PyObject *ind, PyObject *val) \n{\n\tint n, m;\n\tchar *msg = \"invalid index\";\n\tPyObject *flist=NULL, *key, *fieldinfo, *newtup;\n\tPyObject *res;\n\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"can't index void scalar without fields\");\n\t\treturn -1;\n\t}\n\n\tif (PyString_Check(ind) || PyUnicode_Check(ind)) {\n\t\t/* look up in fields */\n\t\tfieldinfo = PyDict_GetItem(self->descr->fields, ind);\n\t\tif (!fieldinfo) {\n\t\t\tPyErr_SetString(PyExc_IndexError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tnewtup = Py_BuildValue(\"(OOO)\", val, \n\t\t\t\t PyTuple_GET_ITEM(fieldinfo, 0),\n\t\t\t\t PyTuple_GET_ITEM(fieldinfo, 1));\n\t\tres = voidtype_setfield(self, newtup, NULL);\n\t\tPy_DECREF(newtup);\n\t\tif (!res) return -1;\n\t\tPy_DECREF(res);\n\t\treturn 0;\n\t}\n\t\n\t/* try to convert it to a number */\n\tn = PyArray_PyIntAsIntp(ind);\n\tif (error_converting(n)) {\n\t\tPyErr_Clear();\n\t\tgoto fail;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tflist = PyDict_GetItem(self->descr->fields, key);\n\tPy_DECREF(key);\n\tif (!flist) m = 0; \n\tm = PyTuple_GET_SIZE(flist);\n\tif (n < 0) n += m;\n\tif (n < 0 || n >= m) goto fail;\n\tfieldinfo = PyDict_GetItem(self->descr->fields, \n\t\t\t\t PyTuple_GET_ITEM(flist, n));\n\tnewtup = Py_BuildValue(\"(OOO)\", val, \n\t\t\t PyTuple_GET_ITEM(fieldinfo, 0),\n\t\t\t PyTuple_GET_ITEM(fieldinfo, 1));\n\tres = voidtype_setfield(self, fieldinfo, NULL);\n\tPy_DECREF(newtup);\n\tif (!res) return -1;\n\tPy_DECREF(res);\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_IndexError, msg);\n\treturn -1;\n}\n\nstatic PyMappingMethods voidtype_as_mapping = {\n (inquiry)voidtype_length,\t\t /*mp_length*/\n (binaryfunc)voidtype_subscript,\t /*mp_subscript*/\n (objobjargproc)voidtype_ass_subscript,\t /*mp_ass_subscript*/\n};\n\n\nstatic int\ngentype_getreadbuf(PyObject *self, int segment, void **ptrptr)\n{\n\tint numbytes;\n\tPyArray_Descr *outcode;\n\t\n\tif (segment != 0) {\n\t\tPyErr_SetString(PyExc_SystemError, \n\t\t\t\t\"Accessing non-existent array segment\");\n\t\treturn -1;\n\t}\n\n\toutcode = PyArray_DescrFromScalar(self);\n\tnumbytes = outcode->elsize;\n\tif PyArray_IsScalar(self, Flexible) {\n\t\tif PyArray_IsScalar(self, String)\n\t\t\t*ptrptr = PyString_AS_STRING(self);\n\t\telse if PyArray_IsScalar(self, Unicode)\n\t\t\t*ptrptr = (char *)PyUnicode_AS_DATA(self);\n\t\telse if PyArray_IsScalar(self, Void)\n\t\t\t*ptrptr = ((PyVoidScalarObject *)self)->obval;\n\t}\n\telse \n\t\t*ptrptr = (void *)_SOFFSET_(self, outcode->type_num);\n\n\tPy_DECREF(outcode);\n\treturn numbytes;\n}\n\nstatic int\ngentype_getsegcount(PyObject *self, int *lenp)\n{\n\tPyArray_Descr *outcode;\n\n\toutcode = PyArray_DescrFromScalar(self);\n\tif (lenp)\n\t\t*lenp = outcode->elsize;\n\tPy_DECREF(outcode);\n\treturn 1;\n}\n\nstatic int\ngentype_getcharbuf(PyObject *self, int segment, const char **ptrptr)\n{\n\tif (PyArray_IsScalar(self, String) ||\t\\\n\t PyArray_IsScalar(self, Unicode))\n\t\treturn gentype_getreadbuf(self, segment, (void **)ptrptr);\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"Non-character array cannot be interpreted \"\\\n\t\t\t\t\"as character buffer.\");\n\t\treturn -1;\n\t}\n}\n\n\nstatic PyBufferProcs gentype_as_buffer = {\n (getreadbufferproc)gentype_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)0, /*bf_getwritebuffer*/\n (getsegcountproc)gentype_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)gentype_getcharbuf, /*bf_getcharbuffer*/\n};\n\n\n#define BASEFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES\n#define LEAFFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES\n\nstatic PyTypeObject PyGenericArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"genericscalar\",\t /*tp_name*/\n sizeof(PyObject),\t\t /*tp_basicsize*/\n};\n\nstatic void\nunicode_dealloc(PyObject *v) \n{\n\tPyDataMem_FREE(((PyVoidScalarObject *)v)->obval);\n\tv->ob_type->tp_free(v);\n}\n\nstatic void\nvoid_dealloc(PyVoidScalarObject *v) \n{\n\tif (v->flags & OWNDATA)\n\t\tPyDataMem_FREE(v->obval);\n\tPy_XDECREF(v->descr);\n\tPy_XDECREF(v->base);\n\tv->ob_type->tp_free(v);\n}\n\nstatic void\nobject_arrtype_dealloc(PyObject *v)\n{\n\tPy_XDECREF(((PyObjectScalarObject *)v)->obval);\n\tv->ob_type->tp_free(v);\n}\n\n/* string and unicode inherit from Python Type first and so GET_ITEM is different to\n get to the Python Type.\n */\n\n/**begin repeat \n#name=byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, object#\n#TYPE=BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, STRING, UNICODE, OBJECT#\n#num=1*16,0,0,1#\n*/\nstatic PyObject *\n@name@_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj=NULL;\n\tPyObject *arr;\n\tPyArray_Descr *typecode;\n\n\tif (type->tp_bases && (PyTuple_GET_SIZE(type->tp_bases)==2)) {\n\t\tPyTypeObject *sup;\n\t\tPyObject *ret;\n\t\t/* We are inheriting from a Python type as well so\n\t\t give it first dibs on conversion */\n\t\tsup = (PyTypeObject *)PyTuple_GET_ITEM(type->tp_bases, @num@);\n\t\tret = sup->tp_new(type, args, kwds);\n\t\tif (ret) return ret;\n\t\tPyErr_Clear();\n\t\t/* now do default conversion */\n\t}\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\n\ttypecode = PyArray_DescrFromType(PyArray_@TYPE@);\n\tarr = PyArray_FromAny(obj, typecode, 0, 0, FORCECAST, NULL);\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n/**end repeat**/\n\n/* bool->tp_new only returns Py_True or Py_False */\nstatic PyObject *\nbool_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj=NULL;\n\tPyObject *arr;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\tif (obj == Py_False)\n\t\tPyArrayScalar_RETURN_FALSE;\n\tif (obj == Py_True)\n\t\tPyArrayScalar_RETURN_TRUE;\n\tarr = PyArray_FROM_OTF(obj, PyArray_BOOL, FORCECAST);\n\tif (arr && 0 == PyArray_NDIM(arr)) {\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)PyArray_DATA(arr));\n\t}\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n\nstatic PyObject *\nbool_arrtype_and(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)&(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_and(a, b);\n}\n\nstatic PyObject *\nbool_arrtype_or(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)|(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_or(a, b);\n}\n\nstatic PyObject *\nbool_arrtype_xor(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)^(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_xor(a, b);\n}\n\nstatic int\nbool_arrtype_nonzero(PyObject *a)\n{\n\treturn a == PyArrayScalar_True;\n}\n\n/* Arithmetic methods -- only so we can override &, |, ^. */\nstatic PyNumberMethods bool_arrtype_as_number = {\n\t0,\t\t\t\t\t/* nb_add */\n\t0,\t\t\t\t\t/* nb_subtract */\n\t0,\t\t\t\t\t/* nb_multiply */\n\t0,\t\t\t\t\t/* nb_divide */\n\t0,\t\t\t\t\t/* nb_remainder */\n\t0,\t\t\t\t\t/* nb_divmod */\n\t0,\t\t\t\t\t/* nb_power */\n\t0,\t\t\t\t\t/* nb_negative */\n\t0,\t\t\t\t\t/* nb_positive */\n\t0,\t\t\t\t\t/* nb_absolute */\n\t(inquiry)bool_arrtype_nonzero,\t\t/* nb_nonzero */\n\t0,\t\t\t\t\t/* nb_invert */\n\t0,\t\t\t\t\t/* nb_lshift */\n\t0,\t\t\t\t\t/* nb_rshift */\n\t(binaryfunc)bool_arrtype_and,\t\t/* nb_and */\n\t(binaryfunc)bool_arrtype_xor,\t\t/* nb_xor */\n\t(binaryfunc)bool_arrtype_or,\t\t/* nb_or */\n};\n\nstatic PyObject *\nvoid_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj, *arr;\n\tulonglong memu=1;\n\tPyObject *new=NULL;\n\tchar *destptr;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\t/* For a VOID scalar first see if obj is an integer or long \n\t and create new memory of that size (filled with 0) for the scalar\n\t*/\n\n\tif (PyLong_Check(obj) || PyInt_Check(obj) || \\\n\t PyArray_IsScalar(obj, Integer) ||\n\t (PyArray_Check(obj) && PyArray_NDIM(obj)==0 &&\t\\\n\t PyArray_ISINTEGER(obj))) {\n\t\tnew = obj->ob_type->tp_as_number->nb_long(obj);\n\t}\n\tif (new && PyLong_Check(new)) {\n\t\tPyObject *ret;\n\t\tmemu = PyLong_AsUnsignedLongLong(new);\n\t\tPy_DECREF(new);\n\t\tif (PyErr_Occurred() || (memu > MAX_INT)) {\n\t\t\tPyErr_Clear();\n\t\t\tPyErr_Format(PyExc_OverflowError, \n\t\t\t\t \"size must be smaller than %d\",\n\t\t\t\t (int) MAX_INT);\n\t\t\treturn NULL;\n\t\t}\n\t\tdestptr = PyDataMem_NEW((int) memu);\n\t\tif (destptr == NULL) return PyErr_NoMemory();\n\t\tret = type->tp_alloc(type, 0);\n\t\tif (ret == NULL) {\n\t\t\tPyDataMem_FREE(destptr);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\t((PyVoidScalarObject *)ret)->obval = destptr;\n\t\t((PyVoidScalarObject *)ret)->ob_size = (int) memu;\n\t\t((PyVoidScalarObject *)ret)->descr = \\\n\t\t\tPyArray_DescrNewFromType(PyArray_VOID);\n\t\t((PyVoidScalarObject *)ret)->descr->elsize = (int) memu;\n\t\t((PyVoidScalarObject *)ret)->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t((PyVoidScalarObject *)ret)->base = NULL;\n\t\tmemset(destptr, '\\0', (size_t) memu);\n\t\treturn ret;\n\t}\n\n\tarr = PyArray_FROM_OTF(obj, PyArray_VOID, FORCECAST);\n return PyArray_Return((PyArrayObject *)arr);\n}\n\n\n/**************** Define Hash functions ********************/\n\n/**begin repeat\n#lname=bool,ubyte,ushort#\n#name=Bool,UByte, UShort#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n return (long)(((Py@name@ScalarObject *)obj)->obval);\n}\n/**end repeat**/\n\n/**begin repeat\n#lname=byte,short,uint,ulong#\n#name=Byte,Short,UInt,ULong#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((Py@name@ScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n/**end repeat**/\n\n#if SIZEOF_INT != SIZEOF_LONG\nstatic long\nint_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((PyIntScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n#endif\n\n/**begin repeat\n#char=,u#\n#Char=,U#\n#ext=&& (x >= LONG_MIN),#\n*/\n#if SIZEOF_LONG != SIZEOF_LONGLONG\n/* we assume SIZEOF_LONGLONG=2*SIZEOF_LONG */\nstatic long\n@char@longlong_arrtype_hash(PyObject *obj)\n{\n long y;\n @char@longlong x = (((Py@Char@LongLongScalarObject *)obj)->obval);\n\n if ((x <= LONG_MAX)@ext@) {\n y = (long) x;\n }\n else {\n union Mask {\n long hashvals[2];\n @char@longlong v;\n } both;\n\n both.v = x;\n y = both.hashvals[0] + (1000003)*both.hashvals[1];\n }\n if (y == -1) y = -2;\n return y;\n}\n#endif\n/**end repeat**/\n\n#if SIZEOF_LONG==SIZEOF_LONGLONG\nstatic long\nulonglong_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((PyULongLongScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n#endif\n\n\n\n/* Wrong thing to do for longdouble, but....*/\n/**begin repeat\n#lname=float, longdouble#\n#name=Float, LongDouble#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n return _Py_HashDouble((double) ((Py@name@ScalarObject *)obj)->obval);\n}\n\n/* borrowed from complex_hash */\nstatic long\nc@lname@_arrtype_hash(PyObject *obj)\n{\n long hashreal, hashimag, combined;\n hashreal = _Py_HashDouble((double) \\\n (((PyC@name@ScalarObject *)obj)->obval).real);\n\n if (hashreal == -1) return -1;\n hashimag = _Py_HashDouble((double) \\\n (((PyC@name@ScalarObject *)obj)->obval).imag);\n if (hashimag == -1) return -1;\n\n combined = hashreal + 1000003 * hashimag;\n if (combined == -1) combined = -2;\n return combined;\n}\n/**end repeat**/\n\nstatic long\nobject_arrtype_hash(PyObject *obj)\n{\n return PyObject_Hash(((PyObjectScalarObject *)obj)->obval);\n}\n\n/* just hash the pointer */\nstatic long\nvoid_arrtype_hash(PyObject *obj)\n{\n return _Py_HashPointer((void *)(((PyVoidScalarObject *)obj)->obval));\n}\n\n/*object arrtype getattro and setattro */\nstatic PyObject *\nobject_arrtype_getattro(PyObjectScalarObject *obj, PyObject *attr) {\n\tPyObject *res;\n\n\t/* first look in object and then hand off to generic type */\n\n\tres = PyObject_GenericGetAttr(obj->obval, attr);\t\n\tif (res) return res;\n\tPyErr_Clear();\n\treturn \tPyObject_GenericGetAttr((PyObject *)obj, attr);\n}\n\nstatic int\nobject_arrtype_setattro(PyObjectScalarObject *obj, PyObject *attr, PyObject *val) {\n\tint res;\n\t/* first look in object and then hand off to generic type */\n\n\tres = PyObject_GenericSetAttr(obj->obval, attr, val);\n\tif (res >= 0) return res;\n\tPyErr_Clear();\n\treturn PyObject_GenericSetAttr((PyObject *)obj, attr, val);\n}\n\nstatic PyObject *\nobject_arrtype_concat(PyObjectScalarObject *self, PyObject *other)\n{\n\treturn PySequence_Concat(self->obval, other);\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_length(PyObjectScalarObject *self) \n{\n\treturn PyObject_Length(self->obval);\n}\n\nstatic PyObject *\nobject_arrtype_repeat(PyObjectScalarObject *self, _int_or_ssize_t count)\n{\n\treturn PySequence_Repeat(self->obval, count);\n}\n\nstatic PyObject *\nobject_arrtype_subscript(PyObjectScalarObject *self, PyObject *key)\n{\n\treturn PyObject_GetItem(self->obval, key);\n}\n\nstatic int\nobject_arrtype_ass_subscript(PyObjectScalarObject *self, PyObject *key, \n\t\t\t PyObject *value)\n{\n\treturn PyObject_SetItem(self->obval, key, value);\n}\n\nstatic int\nobject_arrtype_contains(PyObjectScalarObject *self, PyObject *ob)\n{\n\treturn PySequence_Contains(self->obval, ob);\n}\n\nstatic PyObject *\nobject_arrtype_inplace_concat(PyObjectScalarObject *self, PyObject *o)\n{\n\treturn PySequence_InPlaceConcat(self->obval, o);\n}\n\nstatic PyObject *\nobject_arrtype_inplace_repeat(PyObjectScalarObject *self, _int_or_ssize_t count)\n{\n\treturn PySequence_InPlaceRepeat(self->obval, count);\n}\n\nstatic PySequenceMethods object_arrtype_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)object_arrtype_length, /*sq_length*/\n (binaryfunc)object_arrtype_concat, /*sq_concat*/\n (ssizeargfunc)object_arrtype_repeat, /*sq_repeat*/\n 0, /*sq_item*/\n 0, /*sq_slice*/\n 0, /* sq_ass_item */\n 0, /* sq_ass_slice */\n (objobjproc)object_arrtype_contains, /* sq_contains */\n (binaryfunc)object_arrtype_inplace_concat, /* sq_inplace_concat */\n (ssizeargfunc)object_arrtype_inplace_repeat, /* sq_inplace_repeat */\n#else\n (inquiry)object_arrtype_length, /*sq_length*/\n (binaryfunc)object_arrtype_concat, /*sq_concat*/\n (intargfunc)object_arrtype_repeat, /*sq_repeat*/\n 0, /*sq_item*/\n 0, /*sq_slice*/\n 0, /* sq_ass_item */\n 0, /* sq_ass_slice */\n (objobjproc)object_arrtype_contains, /* sq_contains */\n (binaryfunc)object_arrtype_inplace_concat, /* sq_inplace_concat */\n (intargfunc)object_arrtype_inplace_repeat, /* sq_inplace_repeat */\n#endif\n};\n\nstatic PyMappingMethods object_arrtype_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)object_arrtype_length,\n (binaryfunc)object_arrtype_subscript,\n (objobjargproc)object_arrtype_ass_subscript,\n#else\n (inquiry)object_arrtype_length,\n (binaryfunc)object_arrtype_subscript,\n (objobjargproc)object_arrtype_ass_subscript,\n#endif\n};\n\nstatic _int_or_ssize_t\nobject_arrtype_getsegcount(PyObjectScalarObject *self, _int_or_ssize_t *lenp) \n{\n\tint newlen;\n\tint cnt;\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\t\n\tif (pb == NULL || \\\n\t pb->bf_getsegcount == NULL || \\\n\t (cnt = (*pb->bf_getsegcount)(self->obval, &newlen)) != 1) \n\t\treturn 0;\n\t\n\tif (lenp) \n\t\t*lenp = newlen;\n\t\n\treturn cnt;\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_getreadbuf(PyObjectScalarObject *self, _int_or_ssize_t segment, void **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getreadbuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a readable buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getreadbuffer)(self->obval, segment, ptrptr);\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_getwritebuf(PyObjectScalarObject *self, _int_or_ssize_t segment, void **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getwritebuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a writeable buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getwritebuffer)(self->obval, segment, ptrptr);\n}\n\nstatic _int_or_ssize_t \nobject_arrtype_getcharbuf(PyObjectScalarObject *self, _int_or_ssize_t segment, \n\t\t\t const char **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getcharbuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a character buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getcharbuffer)(self->obval, segment, ptrptr);\n}\n\nstatic PyBufferProcs object_arrtype_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)object_arrtype_getreadbuf,\n (writebufferproc)object_arrtype_getwritebuf,\n (segcountproc)object_arrtype_getsegcount,\n (charbufferproc)object_arrtype_getcharbuf,\n#else\n (getreadbufferproc)object_arrtype_getreadbuf,\n (getwritebufferproc)object_arrtype_getwritebuf,\n (getsegcountproc)object_arrtype_getsegcount,\n (getcharbufferproc)object_arrtype_getcharbuf,\n#endif\n};\n\nstatic PyObject *\nobject_arrtype_call(PyObjectScalarObject *obj, PyObject *args, PyObject *kwds)\n{\n\treturn PyObject_Call(obj->obval, args, kwds);\n}\n\nstatic PyTypeObject PyObjectArrType_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"objectscalar\",\t /*tp_name*/\n sizeof(PyObjectScalarObject),\t /*tp_basicsize*/\n 0, /* tp_itemsize */\n (destructor)object_arrtype_dealloc, /* tp_dealloc */\n 0, /* tp_print */\n 0, /* tp_getattr */\n 0, /* tp_setattr */\n 0, /* tp_compare */\n 0, /* tp_repr */\n 0, /* tp_as_number */\n &object_arrtype_as_sequence, /* tp_as_sequence */\n &object_arrtype_as_mapping, /* tp_as_mapping */\n 0, /* tp_hash */\n (ternaryfunc)object_arrtype_call, /* tp_call */\n 0, /* tp_str */\n (getattrofunc)object_arrtype_getattro, /* tp_getattro */\n (setattrofunc)object_arrtype_setattro, /* tp_setattro */\n &object_arrtype_as_buffer, /* tp_as_buffer */\n 0, /* tp_flags */\n};\n\n/**begin repeat\n#name=bool, string, unicode, void#\n#NAME=Bool, String, Unicode, Void#\n*/\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@scalar\",\t /*tp_name*/\n sizeof(Py@NAME@ScalarObject),\t /*tp_basicsize*/\n};\n/**end repeat**/\n\n/**begin repeat\n#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n#name=int*5, uint*5, float*3, complex*3#\n#CNAME=(CHAR, SHORT, INT, LONG, LONGLONG)*2, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n*/\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@\" STRBITSOF_@CNAME@ \"scalar\",\t /*tp_name*/\n sizeof(Py@NAME@ScalarObject),\t /*tp_basicsize*/\n};\n\n/**end repeat**/\n\n\nstatic PyNumberMethods longdoubletype_as_number;\nstatic PyNumberMethods clongdoubletype_as_number;\n\n\nstatic void\ninitialize_numeric_types(void)\n{\n\tPyGenericArrType_Type.tp_dealloc = (destructor)gentype_dealloc;\n\tPyGenericArrType_Type.tp_as_number = &gentype_as_number;\n\tPyGenericArrType_Type.tp_as_buffer = &gentype_as_buffer;\n\tPyGenericArrType_Type.tp_flags = BASEFLAGS;\n\tPyGenericArrType_Type.tp_methods = gentype_methods;\n\tPyGenericArrType_Type.tp_getset = gentype_getsets;\n\tPyGenericArrType_Type.tp_new = NULL;\n PyGenericArrType_Type.tp_alloc = gentype_alloc;\n\tPyGenericArrType_Type.tp_free = _pya_free;\n\tPyGenericArrType_Type.tp_repr = gentype_repr;\n\tPyGenericArrType_Type.tp_str = gentype_str;\n\tPyGenericArrType_Type.tp_richcompare = gentype_richcompare;\n\n\tPyBoolArrType_Type.tp_as_number = &bool_arrtype_as_number;\n\n\tPyStringArrType_Type.tp_alloc = NULL;\n\tPyStringArrType_Type.tp_free = NULL;\n\t\n\tPyStringArrType_Type.tp_repr = stringtype_repr;\n\tPyStringArrType_Type.tp_str = stringtype_str;\n\n\tPyUnicodeArrType_Type.tp_repr = unicodetype_repr;\n\tPyUnicodeArrType_Type.tp_str = unicodetype_str;\n\n\tPyVoidArrType_Type.tp_methods = voidtype_methods;\n\tPyVoidArrType_Type.tp_getset = voidtype_getsets;\n\tPyVoidArrType_Type.tp_as_mapping = &voidtype_as_mapping;\n\t\n\t/**begin repeat\n#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating, \nComplexFloating, Flexible, Character#\n\t*/\n Py@NAME@ArrType_Type.tp_flags = BASEFLAGS;\n\t/**end repeat**/\n\n\t/**begin repeat\n#name=bool, byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, void, object#\n#NAME=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, String, Unicode, Void, Object#\n\t*/\n\tPy@NAME@ArrType_Type.tp_flags = LEAFFLAGS;\n\tPy@NAME@ArrType_Type.tp_new = @name@_arrtype_new;\n\tPy@NAME@ArrType_Type.tp_richcompare = gentype_richcompare;\n\t/**end repeat**/\n\t/* Allow the Void type to be subclassed -- for adding new types */\n\tPyVoidArrType_Type.tp_flags = BASEFLAGS;\n\n /**begin repeat\n#name=bool, byte, short, ubyte, ushort, uint, ulong, ulonglong, float, longdouble, cfloat, clongdouble, void, object#\n#NAME=Bool, Byte, Short, UByte, UShort, UInt, ULong, ULongLong, Float, LongDouble, CFloat, CLongDouble, Void, Object#\n */\n Py@NAME@ArrType_Type.tp_hash = @name@_arrtype_hash;\n /**end repeat**/\n\n#if SIZEOF_INT != SIZEOF_LONG\n /* We won't be inheriting from Python Int type. */\n PyIntArrType_Type.tp_hash = int_arrtype_hash;\n#endif\n\n#if SIZEOF_LONG != SIZEOF_LONGLONG\n /* We won't be inheriting from Python Int type. */\n PyLongLongArrType_Type.tp_hash = longlong_arrtype_hash;\n#endif\n\n\t/* These need to be coded specially because getitem does not\n\t return a normal Python type\n\t*/\n\tPyLongDoubleArrType_Type.tp_as_number = &longdoubletype_as_number;\n\tPyCLongDoubleArrType_Type.tp_as_number = &clongdoubletype_as_number;\n\n\t/**begin repeat\n#name=int, long, hex, oct, float, repr, str#\n#kind=tp_as_number->nb*5, tp*2#\n\t*/\n\tPyLongDoubleArrType_Type.@kind@_@name@ = longdoubletype_@name@;\n\tPyCLongDoubleArrType_Type.@kind@_@name@ = clongdoubletype_@name@;\n\t/**end repeat**/\n\n\tPyStringArrType_Type.tp_itemsize = sizeof(char);\n\tPyVoidArrType_Type.tp_dealloc = (destructor) void_dealloc;\n\tPyUnicodeArrType_Type.tp_dealloc = unicode_dealloc;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMapIter_Type.tp_iter = PyObject_SelfIter;\n\n/**begin repeat\n#name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,#\n#num=BOOL, BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, OBJECT, NTYPES#\n**/\n PyArrayScalar_Offset[PyArray_@num@] = (int) offsetof(Py@name@ScalarObject, obval);\n/**end repeat**/\n}\n\n\n/* the order of this table is important */\nstatic PyTypeObject *typeobjects[] = {\n &PyBoolArrType_Type,\n &PyByteArrType_Type,\n\t&PyUByteArrType_Type,\n &PyShortArrType_Type,\n &PyUShortArrType_Type,\n\t&PyIntArrType_Type,\n\t&PyUIntArrType_Type,\n\t&PyLongArrType_Type,\n\t&PyULongArrType_Type,\n\t&PyLongLongArrType_Type,\n\t&PyULongLongArrType_Type,\n\t&PyFloatArrType_Type,\n\t&PyDoubleArrType_Type,\n\t&PyLongDoubleArrType_Type,\n\t&PyCFloatArrType_Type,\n\t&PyCDoubleArrType_Type,\n\t&PyCLongDoubleArrType_Type,\n\t&PyObjectArrType_Type,\n\t&PyStringArrType_Type,\n\t&PyUnicodeArrType_Type,\n\t&PyVoidArrType_Type\n};\n\nstatic int\n_typenum_fromtypeobj(PyObject *type, int user)\n{\n\tint typenum, i;\n\n\ttypenum = PyArray_NOTYPE;\n i = 0;\n\twhile(i < PyArray_NTYPES) {\n\t\tif (type == (PyObject *)typeobjects[i]) {\n\t\t\ttypenum = i;\n\t\t\tbreak;\n\t\t}\n i++;\n\t}\n\t\n\tif (!user) return typenum;\n\n\t/* Search any registered types */\n\ti = 0;\n\twhile (i < PyArray_NUMUSERTYPES) {\n\t\tif (type == (PyObject *)(userdescrs[i]->typeobj)) {\n\t\t\ttypenum = i + PyArray_USERDEF;\n\t\t\tbreak;\n\t\t}\n\t\ti++;\n\t}\n\treturn typenum;\n}\n\n/* new reference */\nstatic PyArray_Descr *\nPyArray_DescrFromTypeObject(PyObject *type)\n{\t\n\tint typenum;\n\tPyArray_Descr *new, *conv=NULL;\n\n\t/* if it's a builtin type, then use the typenumber */\n\ttypenum = _typenum_fromtypeobj(type,1);\t\n\tif (typenum != PyArray_NOTYPE) {\n\t\tnew = PyArray_DescrFromType(typenum);\n\t\tif (PyTypeNum_ISUSERDEF(typenum)) goto finish;\n\t\treturn new;\n\t}\n\n\t/* Check the generic types */\n\tif ((type == (PyObject *) &PyNumberArrType_Type) ||\t\t\\\n\t (type == (PyObject *) &PyInexactArrType_Type) ||\t\t\\\n\t (type == (PyObject *) &PyFloatingArrType_Type))\n\t\ttypenum = PyArray_DOUBLE;\n\telse if (type == (PyObject *)&PyComplexFloatingArrType_Type)\n\t\ttypenum = PyArray_CDOUBLE;\n\telse if ((type == (PyObject *)&PyIntegerArrType_Type) ||\t\\\n\t\t (type == (PyObject *)&PySignedIntegerArrType_Type))\n\t\ttypenum = PyArray_LONG;\n\telse if (type == (PyObject *) &PyUnsignedIntegerArrType_Type)\n\t\ttypenum = PyArray_ULONG;\n\telse if (type == (PyObject *) &PyCharacterArrType_Type)\n\t\ttypenum = PyArray_STRING;\n\telse if ((type == (PyObject *) &PyGenericArrType_Type) || \\\n\t\t (type == (PyObject *) &PyFlexibleArrType_Type))\n\t\ttypenum = PyArray_VOID;\n\n\tif (typenum != PyArray_NOTYPE) {\n\t\treturn PyArray_DescrFromType(typenum);\n\t}\n\t\n\t/* Otherwise --- type is a sub-type of an array scalar\n\t currently only VOID allows it -- use it as the type-object.\n\t*/\n\t/* look for a dtypedescr attribute */\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\n finish:\n\tconv = _arraydescr_fromobj(type);\n\tif (conv) {\n\t\tnew->fields = conv->fields;\n\t\tPy_INCREF(new->fields);\n\t\tnew->elsize = conv->elsize;\n\t\tnew->subarray = conv->subarray;\n\t\tconv->subarray = NULL;\n\t\tPy_DECREF(conv);\n\t}\n Py_DECREF(new->typeobj);\n new->typeobj = (PyTypeObject *)type;\n Py_INCREF(type);\n\treturn new;\n}\n\n/* New reference */\n/*OBJECT_API\n Return descr object from array scalar.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromScalar(PyObject *sc)\n{\n\tint type_num;\n\tPyArray_Descr *descr;\n\n\tif PyArray_IsScalar(sc, Void) {\n\t\tdescr = ((PyVoidScalarObject *)sc)->descr;\n\t\tPy_INCREF(descr);\n\t\treturn descr;\n\t}\n descr = PyArray_DescrFromTypeObject((PyObject *)sc->ob_type);\n if (descr->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(descr);\n type_num = descr->type_num;\n\t\tif (type_num == PyArray_STRING) \n\t\t\tdescr->elsize = PyString_GET_SIZE(sc);\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tdescr->elsize = PyUnicode_GET_DATA_SIZE(sc);\n#ifndef Py_UNICODE_WIDE\n\t\t\tdescr->elsize <<= 1;\n#endif\t\t\n\t\t}\n\t\telse {\n\t\t\tdescr->elsize =\t\t\t\t\t\\\n\t\t\t\t((PyVoidScalarObject *)sc)->ob_size;\n\t\t\tdescr->fields = PyObject_GetAttrString(sc, \"fields\");\n\t\t\tif (!descr->fields || !PyDict_Check(descr->fields) || \\\n\t\t\t (descr->fields == Py_None)) {\n\t\t\t\tPy_XDECREF(descr->fields);\n\t\t\t\tdescr->fields = NULL;\n\t\t\t}\n\t\t\tPyErr_Clear();\n\t\t}\n }\n\treturn descr;\n}\n\n/* New reference */\n/*OBJECT_API\n Get a typeobject from a type-number\n*/\nstatic PyObject *\nPyArray_TypeObjectFromType(int type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr == NULL) return NULL;\n\tobj = (PyObject *)descr->typeobj;\n\tPy_INCREF(obj);\n\tPy_DECREF(descr);\n\treturn obj;\n}\n\n", + "source_code_before": "/* -*- c -*- */\n\nstatic int PyArrayScalar_Offset[PyArray_NTYPES+1];\n/* to be exposed in C-API */\n#define PyArrayScalar_False ((PyObject *)&_PyArrayScalar_BoolValues[0])\n#define PyArrayScalar_True ((PyObject *)&_PyArrayScalar_BoolValues[1])\n#define PyArrayScalar_RETURN_BOOL_FROM_LONG(i)\t\t\t\\\n\treturn Py_INCREF(&_PyArrayScalar_BoolValues[((i)!=0)]),\t\\\n\t\t(PyObject *)&_PyArrayScalar_BoolValues[((i)!=0)]\n#define PyArrayScalar_RETURN_FALSE\t\t\\\n\treturn Py_INCREF(PyArrayScalar_False),\t\\\n\t\tPyArrayScalar_False\n#define PyArrayScalar_RETURN_TRUE\t\t\\\n\treturn Py_INCREF(PyArrayScalar_True),\t\\\n\t\tPyArrayScalar_True\n/* end to be exposed in C-API */\n\n#define _SOFFSET_(obj, type_num) ((char *)(obj) + PyArrayScalar_Offset[(type_num)])\n\n/**begin repeat\n#name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,#\n#type=Bool, signed char, short, int, long, longlong, unsigned char, unsigned short, unsigned int, unsigned long, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, PyObject *,char#\n*/\ntypedef struct {\n\tPyObject_HEAD\n\t@type@ obval;\n} Py@name@ScalarObject;\n/**end repeat**/\n\nstatic PyBoolScalarObject _PyArrayScalar_BoolValues[] = {\n\t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 0},\n\t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 1},\n};\n\n/* Inheritance established later when tp_bases is set (or tp_base for \n single inheritance) */\n\n/**begin repeat\n\n#name=number, integer, signedinteger, unsignedinteger, inexact, floating, complexfloating, flexible, \ncharacter#\n#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating, ComplexFloating, Flexible, Character#\n*/\n\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@scalar\",\t\t /*tp_name*/\n sizeof(PyObject),\t\t /*tp_basicsize*/\n};\n/**end repeat**/\n\n\n#define PyStringScalarObject PyStringObject\n#define PyUnicodeScalarObject PyUnicodeObject\n\ntypedef struct {\n\tPyObject_VAR_HEAD\n\tchar *obval;\n\tPyArray_Descr *descr;\n\tint flags;\n\tPyObject *base;\n} PyVoidScalarObject;\n\n/* no error checking is performed -- ctypeptr must be same type as scalar */\n/* in case of flexible type, the data is not copied \n into ctypeptr which is expected to be a pointer to pointer */\n/*OBJECT_API\n Convert to c-type\n*/\nstatic void\nPyArray_ScalarAsCtype(PyObject *scalar, void *ctypeptr)\n{\n\tPyArray_Descr *typecode;\n\ttypecode = PyArray_DescrFromScalar(scalar);\n\t\n\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\tvoid **newptr = (void **)ctypeptr;\n\t\tswitch(typecode->type_num) {\n\t\tcase PyArray_STRING:\n\t\t\t*newptr = (void *)PyString_AS_STRING(scalar);\n break;\n\t\tcase PyArray_UNICODE:\n\t\t\t*newptr = (void *)PyUnicode_AS_DATA(scalar);\n break;\n\t\tdefault:\n\t\t\t*newptr = ((PyVoidScalarObject *)scalar)->obval;\n break;\n\t\t}\n\t\treturn;\n\t}\n\tmemcpy(ctypeptr, _SOFFSET_(scalar, typecode->type_num),\n\t typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn;\n}\n\n/* The output buffer must be large-enough to receive the value */\n/* Even for flexible types which is different from ScalarAsCtype\n where only a reference for flexible types is returned \n*/\n\n/*OBJECT_API\n Cast Scalar to c-type\n*/\nstatic int\nPyArray_CastScalarToCtype(PyObject *scalar, void *ctypeptr, \n\t\t\t PyArray_Descr *outcode)\n{\n\tPyArray_Descr* descr;\n\t\n\tdescr = PyArray_DescrFromScalar(scalar);\n\tif (PyTypeNum_ISEXTENDED(descr->type_num) ||\n\t PyTypeNum_ISEXTENDED(outcode->type_num)) {\n\t\tPyArrayObject *ain, *aout;\n\n\t\tain = (PyArrayObject *)PyArray_FromScalar(scalar, NULL);\n\t\tif (ain == NULL) {Py_DECREF(descr); return -1;}\n\t\taout = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t outcode,\n\t\t\t\t\t 0, NULL, \n\t\t\t\t\t NULL, ctypeptr, \n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\t\tif (aout == NULL) {Py_DECREF(ain); return -1;}\n\t\tdescr->f->cast[outcode->type_num](ain->data, \n\t\t\t\t\t aout->data, 1, ain, aout);\n\t\tPy_DECREF(ain);\n\t\tPy_DECREF(aout);\n\t}\n\telse {\n\t\tdescr->f->cast[outcode->type_num](_SOFFSET_(scalar, \n\t\t\t\t\t\t\t descr->type_num), \n\t\t\t\t\t ctypeptr, 1, NULL, NULL);\n\t}\n\tPy_DECREF(descr);\n\treturn 0;\n}\n\n/* 0-dim array from array-scalar object */\n/* always contains a copy of the data \n unless outcode is NULL, it is of void type and the referrer does\n not own it either.\n*/\n\n/* steals reference to outcode */\n/*OBJECT_API\n Get 0-dim array from scalar\n*/\nstatic PyObject *\nPyArray_FromScalar(PyObject *scalar, PyArray_Descr *outcode)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *r;\n\tchar *memptr;\n\tPyObject *ret;\n\n\t/* convert to 0-dim array of scalar typecode */\n\ttypecode = PyArray_DescrFromScalar(scalar);\n\tif ((typecode->type_num == PyArray_VOID) &&\t\t\t\\\n\t !(((PyVoidScalarObject *)scalar)->flags & OWNDATA) &&\t\\\n\t outcode == NULL) {\n\t\tr = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t typecode,\n\t\t\t\t\t 0, NULL, NULL,\n\t\t\t\t\t ((PyVoidScalarObject *)scalar)->obval,\n\t\t\t\t\t ((PyVoidScalarObject *)scalar)->flags,\n\t\t\t\t\t NULL);\n\t\tPyArray_BASE(r) = (PyObject *)scalar;\n\t\tPy_INCREF(scalar);\n\t\treturn r;\n\t}\n\tr = PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t typecode,\n\t\t\t\t 0, NULL, \n\t\t\t\t NULL, NULL, 0, NULL);\n\tif (r==NULL) {Py_XDECREF(outcode); return NULL;}\n\n\tswitch(typecode->type_num) {\n\tcase PyArray_STRING:\n\t\tmemptr = PyString_AS_STRING(scalar);\n\t\tbreak;\n\tcase PyArray_UNICODE:\n\t\tmemptr = (char *)PyUnicode_AS_DATA(scalar);\n#ifdef Py_UNICODE_WIDE\n\t\tbreak;\n#else\n\t\tPyUCS2Buffer_AsUCS4((Py_UNICODE *)memptr, \n\t\t\t\t (PyArray_UCS4 *)PyArray_DATA(r),\n\t\t\t\t PyUnicode_GET_SIZE(scalar),\n\t\t\t\t PyArray_ITEMSIZE(r) >> 2);\n goto finish;\n#endif\n\tdefault:\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tmemptr = (((PyVoidScalarObject *)scalar)->obval);\n\t\t}\n\t\telse {\n\t\t\tmemptr = _SOFFSET_(scalar, typecode->type_num);\n\t\t}\n\t\tbreak;\n\t}\n\n\tmemcpy(PyArray_DATA(r), memptr, PyArray_ITEMSIZE(r));\n\tif (PyArray_ISOBJECT(r)) {\n\t\tPy_INCREF(*((PyObject **)memptr));\n\t}\n#ifndef Py_UNICODE_WIDE\n finish:\t\n#endif\n\tif (outcode == NULL) return r;\n\t\n\tif (outcode->type_num == typecode->type_num) {\n\t\tif (!PyTypeNum_ISEXTENDED(typecode->type_num))\n\t\t\treturn r;\n\t\tif (outcode->elsize == typecode->elsize);\n\t\treturn r;\t\t\t\n\t}\n\t\n\t/* cast if necessary to desired output typecode */\n\tret = PyArray_CastToType((PyArrayObject *)r, outcode, 0);\n\tPy_DECREF(r);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n const size_t size = _PyObject_VAR_SIZE(type, nitems+1);\n\n obj = (PyObject *)_pya_malloc(size);\n\tmemset(obj, 0, size);\n\tif (type->tp_itemsize == 0)\n PyObject_INIT(obj, type);\n else\n (void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems);\n return obj;\n}\n\nstatic void\ngentype_dealloc(PyObject *v) \n{\n\tv->ob_type->tp_free(v);\n}\n\n\nstatic PyObject *\ngentype_power(PyObject *m1, PyObject *m2, PyObject *m3)\n{\n\tPyObject *arr, *ret, *arg2;\n\tchar *msg=\"unsupported operand type(s) for ** or pow()\";\n\t\n\tif (!PyArray_IsScalar(m1,Generic)) {\n\t\tif (PyArray_Check(m1)) {\n\t\t\tret = m1->ob_type->tp_as_number->nb_power(m1,m2, \n\t\t\t\t\t\t\t\t Py_None);\n\t\t}\n\t\telse {\n\t\t\tif (!PyArray_IsScalar(m2,Generic)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tarr = PyArray_FromScalar(m2, NULL);\n\t\t\tif (arr == NULL) return NULL;\n\t\t\tret = arr->ob_type->tp_as_number->nb_power(m1, arr,\n\t\t\t\t\t\t\t\t Py_None);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t\treturn ret;\n\t}\n\tif (!PyArray_IsScalar(m2, Generic)) {\n\t\tif (PyArray_Check(m2)) {\n\t\t\tret = m2->ob_type->tp_as_number->nb_power(m1,m2, \n\t\t\t\t\t\t\t\t Py_None);\n\t\t}\n\t\telse {\n\t\t\tif (!PyArray_IsScalar(m1, Generic)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tarr = PyArray_FromScalar(m1, NULL);\n\t\t\tif (arr == NULL) return NULL;\n\t\t\tret = arr->ob_type->tp_as_number->nb_power(arr, m2,\n\t\t\t\t\t\t\t\t Py_None);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t\treturn ret;\n\t}\n\tarr=arg2=NULL;\n\tarr = PyArray_FromScalar(m1, NULL);\n\targ2 = PyArray_FromScalar(m2, NULL);\t\n\tif (arr == NULL || arg2 == NULL) {\n\t\tPy_XDECREF(arr); Py_XDECREF(arg2); return NULL;\n\t}\n\tret = arr->ob_type->tp_as_number->nb_power(arr, arg2, Py_None);\n\tPy_DECREF(arr);\n\tPy_DECREF(arg2);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_generic_method(PyObject *self, PyObject *args, PyObject *kwds, \n\t\t char *str)\n{\n\tPyObject *arr, *meth, *ret;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tmeth = PyObject_GetAttrString(arr, str);\n\tif (meth == NULL) {Py_DECREF(arr); return NULL;}\n\tif (kwds == NULL) \n\t\tret = PyObject_CallObject(meth, args);\n\telse\n\t\tret = PyObject_Call(meth, args, kwds);\n\tPy_DECREF(meth);\n\tPy_DECREF(arr);\n if (ret && PyArray_Check(ret))\n return PyArray_Return((PyArrayObject *)ret);\n else\n return ret;\n}\n\n/**begin repeat\n\n#name=add, subtract, divide, remainder, divmod, lshift, rshift, and, xor, or, floor_divide, true_divide#\n#PYNAME=Add, Subtract, Divide, Remainder, Divmod, Lshift, Rshift, And, Xor, Or, FloorDivide, TrueDivide#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *m1, PyObject *m2)\n{\n\treturn PyArray_Type.tp_as_number->nb_@name@(m1, m2);\n}\n/**end repeat**/\n\n\nstatic PyObject *\ngentype_multiply(PyObject *m1, PyObject *m2)\n{\n\tPyObject *ret=NULL;\n\tlong repeat;\n\n\tif (!PyArray_IsScalar(m1, Generic) && \n\t ((m1->ob_type->tp_as_number == NULL) ||\n\t (m1->ob_type->tp_as_number->nb_multiply == NULL))) {\n\t\t/* Try to convert m2 to an int and try sequence\n\t\t repeat */\n\t\trepeat = PyInt_AsLong(m2);\n\t\tif (repeat == -1 && PyErr_Occurred()) return NULL;\n\t\tret = PySequence_Repeat(m1, (int) repeat);\n\t}\n\telse if (!PyArray_IsScalar(m2, Generic) && \n\t\t ((m2->ob_type->tp_as_number == NULL) ||\n\t\t (m2->ob_type->tp_as_number->nb_multiply == NULL))) {\n\t\t/* Try to convert m1 to an int and try sequence\n\t\t repeat */\n\t\trepeat = PyInt_AsLong(m1);\n\t\tif (repeat == -1 && PyErr_Occurred()) return NULL;\n\t\tret = PySequence_Repeat(m2, (int) repeat);\n\t}\n\tif (ret==NULL) {\n\t\tPyErr_Clear(); /* no effect if not set */\n\t\tret = PyArray_Type.tp_as_number->nb_multiply(m1, m2);\n\t}\n\treturn ret;\n}\n\n/**begin repeat\n\n#name=positive, negative, absolute, invert, int, long, float, oct, hex#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *m1)\n{\n\tPyObject *arr, *ret;\n\n\tarr = PyArray_FromScalar(m1, NULL);\n\tif (arr == NULL) return NULL;\n\tret = arr->ob_type->tp_as_number->nb_@name@(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n/**end repeat**/\n\nstatic int\ngentype_nonzero_number(PyObject *m1)\n{\n\tPyObject *arr;\n\tint ret;\n\n\tarr = PyArray_FromScalar(m1, NULL);\n\tif (arr == NULL) return -1;\n\tret = arr->ob_type->tp_as_number->nb_nonzero(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_str(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret, *tmp;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tif (arr==NULL) return NULL;\n\tret = PyObject_Str((tmp=arr->descr->f->getitem(arr->data, arr)));\n\tPy_DECREF(arr);\n\tPy_XDECREF(tmp);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_repr(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret, *tmp ;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tif (arr==NULL) return NULL;\n\tret = PyObject_Repr((tmp=arr->descr->f->getitem(arr->data, arr)));\n\tPy_DECREF(arr);\n\tPy_XDECREF(tmp);\n\treturn ret;\n}\n\nstatic void\nformat_longdouble(char *buf, size_t buflen, longdouble val, int precision)\n{\n register char *cp;\n\n PyOS_snprintf(buf, buflen, \"%.*\" LONGDOUBLE_FMT, precision, val);\n cp = buf;\n if (*cp == '-')\n cp++;\n for (; *cp != '\\0'; cp++) {\n if (!isdigit(Py_CHARMASK(*cp)))\n break;\n }\n if (*cp == '\\0') {\n *cp++ = '.';\n *cp++ = '0';\n *cp++ = '\\0';\n }\n}\n\n/* over-ride repr and str of array-scalar strings and unicode to \n remove NULL bytes and then call the corresponding functions \n of string and unicode. \n */\n\n/**begin repeat\n#name=string*2,unicode*2#\n#form=(repr,str)*2#\n#Name=String*2,Unicode*2#\n#NAME=STRING*2,UNICODE*2#\n#extra=AndSize*2,,#\n#type=char*2, Py_UNICODE*2#\n*/\nstatic PyObject *\n@name@type_@form@(PyObject *self)\n{\n\tconst @type@ *dptr, *ip;\n\tint len;\n\tPyObject *new;\n\tPyObject *ret;\n\n\tip = dptr = Py@Name@_AS_@NAME@(self);\n\tlen = Py@Name@_GET_SIZE(self);\n\tdptr += len-1;\n\twhile(len > 0 && *dptr-- == 0) len--;\n\tnew = Py@Name@_From@Name@@extra@(ip, len);\n\tif (new == NULL) return PyString_FromString(\"\");\n\tret = Py@Name@_Type.tp_@form@(new);\n\tPy_DECREF(new);\n\treturn ret;\n}\n/**end repeat**/\n\n\n\n#if SIZEOF_LONGDOUBLE == SIZEOF_DOUBLE\n#define PREC_REPR 17\n#define PREC_STR 17\n#else\n#define PREC_REPR 21\n#define PREC_STR 21\n#endif\n\nstatic PyObject *\nlongdoubletype_repr(PyObject *self)\n{\n static char buf[100];\n format_longdouble(buf, sizeof(buf), ((PyLongDoubleScalarObject *)self)->obval, PREC_REPR);\n return PyString_FromString(buf);\n}\n\nstatic PyObject *\nclongdoubletype_repr(PyObject *self)\n{\n static char buf1[100];\n static char buf2[100];\n\tstatic char buf3[202];\n clongdouble x;\n x = ((PyCLongDoubleScalarObject *)self)->obval;\n format_longdouble(buf1, sizeof(buf1), x.real, PREC_REPR);\n format_longdouble(buf2, sizeof(buf2), x.imag, PREC_REPR);\n\n\tsnprintf(buf3, sizeof(buf3), \"(%s+%sj)\", buf1, buf2);\n\treturn PyString_FromString(buf3);\n}\n\n#define longdoubletype_str longdoubletype_repr\n#define clongdoubletype_str clongdoubletype_repr\n\n/** Could improve this with a PyLong_FromLongDouble(longdouble ldval)\n but this would need some more work...\n**/\n\n/**begin repeat\n\n#name=(int, long, hex, oct, float)*2#\n#KIND=(Long*4, Float)*2#\n#char=,,,,,c*5#\n#CHAR=,,,,,C*5#\n#POST=,,,,,.real*5#\n*/\nstatic PyObject *\n@char@longdoubletype_@name@(PyObject *self)\n{\n\tdouble dval;\n\tPyObject *obj, *ret;\n\t\n\tdval = (double)(((Py@CHAR@LongDoubleScalarObject *)self)->obval)@POST@;\n\tobj = Py@KIND@_FromDouble(dval);\n\tret = obj->ob_type->tp_as_number->nb_@name@(obj);\n\tPy_DECREF(obj);\n\treturn ret;\n}\n/**end repeat**/\n\n#if PY_VERSION_HEX >= 0x02050000\n/* This needs a better implementation */\nstatic Py_ssize_t\ngentype_index(PyObject *self)\n{\n\tPyObject *obj;\n\tif (!(PyArray_IsScalar(self, Integer))) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"not an integer type.\");\n\t\treturn -1;\n\t}\n\tobj = gentype_int(self);\n\tif (obj == NULL) return -1;\n\treturn PyInt_AsSsize_t(obj);\t\n}\n#endif\n\n\nstatic PyNumberMethods gentype_as_number = {\n (binaryfunc)gentype_add,\t\t /*nb_add*/\n (binaryfunc)gentype_subtract,\t\t /*nb_subtract*/\n (binaryfunc)gentype_multiply,\t\t /*nb_multiply*/\n (binaryfunc)gentype_divide,\t\t /*nb_divide*/\n (binaryfunc)gentype_remainder,\t /*nb_remainder*/\n (binaryfunc)gentype_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)gentype_power,\t\t /*nb_power*/\n (unaryfunc)gentype_negative,\t \n (unaryfunc)gentype_positive, \t /*nb_pos*/ \n (unaryfunc)gentype_absolute,\t\t /*(unaryfunc)gentype_abs,*/\n (inquiry)gentype_nonzero_number,\t\t /*nb_nonzero*/\n (unaryfunc)gentype_invert,\t\t /*nb_invert*/\n (binaryfunc)gentype_lshift,\t /*nb_lshift*/\n (binaryfunc)gentype_rshift,\t /*nb_rshift*/\n (binaryfunc)gentype_and,\t /*nb_and*/\n (binaryfunc)gentype_xor,\t /*nb_xor*/\n (binaryfunc)gentype_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)gentype_int,\t\t /*nb_int*/\n (unaryfunc)gentype_long,\t\t /*nb_long*/\n (unaryfunc)gentype_float,\t\t /*nb_float*/\n (unaryfunc)gentype_oct,\t\t /*nb_oct*/\n (unaryfunc)gentype_hex,\t\t /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)gentype_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)gentype_true_divide,\t /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n\t(lenfunc)gentype_index, /* nb_index */\n#endif\n};\n\n\nstatic PyObject *\ngentype_richcompare(PyObject *self, PyObject *other, int cmp_op) \n{\n\n\tPyObject *arr, *ret;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tret = arr->ob_type->tp_richcompare(arr, other, cmp_op);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_ndim_get(PyObject *self)\n{\n\treturn PyInt_FromLong(0);\n}\n\nstatic PyObject *\ngentype_flags_get(PyObject *self)\n{\n\tstatic int flags=CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n\n return PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, flags, 1);\n}\n\nstatic PyObject *\nvoidtype_flags_get(PyVoidScalarObject *self)\n{\n\treturn PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 1);\n}\n\nstatic PyObject *\nvoidtype_dtypedescr_get(PyVoidScalarObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n\nstatic PyObject *\ngentype_shape_get(PyObject *self)\n{\n\treturn PyTuple_New(0);\n}\n\n/*\nstatic int\ngentype_shape_set(PyObject *self, PyObject *val)\n{\n\tif (!PyTuple_Check(val) || PyTuple_GET_SIZE(val) > 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \\\n\t\t\t\t\"invalid shape for scalar\");\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n*/\n\nstatic PyObject *\ngentype_dataptr_get(PyObject *self)\n{\n\treturn Py_BuildValue(\"NO\",PyString_FromString(\"\"),Py_True);\n}\n\n\nstatic PyObject *\ngentype_data_get(PyObject *self)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\n\ttypecode = PyArray_DescrFromScalar(self);\n\tret = PyBuffer_FromObject(self, 0, typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\n\nstatic PyObject *\ngentype_itemsize_get(PyObject *self)\n{\t\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\n\ttypecode = PyArray_DescrFromScalar(self);\n\tret = PyInt_FromLong((long) typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_size_get(PyObject *self)\n{\n\treturn PyInt_FromLong(1);\n}\n\nstatic void\ngentype_struct_free(void *ptr, void *arr)\n{\n Py_DECREF((PyObject *)arr);\n _pya_free(ptr);\n}\n\nstatic PyObject *\ngentype_struct_get(PyObject *self)\n{\n PyArrayObject *arr;\n PyArrayInterface *inter;\n \n arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = 0;\n inter->flags = arr->flags;\n inter->typekind = arr->descr->kind;\n inter->itemsize = arr->descr->elsize;\n inter->strides = NULL;\n inter->shape = NULL;\n inter->data = arr->data;\n return PyCObject_FromVoidPtrAndDesc(inter, arr, gentype_struct_free);\n}\n\nstatic PyObject *\ngentype_typestr_get(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tret = PyObject_GetAttrString((PyObject *)arr->descr, \"str\");\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_descr_get(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tret = PyObject_GetAttrString((PyObject *)arr, \"__array_descr__\");\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\n\nstatic PyObject *\ngentype_typedescr_get(PyObject *self)\n{\n\treturn (PyObject *)PyArray_DescrFromScalar(self);\n}\n\n\nstatic PyObject *\ngentype_base_get(PyObject *self)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic PyArray_Descr *\n_realdescr_fromcomplexscalar(PyObject *self, int *typenum)\n{\n\tif PyArray_IsScalar(self, CDouble) {\n\t\t*typenum = PyArray_CDOUBLE;\n\t\treturn PyArray_DescrFromType(PyArray_DOUBLE);\n\t}\n\tif PyArray_IsScalar(self, CFloat) {\n\t\t*typenum = PyArray_CFLOAT;\n\t\treturn PyArray_DescrFromType(PyArray_FLOAT);\n\t}\n\tif PyArray_IsScalar(self, CLongDouble) {\n\t\t*typenum = PyArray_CLONGDOUBLE;\n\t\treturn PyArray_DescrFromType(PyArray_LONGDOUBLE);\n\t}\n\treturn NULL;\n}\n\nstatic PyObject *\ngentype_real_get(PyObject *self)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\tint typenum;\n\n\tif (PyArray_IsScalar(self, ComplexFloating)) {\n\t\ttypecode = _realdescr_fromcomplexscalar(self, &typenum);\n\t\tret = PyArray_Scalar(_SOFFSET_(self, typenum), typecode,\n\t\t\t\t NULL);\n\t\tPy_DECREF(typecode);\n\t\treturn ret;\n\t}\n\telse if PyArray_IsScalar(self, Object) {\n\t\tPyObject *obj = ((PyObjectScalarObject *)self)->obval;\n\t\tret = PyObject_GetAttrString(obj, \"real\");\n\t\tif (ret != NULL) return ret;\n\t\tPyErr_Clear();\n\t}\n\tPy_INCREF(self);\n\treturn (PyObject *)self;\n}\n\nstatic PyObject *\ngentype_imag_get(PyObject *self)\n{\t\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\t\n\tint typenum;\n\t\n\ttypecode = _realdescr_fromcomplexscalar(self, &typenum);\n\tif (PyArray_IsScalar(self, ComplexFloating)) {\n\t\tret = PyArray_Scalar(_SOFFSET_(self, typenum)\t\t\\\n\t\t\t\t + typecode->elsize, typecode, NULL);\n\t}\n\telse if PyArray_IsScalar(self, Object) {\n\t\tPyObject *obj = ((PyObjectScalarObject *)self)->obval;\n\t\tPyArray_Descr *newtype;\n\t\tret = PyObject_GetAttrString(obj, \"imag\");\n\t\tif (ret == NULL) {\n\t\t\tPyErr_Clear();\n\t\t\tobj = PyInt_FromLong(0);\n\t\t\tnewtype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\t\tret = PyArray_Scalar((char *)&obj, newtype, NULL);\n\t\t\tPy_DECREF(newtype);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tchar *temp;\n\t\ttemp = PyDataMem_NEW(typecode->elsize);\n\t\tmemset(temp, '\\0', typecode->elsize);\n\t\tret = PyArray_Scalar(temp, typecode, NULL);\n\t\tPyDataMem_FREE(temp);\n\t}\n\t\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_flat_get(PyObject *self)\n{\n\tPyObject *ret, *arr;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tret = PyArray_IterNew(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyGetSetDef gentype_getsets[] = {\n {\"ndim\", \n\t (getter)gentype_ndim_get, \n\t (setter) 0, \n\t \"number of array dimensions\"},\n {\"flags\", \n\t (getter)gentype_flags_get, \n\t (setter)0, \n\t \"integer value of flags\"},\n {\"shape\", \n\t (getter)gentype_shape_get, \n\t (setter)0, \n\t \"tuple of array dimensions\"},\n {\"strides\", \n\t (getter)gentype_shape_get, \n\t (setter) 0, \n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)gentype_data_get, \n\t (setter) 0, \n\t \"pointer to start of data\"},\n {\"itemsize\", \n\t (getter)gentype_itemsize_get, \n\t (setter)0, \n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)gentype_size_get,\n (setter)0,\n \"number of elements in the gentype\"},\n {\"nbytes\",\n (getter)gentype_itemsize_get,\n (setter)0,\n \"length of item in bytes\"},\n\t{\"base\",\n\t (getter)gentype_base_get,\n\t (setter)0,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)gentype_typedescr_get,\n\t NULL,\n\t \"get array data-descriptor\"},\n {\"real\", \n\t (getter)gentype_real_get, \n\t (setter)0,\n\t \"real part of scalar\"},\n {\"imag\", \n\t (getter)gentype_imag_get, \n\t (setter)0, \n\t \"imaginary part of scalar\"},\n\t{\"flat\", \n\t (getter)gentype_flat_get, \n\t (setter)0, \n\t \"a 1-d view of scalar\"}, \n\t{\"__array_data__\", \n\t (getter)gentype_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)gentype_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)gentype_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)gentype_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)gentype_shape_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)gentype_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t/* Does not have __array_priority__ because it is not a subtype.\n\t */\n \t{NULL, NULL, NULL, NULL} /* Sentinel */\n};\n\n\n/* 0-dim array from scalar object */\n\nstatic char doc_getarray[] = \"sc.__array__(|type) return 0-dim array\";\n\nstatic PyObject *\ngentype_getarray(PyObject *scalar, PyObject *args) \n{\n\tPyArray_Descr *outcode=NULL;\n\tPyObject *ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", &PyArray_DescrConverter,\n\t\t\t &outcode)) return NULL;\n\tret = PyArray_FromScalar(scalar, outcode);\n\treturn ret;\n}\n\nstatic char doc_sc_wraparray[] = \"sc.__array_wrap__(obj) return scalar from array\";\n\nstatic PyObject *\ngentype_wraparray(PyObject *scalar, PyObject *args)\n{\n\tPyObject *arr;\n\n\tif (PyTuple_Size(args) < 1) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"only accepts 1 argument.\");\n\t\treturn NULL;\n\t}\n\tarr = PyTuple_GET_ITEM(args, 0);\n\tif (!PyArray_Check(arr)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"can only be called with ndarray object\");\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_Scalar(PyArray_DATA(arr), PyArray_DESCR(arr), arr);\n}\n\n\n/**begin repeat\n\n#name=tolist, item, tostring, astype, copy, __deepcopy__, choose, searchsorted, reshape, view, swapaxes, conj, conjugate, nonzero, flatten, ravel, fill, transpose, newbyteorder#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *self, PyObject *args)\n{\n\treturn gentype_generic_method(self, args, NULL, \"@name@\");\n}\n/**end repeat**/\n\nstatic PyObject *\ngentype_squeeze(PyObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\tPy_INCREF(self);\n\treturn self;\n}\n\nstatic int\ngentype_getreadbuf(PyObject *, int, void **);\n\nstatic PyObject *\ngentype_byteswap(PyObject *self, PyObject *args)\n{\n\tBool inplace=FALSE;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter, &inplace))\n\t\treturn NULL;\n\t\n\tif (inplace) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot byteswap a scalar in-place\");\n\t\treturn NULL;\n\t}\n\telse {\n\t\t/* get the data, copyswap it and pass it to a new Array scalar\n\t\t */\n\t\tchar *data;\n\t\tint numbytes;\n\t\tPyArray_Descr *descr;\n\t\tPyObject *new;\n\t\tchar *newmem;\n\n\t\tnumbytes = gentype_getreadbuf(self, 0, (void **)&data);\n\t\tdescr = PyArray_DescrFromScalar(self);\n\t\tnewmem = _pya_malloc(descr->elsize);\n\t\tif (newmem == NULL) {Py_DECREF(descr); return PyErr_NoMemory();}\n\t\telse memcpy(newmem, data, descr->elsize);\n\t\tdescr->f->copyswap(newmem, NULL, 1, descr->elsize);\n\t\tnew = PyArray_Scalar(newmem, descr, NULL);\n\t\t_pya_free(newmem);\n\t\tPy_DECREF(descr);\n\t\treturn new;\n\t}\n}\n\n\n/**begin repeat\n\n#name=take, getfield, put, putmask, repeat, tofile, mean, trace, diagonal, clip, std, var, sum, cumsum, prod, cumprod, compress, sort, argsort, round, argmax, argmin, max, min, ptp, any, all, resize#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\treturn gentype_generic_method(self, args, kwds, \"@name@\");\n}\n/**end repeat**/\n\nstatic PyObject *\nvoidtype_getfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyObject *ret;\n\n\tret = gentype_generic_method((PyObject *)self, args, kwds, \"getfield\");\n\tif (!ret) return ret;\n\tif (PyArray_IsScalar(ret, Generic) &&\t\\\n\t (!PyArray_IsScalar(ret, Void))) {\n\t\tPyArray_Descr *new;\n\t\tif (!PyArray_ISNBO(self->descr->byteorder)) {\n\t\t\tnew = PyArray_DescrFromScalar(ret);\n\t\t\tnew->f->copyswap(_SOFFSET_(ret, \n\t\t\t\t\t\t new->type_num),\n\t\t\t\t\t NULL, 1, new->elsize);\n\t\t\tPy_DECREF(new);\n\t\t}\n\t}\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_setfield(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\t\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"Can't set fields in a non-void array scalar.\");\n\treturn NULL;\n}\t\n\nstatic PyObject *\nvoidtype_setfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *typecode;\n\tint offset = 0;\n\tPyObject *value, *src;\n\tint mysize;\n\tchar *dptr;\n\tstatic char *kwlist[] = {\"value\", \"dtype\", \"offset\", 0};/* XXX ? */\n\t\n\tif ((self->flags & WRITEABLE) != WRITEABLE) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"Can't write to memory\");\n\t\treturn NULL;\n\t}\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO&|i\", kwlist,\n\t\t\t\t\t &value,\n\t\t\t\t\t PyArray_DescrConverter, \n\t\t\t\t\t &typecode, &offset)) return NULL;\n\n\tmysize = self->ob_size;\n\t\n\tif (offset < 0 || (offset + typecode->elsize) > mysize) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need 0 <= offset <= %d for requested type \" \\\n\t\t\t \"but received offset = %d\",\n\t\t\t mysize-typecode->elsize, offset);\n\t\tPy_DECREF(typecode);\n\t\treturn NULL;\n\t}\t\n\n\tdptr = self->obval + offset;\n\n\t/* Copy data from value to correct place in dptr */\n src = PyArray_FromAny(value, typecode, 0, 0, CARRAY_FLAGS, NULL);\n if (src == NULL) return NULL;\n\ttypecode->f->copyswap(dptr, PyArray_DATA(src), \n\t\t\t !PyArray_ISNBO(self->descr->byteorder),\n\t\t\t PyArray_ITEMSIZE(src));\n\tPy_DECREF(src);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic PyObject *\ngentype_reduce(PyObject *self, PyObject *args)\n{\n\tPyObject *ret=NULL, *obj=NULL, *mod=NULL;\n\tconst char *buffer; \n\tint buflen;\n\n\t/* Return a tuple of (callable object, arguments) */\n\n\tret = PyTuple_New(2);\n\tif (ret == NULL) return NULL;\t\n\tif (PyObject_AsReadBuffer(self, (const void **)&buffer, &buflen)<0) {\n\t\tPy_DECREF(ret); return NULL;\n\t}\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) return NULL;\n\tobj = PyObject_GetAttrString(mod, \"scalar\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) return NULL;\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tobj = PyObject_GetAttrString((PyObject *)self, \"dtype\");\n\tif PyArray_IsScalar(self, Object) {\n\t\tmod = ((PyObjectScalarObject *)self)->obval;\n\t\tPyTuple_SET_ITEM(ret, 1,\n\t\t\t\t Py_BuildValue(\"NO\", obj, mod));\n\t}\n\telse {\n\t\tmod = PyString_FromStringAndSize(buffer, buflen);\n\t\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t\t Py_BuildValue(\"NN\", obj, mod));\n\t}\n\treturn ret;\n}\n\n/* ignores everything */\nstatic PyObject *\ngentype_setstate(PyObject *self, PyObject *args)\n{\n\tPy_INCREF(Py_None);\n\treturn (Py_None);\n}\n\nstatic PyObject *\ngentype_dump(PyObject *self, PyObject *args)\n{\n\tPyObject *file=NULL;\n\tint ret;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &file))\n\t\treturn NULL;\n\tret = PyArray_Dump(self, file, 2);\n\tif (ret < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyObject *\ngentype_dumps(PyObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\"))\n\t\treturn NULL;\n\treturn PyArray_Dumps(self, 2);\n}\n\n\n/* setting flags cannot be done for scalars */\nstatic PyObject *\ngentype_setflags(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* need to fill in doc-strings for these methods on import -- copy from \n array docstrings \n*/\nstatic PyMethodDef gentype_methods[] = {\n {\"tolist\",\t (PyCFunction)gentype_tolist,\t1, NULL},\n {\"item\", (PyCFunction)gentype_item, METH_VARARGS, NULL},\n\t{\"tofile\", (PyCFunction)gentype_tofile, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"tostring\", (PyCFunction)gentype_tostring, METH_VARARGS, NULL},\n {\"byteswap\", (PyCFunction)gentype_byteswap,1, NULL},\n {\"astype\", (PyCFunction)gentype_astype, 1, NULL},\n\t{\"getfield\", (PyCFunction)gentype_getfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{\"setfield\", (PyCFunction)gentype_setfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n {\"copy\", (PyCFunction)gentype_copy, 1, NULL}, \n {\"resize\", (PyCFunction)gentype_resize, 1, NULL}, \n\n\t{\"__array__\", (PyCFunction)gentype_getarray, 1, doc_getarray},\n\t{\"__array_wrap__\", (PyCFunction)gentype_wraparray, 1, doc_sc_wraparray},\n\n /* for the copy module */\n {\"__copy__\", (PyCFunction)gentype_copy, 1, NULL},\n {\"__deepcopy__\", (PyCFunction)gentype___deepcopy__, 1, NULL},\n\n\n {\"__reduce__\", (PyCFunction) gentype_reduce, 1, NULL},\t\n\t/* For consistency does nothing */\n\t{\"__setstate__\", (PyCFunction) gentype_setstate, 1, NULL},\n\n\t{\"dumps\", (PyCFunction) gentype_dumps, 1, NULL},\n\t{\"dump\", (PyCFunction) gentype_dump, 1, NULL},\n\n\t/* Methods for array */\n\t{\"fill\", (PyCFunction)gentype_fill,\n\t METH_VARARGS, NULL},\n\t{\"transpose\",\t(PyCFunction)gentype_transpose, \n\t METH_VARARGS, NULL},\n\t{\"take\",\t(PyCFunction)gentype_take, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"put\",\t(PyCFunction)gentype_put, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"putmask\",\t(PyCFunction)gentype_putmask, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"repeat\",\t(PyCFunction)gentype_repeat, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"choose\",\t(PyCFunction)gentype_choose, \n\t METH_VARARGS, NULL},\t\n\t{\"sort\",\t(PyCFunction)gentype_sort, \n\t METH_VARARGS, NULL},\n\t{\"argsort\",\t(PyCFunction)gentype_argsort, \n\t METH_VARARGS, NULL},\n\t{\"searchsorted\", (PyCFunction)gentype_searchsorted, \n\t METH_VARARGS, NULL},\t\n\t{\"argmax\",\t(PyCFunction)gentype_argmax, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"argmin\", (PyCFunction)gentype_argmin,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"reshape\",\t(PyCFunction)gentype_reshape, \n\t METH_VARARGS, NULL},\n\t{\"squeeze\",\t(PyCFunction)gentype_squeeze, \n\t METH_VARARGS, NULL},\n\t{\"view\", (PyCFunction)gentype_view, \n\t METH_VARARGS, NULL},\n\t{\"swapaxes\", (PyCFunction)gentype_swapaxes,\n\t METH_VARARGS, NULL},\n\t{\"max\", (PyCFunction)gentype_max,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"min\", (PyCFunction)gentype_min,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"ptp\", (PyCFunction)gentype_ptp,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"mean\", (PyCFunction)gentype_mean,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"trace\", (PyCFunction)gentype_trace,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"diagonal\", (PyCFunction)gentype_diagonal,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"clip\", (PyCFunction)gentype_clip,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"conj\", (PyCFunction)gentype_conj,\n\t METH_VARARGS, NULL},\n\t{\"conjugate\", (PyCFunction)gentype_conjugate,\n\t METH_VARARGS, NULL},\n\t{\"nonzero\", (PyCFunction)gentype_nonzero,\n\t METH_VARARGS, NULL},\n\t{\"std\", (PyCFunction)gentype_std,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"var\", (PyCFunction)gentype_var,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"sum\", (PyCFunction)gentype_sum,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"cumsum\", (PyCFunction)gentype_cumsum,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"prod\", (PyCFunction)gentype_prod,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"cumprod\", (PyCFunction)gentype_cumprod,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"all\", (PyCFunction)gentype_all,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"any\", (PyCFunction)gentype_any,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"compress\", (PyCFunction)gentype_compress,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"flatten\", (PyCFunction)gentype_flatten,\n\t METH_VARARGS, NULL},\n\t{\"ravel\", (PyCFunction)gentype_ravel,\n\t METH_VARARGS, NULL},\n\t{\"round\", (PyCFunction)gentype_round,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"setflags\", (PyCFunction)gentype_setflags,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"newbyteorder\", (PyCFunction)gentype_newbyteorder,\n\t METH_VARARGS, NULL},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\nstatic PyGetSetDef voidtype_getsets[] = {\n {\"flags\", \n\t (getter)voidtype_flags_get, \n\t (setter)0, \n\t \"integer value of flags\"},\n\t{\"dtype\",\n\t (getter)voidtype_dtypedescr_get,\n\t (setter)0,\n\t \"dtype object\"},\n\t{NULL, NULL}\n};\n\nstatic PyMethodDef voidtype_methods[] = {\n\t{\"getfield\", (PyCFunction)voidtype_getfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{\"setfield\", (PyCFunction)voidtype_setfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{NULL, NULL}\n};\n\n/************* As_mapping functions for void array scalar ************/\n\nstatic int\nvoidtype_length(PyVoidScalarObject *self) \n{\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\treturn 0;\n\t}\n\telse { /* return the number of fields */\n\t\tPyObject *key;\n\t\tPyObject *flist;\n\t\tkey = PyInt_FromLong(-1);\n\t\tflist = PyDict_GetItem(self->descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!flist) return 0;\n\t\treturn PyTuple_GET_SIZE(flist);\n\t}\n}\n\n/* get field by name or number */\nstatic PyObject *\nvoidtype_subscript(PyVoidScalarObject *self, PyObject *ind)\n{\n\tint n, m;\n\tchar *msg = \"invalid index\";\n\tPyObject *flist=NULL, *key, *fieldinfo;\n\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"can't index void scalar without fields\");\n\t\treturn NULL;\n\t}\n\n\tif (PyString_Check(ind) || PyUnicode_Check(ind)) {\n\t\t/* look up in fields */\n\t\tfieldinfo = PyDict_GetItem(self->descr->fields, ind);\n\t\tif (!fieldinfo) {\n\t\t\tPyErr_SetString(PyExc_IndexError, msg);\n\t\t\treturn NULL;\n\t\t}\n\t\treturn voidtype_getfield(self, fieldinfo, NULL);\n\t}\n\t\n\t/* try to convert it to a number */\n\tn = PyArray_PyIntAsIntp(ind);\n\tif (error_converting(n)) {\n\t\tPyErr_Clear();\n\t\tgoto fail;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tflist = PyDict_GetItem(self->descr->fields, key);\n\tPy_DECREF(key);\n\tif (!flist) m = 0; \n\tm = PyTuple_GET_SIZE(flist);\n\tif (n < 0) n += m;\n\tif (n < 0 || n >= m) goto fail;\n\tfieldinfo = PyDict_GetItem(self->descr->fields, \n\t\t\t\t PyTuple_GET_ITEM(flist, n));\n\treturn voidtype_getfield(self, fieldinfo, NULL);\n\n fail:\n\tPyErr_SetString(PyExc_IndexError, msg);\n\treturn NULL;\n}\n\nstatic int\nvoidtype_ass_subscript(PyVoidScalarObject *self, PyObject *ind, PyObject *val) \n{\n\tint n, m;\n\tchar *msg = \"invalid index\";\n\tPyObject *flist=NULL, *key, *fieldinfo, *newtup;\n\tPyObject *res;\n\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"can't index void scalar without fields\");\n\t\treturn -1;\n\t}\n\n\tif (PyString_Check(ind) || PyUnicode_Check(ind)) {\n\t\t/* look up in fields */\n\t\tfieldinfo = PyDict_GetItem(self->descr->fields, ind);\n\t\tif (!fieldinfo) {\n\t\t\tPyErr_SetString(PyExc_IndexError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tnewtup = Py_BuildValue(\"(OOO)\", val, \n\t\t\t\t PyTuple_GET_ITEM(fieldinfo, 0),\n\t\t\t\t PyTuple_GET_ITEM(fieldinfo, 1));\n\t\tres = voidtype_setfield(self, newtup, NULL);\n\t\tPy_DECREF(newtup);\n\t\tif (!res) return -1;\n\t\tPy_DECREF(res);\n\t\treturn 0;\n\t}\n\t\n\t/* try to convert it to a number */\n\tn = PyArray_PyIntAsIntp(ind);\n\tif (error_converting(n)) {\n\t\tPyErr_Clear();\n\t\tgoto fail;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tflist = PyDict_GetItem(self->descr->fields, key);\n\tPy_DECREF(key);\n\tif (!flist) m = 0; \n\tm = PyTuple_GET_SIZE(flist);\n\tif (n < 0) n += m;\n\tif (n < 0 || n >= m) goto fail;\n\tfieldinfo = PyDict_GetItem(self->descr->fields, \n\t\t\t\t PyTuple_GET_ITEM(flist, n));\n\tnewtup = Py_BuildValue(\"(OOO)\", val, \n\t\t\t PyTuple_GET_ITEM(fieldinfo, 0),\n\t\t\t PyTuple_GET_ITEM(fieldinfo, 1));\n\tres = voidtype_setfield(self, fieldinfo, NULL);\n\tPy_DECREF(newtup);\n\tif (!res) return -1;\n\tPy_DECREF(res);\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_IndexError, msg);\n\treturn -1;\n}\n\nstatic PyMappingMethods voidtype_as_mapping = {\n (inquiry)voidtype_length,\t\t /*mp_length*/\n (binaryfunc)voidtype_subscript,\t /*mp_subscript*/\n (objobjargproc)voidtype_ass_subscript,\t /*mp_ass_subscript*/\n};\n\n\nstatic int\ngentype_getreadbuf(PyObject *self, int segment, void **ptrptr)\n{\n\tint numbytes;\n\tPyArray_Descr *outcode;\n\t\n\tif (segment != 0) {\n\t\tPyErr_SetString(PyExc_SystemError, \n\t\t\t\t\"Accessing non-existent array segment\");\n\t\treturn -1;\n\t}\n\n\toutcode = PyArray_DescrFromScalar(self);\n\tnumbytes = outcode->elsize;\n\tif PyArray_IsScalar(self, Flexible) {\n\t\tif PyArray_IsScalar(self, String)\n\t\t\t*ptrptr = PyString_AS_STRING(self);\n\t\telse if PyArray_IsScalar(self, Unicode)\n\t\t\t*ptrptr = (char *)PyUnicode_AS_DATA(self);\n\t\telse if PyArray_IsScalar(self, Void)\n\t\t\t*ptrptr = ((PyVoidScalarObject *)self)->obval;\n\t}\n\telse \n\t\t*ptrptr = (void *)_SOFFSET_(self, outcode->type_num);\n\n\tPy_DECREF(outcode);\n\treturn numbytes;\n}\n\nstatic int\ngentype_getsegcount(PyObject *self, int *lenp)\n{\n\tPyArray_Descr *outcode;\n\n\toutcode = PyArray_DescrFromScalar(self);\n\tif (lenp)\n\t\t*lenp = outcode->elsize;\n\tPy_DECREF(outcode);\n\treturn 1;\n}\n\nstatic int\ngentype_getcharbuf(PyObject *self, int segment, const char **ptrptr)\n{\n\tif (PyArray_IsScalar(self, String) ||\t\\\n\t PyArray_IsScalar(self, Unicode))\n\t\treturn gentype_getreadbuf(self, segment, (void **)ptrptr);\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"Non-character array cannot be interpreted \"\\\n\t\t\t\t\"as character buffer.\");\n\t\treturn -1;\n\t}\n}\n\n\nstatic PyBufferProcs gentype_as_buffer = {\n (getreadbufferproc)gentype_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)0, /*bf_getwritebuffer*/\n (getsegcountproc)gentype_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)gentype_getcharbuf, /*bf_getcharbuffer*/\n};\n\n\n#define BASEFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES\n#define LEAFFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES\n\nstatic PyTypeObject PyGenericArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"genericscalar\",\t /*tp_name*/\n sizeof(PyObject),\t\t /*tp_basicsize*/\n};\n\nstatic void\nunicode_dealloc(PyObject *v) \n{\n\tPyDataMem_FREE(((PyVoidScalarObject *)v)->obval);\n\tv->ob_type->tp_free(v);\n}\n\nstatic void\nvoid_dealloc(PyVoidScalarObject *v) \n{\n\tif (v->flags & OWNDATA)\n\t\tPyDataMem_FREE(v->obval);\n\tPy_XDECREF(v->descr);\n\tPy_XDECREF(v->base);\n\tv->ob_type->tp_free(v);\n}\n\nstatic void\nobject_arrtype_dealloc(PyObject *v)\n{\n\tPy_XDECREF(((PyObjectScalarObject *)v)->obval);\n\tv->ob_type->tp_free(v);\n}\n\n/* string and unicode inherit from Python Type first and so GET_ITEM is different to\n get to the Python Type.\n */\n\n/**begin repeat \n#name=byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, object#\n#TYPE=BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, STRING, UNICODE, OBJECT#\n#num=1*16,0,0,1#\n*/\nstatic PyObject *\n@name@_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj=NULL;\n\tPyObject *arr;\n\tPyArray_Descr *typecode;\n\n\tif (type->tp_bases && (PyTuple_GET_SIZE(type->tp_bases)==2)) {\n\t\tPyTypeObject *sup;\n\t\tPyObject *ret;\n\t\t/* We are inheriting from a Python type as well so\n\t\t give it first dibs on conversion */\n\t\tsup = (PyTypeObject *)PyTuple_GET_ITEM(type->tp_bases, @num@);\n\t\tret = sup->tp_new(type, args, kwds);\n\t\tif (ret) return ret;\n\t\tPyErr_Clear();\n\t\t/* now do default conversion */\n\t}\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\n\ttypecode = PyArray_DescrFromType(PyArray_@TYPE@);\n\tarr = PyArray_FromAny(obj, typecode, 0, 0, FORCECAST, NULL);\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n/**end repeat**/\n\n/* bool->tp_new only returns Py_True or Py_False */\nstatic PyObject *\nbool_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj=NULL;\n\tPyObject *arr;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\tif (obj == Py_False)\n\t\tPyArrayScalar_RETURN_FALSE;\n\tif (obj == Py_True)\n\t\tPyArrayScalar_RETURN_TRUE;\n\tarr = PyArray_FROM_OTF(obj, PyArray_BOOL, FORCECAST);\n\tif (arr && 0 == PyArray_NDIM(arr)) {\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)PyArray_DATA(arr));\n\t}\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n\nstatic PyObject *\nbool_arrtype_and(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)&(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_and(a, b);\n}\n\nstatic PyObject *\nbool_arrtype_or(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)|(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_or(a, b);\n}\n\nstatic PyObject *\nbool_arrtype_xor(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)^(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_xor(a, b);\n}\n\nstatic int\nbool_arrtype_nonzero(PyObject *a)\n{\n\treturn a == PyArrayScalar_True;\n}\n\n/* Arithmetic methods -- only so we can override &, |, ^. */\nstatic PyNumberMethods bool_arrtype_as_number = {\n\t0,\t\t\t\t\t/* nb_add */\n\t0,\t\t\t\t\t/* nb_subtract */\n\t0,\t\t\t\t\t/* nb_multiply */\n\t0,\t\t\t\t\t/* nb_divide */\n\t0,\t\t\t\t\t/* nb_remainder */\n\t0,\t\t\t\t\t/* nb_divmod */\n\t0,\t\t\t\t\t/* nb_power */\n\t0,\t\t\t\t\t/* nb_negative */\n\t0,\t\t\t\t\t/* nb_positive */\n\t0,\t\t\t\t\t/* nb_absolute */\n\t(inquiry)bool_arrtype_nonzero,\t\t/* nb_nonzero */\n\t0,\t\t\t\t\t/* nb_invert */\n\t0,\t\t\t\t\t/* nb_lshift */\n\t0,\t\t\t\t\t/* nb_rshift */\n\t(binaryfunc)bool_arrtype_and,\t\t/* nb_and */\n\t(binaryfunc)bool_arrtype_xor,\t\t/* nb_xor */\n\t(binaryfunc)bool_arrtype_or,\t\t/* nb_or */\n};\n\nstatic PyObject *\nvoid_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj, *arr;\n\tulonglong memu=1;\n\tPyObject *new=NULL;\n\tchar *destptr;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\t/* For a VOID scalar first see if obj is an integer or long \n\t and create new memory of that size (filled with 0) for the scalar\n\t*/\n\n\tif (PyLong_Check(obj) || PyInt_Check(obj) || \\\n\t PyArray_IsScalar(obj, Integer) ||\n\t (PyArray_Check(obj) && PyArray_NDIM(obj)==0 &&\t\\\n\t PyArray_ISINTEGER(obj))) {\n\t\tnew = obj->ob_type->tp_as_number->nb_long(obj);\n\t}\n\tif (new && PyLong_Check(new)) {\n\t\tPyObject *ret;\n\t\tmemu = PyLong_AsUnsignedLongLong(new);\n\t\tPy_DECREF(new);\n\t\tif (PyErr_Occurred() || (memu > MAX_INT)) {\n\t\t\tPyErr_Clear();\n\t\t\tPyErr_Format(PyExc_OverflowError, \n\t\t\t\t \"size must be smaller than %d\",\n\t\t\t\t (int) MAX_INT);\n\t\t\treturn NULL;\n\t\t}\n\t\tdestptr = PyDataMem_NEW((int) memu);\n\t\tif (destptr == NULL) return PyErr_NoMemory();\n\t\tret = type->tp_alloc(type, 0);\n\t\tif (ret == NULL) {\n\t\t\tPyDataMem_FREE(destptr);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\t((PyVoidScalarObject *)ret)->obval = destptr;\n\t\t((PyVoidScalarObject *)ret)->ob_size = (int) memu;\n\t\t((PyVoidScalarObject *)ret)->descr = \\\n\t\t\tPyArray_DescrNewFromType(PyArray_VOID);\n\t\t((PyVoidScalarObject *)ret)->descr->elsize = (int) memu;\n\t\t((PyVoidScalarObject *)ret)->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t((PyVoidScalarObject *)ret)->base = NULL;\n\t\tmemset(destptr, '\\0', (size_t) memu);\n\t\treturn ret;\n\t}\n\n\tarr = PyArray_FROM_OTF(obj, PyArray_VOID, FORCECAST);\n return PyArray_Return((PyArrayObject *)arr);\n}\n\n\n/**************** Define Hash functions ********************/\n\n/**begin repeat\n#lname=bool,ubyte,ushort#\n#name=Bool,UByte, UShort#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n return (long)(((Py@name@ScalarObject *)obj)->obval);\n}\n/**end repeat**/\n\n/**begin repeat\n#lname=byte,short,uint,ulong#\n#name=Byte,Short,UInt,ULong#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((Py@name@ScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n/**end repeat**/\n\n#if SIZEOF_INT != SIZEOF_LONG\nstatic long\nint_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((PyIntScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n#endif\n\n/**begin repeat\n#char=,u#\n#Char=,U#\n#ext=&& (x >= LONG_MIN),#\n*/\n#if SIZEOF_LONG != SIZEOF_LONGLONG\n/* we assume SIZEOF_LONGLONG=2*SIZEOF_LONG */\nstatic long\n@char@longlong_arrtype_hash(PyObject *obj)\n{\n long y;\n @char@longlong x = (((Py@Char@LongLongScalarObject *)obj)->obval);\n\n if ((x <= LONG_MAX)@ext@) {\n y = (long) x;\n }\n else {\n union Mask {\n long hashvals[2];\n @char@longlong v;\n } both;\n\n both.v = x;\n y = both.hashvals[0] + (1000003)*both.hashvals[1];\n }\n if (y == -1) y = -2;\n return y;\n}\n#endif\n/**end repeat**/\n\n#if SIZEOF_LONG==SIZEOF_LONGLONG\nstatic long\nulonglong_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((PyULongLongScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n#endif\n\n\n\n/* Wrong thing to do for longdouble, but....*/\n/**begin repeat\n#lname=float, longdouble#\n#name=Float, LongDouble#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n return _Py_HashDouble((double) ((Py@name@ScalarObject *)obj)->obval);\n}\n\n/* borrowed from complex_hash */\nstatic long\nc@lname@_arrtype_hash(PyObject *obj)\n{\n long hashreal, hashimag, combined;\n hashreal = _Py_HashDouble((double) \\\n (((PyC@name@ScalarObject *)obj)->obval).real);\n\n if (hashreal == -1) return -1;\n hashimag = _Py_HashDouble((double) \\\n (((PyC@name@ScalarObject *)obj)->obval).imag);\n if (hashimag == -1) return -1;\n\n combined = hashreal + 1000003 * hashimag;\n if (combined == -1) combined = -2;\n return combined;\n}\n/**end repeat**/\n\nstatic long\nobject_arrtype_hash(PyObject *obj)\n{\n return PyObject_Hash(((PyObjectScalarObject *)obj)->obval);\n}\n\n/* just hash the pointer */\nstatic long\nvoid_arrtype_hash(PyObject *obj)\n{\n return _Py_HashPointer((void *)(((PyVoidScalarObject *)obj)->obval));\n}\n\n/*object arrtype getattro and setattro */\nstatic PyObject *\nobject_arrtype_getattro(PyObjectScalarObject *obj, PyObject *attr) {\n\tPyObject *res;\n\n\t/* first look in object and then hand off to generic type */\n\n\tres = PyObject_GenericGetAttr(obj->obval, attr);\t\n\tif (res) return res;\n\tPyErr_Clear();\n\treturn \tPyObject_GenericGetAttr((PyObject *)obj, attr);\n}\n\nstatic int\nobject_arrtype_setattro(PyObjectScalarObject *obj, PyObject *attr, PyObject *val) {\n\tint res;\n\t/* first look in object and then hand off to generic type */\n\n\tres = PyObject_GenericSetAttr(obj->obval, attr, val);\n\tif (res >= 0) return res;\n\tPyErr_Clear();\n\treturn PyObject_GenericSetAttr((PyObject *)obj, attr, val);\n}\n\nstatic PyObject *\nobject_arrtype_concat(PyObjectScalarObject *self, PyObject *other)\n{\n\treturn PySequence_Concat(self->obval, other);\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_length(PyObjectScalarObject *self) \n{\n\treturn PyObject_Length(self->obval);\n}\n\nstatic PyObject *\nobject_arrtype_repeat(PyObjectScalarObject *self, _int_or_ssize_t count)\n{\n\treturn PySequence_Repeat(self->obval, count);\n}\n\nstatic PyObject *\nobject_arrtype_subscript(PyObjectScalarObject *self, PyObject *key)\n{\n\treturn PyObject_GetItem(self->obval, key);\n}\n\nstatic int\nobject_arrtype_ass_subscript(PyObjectScalarObject *self, PyObject *key, \n\t\t\t PyObject *value)\n{\n\treturn PyObject_SetItem(self->obval, key, value);\n}\n\nstatic int\nobject_arrtype_contains(PyObjectScalarObject *self, PyObject *ob)\n{\n\treturn PySequence_Contains(self->obval, ob);\n}\n\nstatic PyObject *\nobject_arrtype_inplace_concat(PyObjectScalarObject *self, PyObject *o)\n{\n\treturn PySequence_InPlaceConcat(self->obval, o);\n}\n\nstatic PyObject *\nobject_arrtype_inplace_repeat(PyObjectScalarObject *self, _int_or_ssize_t count)\n{\n\treturn PySequence_InPlaceRepeat(self->obval, count);\n}\n\nstatic PySequenceMethods object_arrtype_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)object_arrtype_length, /*sq_length*/\n (binaryfunc)object_arrtype_concat, /*sq_concat*/\n (ssizeargfunc)object_arrtype_repeat, /*sq_repeat*/\n 0, /*sq_item*/\n 0, /*sq_slice*/\n 0, /* sq_ass_item */\n 0, /* sq_ass_slice */\n (objobjproc)object_arrtype_contains, /* sq_contains */\n (binaryfunc)object_arrtype_inplace_concat, /* sq_inplace_concat */\n (ssizeargfunc)object_arrtype_inplace_repeat, /* sq_inplace_repeat */\n#else\n (inquiry)object_arrtype_length, /*sq_length*/\n (binaryfunc)object_arrtype_concat, /*sq_concat*/\n (intargfunc)object_arrtype_repeat, /*sq_repeat*/\n 0, /*sq_item*/\n 0, /*sq_slice*/\n 0, /* sq_ass_item */\n 0, /* sq_ass_slice */\n (objobjproc)object_arrtype_contains, /* sq_contains */\n (binaryfunc)object_arrtype_inplace_concat, /* sq_inplace_concat */\n (intargfunc)object_arrtype_inplace_repeat, /* sq_inplace_repeat */\n#endif\n};\n\nstatic PyMappingMethods object_arrtype_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)object_arrtype_length,\n (binaryfunc)object_arrtype_subscript,\n (objobjargproc)object_arrtype_ass_subscript,\n#else\n (inquiry)object_arrtype_length,\n (binaryfunc)object_arrtype_subscript,\n (objobjargproc)object_arrtype_ass_subscript,\n#endif\n};\n\nstatic _int_or_ssize_t\nobject_arrtype_getsegcount(PyObjectScalarObject *self, _int_or_ssize_t *lenp) \n{\n\tint newlen;\n\tint cnt;\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\t\n\tif (pb == NULL || \\\n\t pb->bf_getsegcount == NULL || \\\n\t (cnt = (*pb->bf_getsegcount)(self->obval, &newlen)) != 1) \n\t\treturn 0;\n\t\n\tif (lenp) \n\t\t*lenp = newlen;\n\t\n\treturn cnt;\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_getreadbuf(PyObjectScalarObject *self, _int_or_ssize_t segment, void **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getreadbuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a readable buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getreadbuffer)(self->obval, segment, ptrptr);\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_getwritebuf(PyObjectScalarObject *self, _int_or_ssize_t segment, void **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getwritebuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a writeable buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getwritebuffer)(self->obval, segment, ptrptr);\n}\n\nstatic _int_or_ssize_t \nobject_arrtype_getcharbuf(PyObjectScalarObject *self, _int_or_ssize_t segment, \n\t\t\t const char **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getcharbuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a character buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getcharbuffer)(self->obval, segment, ptrptr);\n}\n\nstatic PyBufferProcs object_arrtype_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)object_arrtype_getreadbuf,\n (writebufferproc)object_arrtype_getwritebuf,\n (segcountproc)object_arrtype_getsegcount,\n (charbufferproc)object_arrtype_getcharbuf,\n#else\n (getreadbufferproc)object_arrtype_getreadbuf,\n (getwritebufferproc)object_arrtype_getwritebuf,\n (getsegcountproc)object_arrtype_getsegcount,\n (getcharbufferproc)object_arrtype_getcharbuf,\n#endif\n};\n\nstatic PyObject *\nobject_arrtype_call(PyObjectScalarObject *obj, PyObject *args, PyObject *kwds)\n{\n\treturn PyObject_Call(obj->obval, args, kwds);\n}\n\nstatic PyTypeObject PyObjectArrType_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"objectscalar\",\t /*tp_name*/\n sizeof(PyObjectScalarObject),\t /*tp_basicsize*/\n 0, /* tp_itemsize */\n (destructor)object_arrtype_dealloc, /* tp_dealloc */\n 0, /* tp_print */\n 0, /* tp_getattr */\n 0, /* tp_setattr */\n 0, /* tp_compare */\n 0, /* tp_repr */\n 0, /* tp_as_number */\n &object_arrtype_as_sequence, /* tp_as_sequence */\n &object_arrtype_as_mapping, /* tp_as_mapping */\n 0, /* tp_hash */\n (ternaryfunc)object_arrtype_call, /* tp_call */\n 0, /* tp_str */\n (getattrofunc)object_arrtype_getattro, /* tp_getattro */\n (setattrofunc)object_arrtype_setattro, /* tp_setattro */\n &object_arrtype_as_buffer, /* tp_as_buffer */\n 0, /* tp_flags */\n};\n\n/**begin repeat\n#name=bool, string, unicode, void#\n#NAME=Bool, String, Unicode, Void#\n*/\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@scalar\",\t /*tp_name*/\n sizeof(Py@NAME@ScalarObject),\t /*tp_basicsize*/\n};\n/**end repeat**/\n\n/**begin repeat\n#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n#name=int*5, uint*5, float*3, complex*3#\n#CNAME=(CHAR, SHORT, INT, LONG, LONGLONG)*2, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n*/\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@\" STRBITSOF_@CNAME@ \"scalar\",\t /*tp_name*/\n sizeof(Py@NAME@ScalarObject),\t /*tp_basicsize*/\n};\n\n/**end repeat**/\n\n\nstatic PyNumberMethods longdoubletype_as_number;\nstatic PyNumberMethods clongdoubletype_as_number;\n\n\nstatic void\ninitialize_numeric_types(void)\n{\n\tPyGenericArrType_Type.tp_dealloc = (destructor)gentype_dealloc;\n\tPyGenericArrType_Type.tp_as_number = &gentype_as_number;\n\tPyGenericArrType_Type.tp_as_buffer = &gentype_as_buffer;\n\tPyGenericArrType_Type.tp_flags = BASEFLAGS;\n\tPyGenericArrType_Type.tp_methods = gentype_methods;\n\tPyGenericArrType_Type.tp_getset = gentype_getsets;\n\tPyGenericArrType_Type.tp_new = NULL;\n PyGenericArrType_Type.tp_alloc = gentype_alloc;\n\tPyGenericArrType_Type.tp_free = _pya_free;\n\tPyGenericArrType_Type.tp_repr = gentype_repr;\n\tPyGenericArrType_Type.tp_str = gentype_str;\n\tPyGenericArrType_Type.tp_richcompare = gentype_richcompare;\n\n\tPyBoolArrType_Type.tp_as_number = &bool_arrtype_as_number;\n\n\tPyStringArrType_Type.tp_alloc = NULL;\n\tPyStringArrType_Type.tp_free = NULL;\n\t\n\tPyStringArrType_Type.tp_repr = stringtype_repr;\n\tPyStringArrType_Type.tp_str = stringtype_str;\n\n\tPyUnicodeArrType_Type.tp_repr = unicodetype_repr;\n\tPyUnicodeArrType_Type.tp_str = unicodetype_str;\n\n\tPyVoidArrType_Type.tp_methods = voidtype_methods;\n\tPyVoidArrType_Type.tp_getset = voidtype_getsets;\n\tPyVoidArrType_Type.tp_as_mapping = &voidtype_as_mapping;\n\t\n\t/**begin repeat\n#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating, \nComplexFloating, Flexible, Character#\n\t*/\n Py@NAME@ArrType_Type.tp_flags = BASEFLAGS;\n\t/**end repeat**/\n\n\t/**begin repeat\n#name=bool, byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, void, object#\n#NAME=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, String, Unicode, Void, Object#\n\t*/\n\tPy@NAME@ArrType_Type.tp_flags = LEAFFLAGS;\n\tPy@NAME@ArrType_Type.tp_new = @name@_arrtype_new;\n\tPy@NAME@ArrType_Type.tp_richcompare = gentype_richcompare;\n\t/**end repeat**/\n\t/* Allow the Void type to be subclassed -- for adding new types */\n\tPyVoidArrType_Type.tp_flags = BASEFLAGS;\n\n /**begin repeat\n#name=bool, byte, short, ubyte, ushort, uint, ulong, ulonglong, float, longdouble, cfloat, clongdouble, void, object#\n#NAME=Bool, Byte, Short, UByte, UShort, UInt, ULong, ULongLong, Float, LongDouble, CFloat, CLongDouble, Void, Object#\n */\n Py@NAME@ArrType_Type.tp_hash = @name@_arrtype_hash;\n /**end repeat**/\n\n#if SIZEOF_INT != SIZEOF_LONG\n /* We won't be inheriting from Python Int type. */\n PyIntArrType_Type.tp_hash = int_arrtype_hash;\n#endif\n\n#if SIZEOF_LONG != SIZEOF_LONGLONG\n /* We won't be inheriting from Python Int type. */\n PyLongLongArrType_Type.tp_hash = longlong_arrtype_hash;\n#endif\n\n\t/* These need to be coded specially because getitem does not\n\t return a normal Python type\n\t*/\n\tPyLongDoubleArrType_Type.tp_as_number = &longdoubletype_as_number;\n\tPyCLongDoubleArrType_Type.tp_as_number = &clongdoubletype_as_number;\n\n\t/**begin repeat\n#name=int, long, hex, oct, float, repr, str#\n#kind=tp_as_number->nb*5, tp*2#\n\t*/\n\tPyLongDoubleArrType_Type.@kind@_@name@ = longdoubletype_@name@;\n\tPyCLongDoubleArrType_Type.@kind@_@name@ = clongdoubletype_@name@;\n\t/**end repeat**/\n\n\tPyStringArrType_Type.tp_itemsize = sizeof(char);\n\tPyVoidArrType_Type.tp_dealloc = (destructor) void_dealloc;\n\tPyUnicodeArrType_Type.tp_dealloc = unicode_dealloc;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMapIter_Type.tp_iter = PyObject_SelfIter;\n\n/**begin repeat\n#name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,#\n#num=BOOL, BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, OBJECT, NTYPES#\n**/\n PyArrayScalar_Offset[PyArray_@num@] = (int) offsetof(Py@name@ScalarObject, obval);\n/**end repeat**/\n}\n\n\n/* the order of this table is important */\nstatic PyTypeObject *typeobjects[] = {\n &PyBoolArrType_Type,\n &PyByteArrType_Type,\n\t&PyUByteArrType_Type,\n &PyShortArrType_Type,\n &PyUShortArrType_Type,\n\t&PyIntArrType_Type,\n\t&PyUIntArrType_Type,\n\t&PyLongArrType_Type,\n\t&PyULongArrType_Type,\n\t&PyLongLongArrType_Type,\n\t&PyULongLongArrType_Type,\n\t&PyFloatArrType_Type,\n\t&PyDoubleArrType_Type,\n\t&PyLongDoubleArrType_Type,\n\t&PyCFloatArrType_Type,\n\t&PyCDoubleArrType_Type,\n\t&PyCLongDoubleArrType_Type,\n\t&PyObjectArrType_Type,\n\t&PyStringArrType_Type,\n\t&PyUnicodeArrType_Type,\n\t&PyVoidArrType_Type\n};\n\nstatic int\n_typenum_fromtypeobj(PyObject *type, int user)\n{\n\tint typenum, i;\n\n\ttypenum = PyArray_NOTYPE;\n i = 0;\n\twhile(i < PyArray_NTYPES) {\n\t\tif (type == (PyObject *)typeobjects[i]) {\n\t\t\ttypenum = i;\n\t\t\tbreak;\n\t\t}\n i++;\n\t}\n\t\n\tif (!user) return typenum;\n\n\t/* Search any registered types */\n\ti = 0;\n\twhile (i < PyArray_NUMUSERTYPES) {\n\t\tif (type == (PyObject *)(userdescrs[i]->typeobj)) {\n\t\t\ttypenum = i + PyArray_USERDEF;\n\t\t\tbreak;\n\t\t}\n\t\ti++;\n\t}\n\treturn typenum;\n}\n\n/* new reference */\nstatic PyArray_Descr *\nPyArray_DescrFromTypeObject(PyObject *type)\n{\t\n\tint typenum;\n\tPyArray_Descr *new, *conv=NULL;\n\n\t/* if it's a builtin type, then use the typenumber */\n\ttypenum = _typenum_fromtypeobj(type,1);\t\n\tif (typenum != PyArray_NOTYPE) {\n\t\tnew = PyArray_DescrFromType(typenum);\n\t\tif (PyTypeNum_ISUSERDEF(typenum)) goto finish;\n\t\treturn new;\n\t}\n\n\t/* Check the generic types */\n\tif ((type == (PyObject *) &PyNumberArrType_Type) ||\t\t\\\n\t (type == (PyObject *) &PyInexactArrType_Type) ||\t\t\\\n\t (type == (PyObject *) &PyFloatingArrType_Type))\n\t\ttypenum = PyArray_DOUBLE;\n\telse if (type == (PyObject *)&PyComplexFloatingArrType_Type)\n\t\ttypenum = PyArray_CDOUBLE;\n\telse if ((type == (PyObject *)&PyIntegerArrType_Type) ||\t\\\n\t\t (type == (PyObject *)&PySignedIntegerArrType_Type))\n\t\ttypenum = PyArray_LONG;\n\telse if (type == (PyObject *) &PyUnsignedIntegerArrType_Type)\n\t\ttypenum = PyArray_ULONG;\n\telse if (type == (PyObject *) &PyCharacterArrType_Type)\n\t\ttypenum = PyArray_STRING;\n\telse if ((type == (PyObject *) &PyGenericArrType_Type) || \\\n\t\t (type == (PyObject *) &PyFlexibleArrType_Type))\n\t\ttypenum = PyArray_VOID;\n\n\tif (typenum != PyArray_NOTYPE) {\n\t\treturn PyArray_DescrFromType(typenum);\n\t}\n\t\n\t/* Otherwise --- type is a sub-type of an array scalar\n\t currently only VOID allows it -- use it as the type-object.\n\t*/\n\t/* look for a dtypedescr attribute */\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\n finish:\n\tconv = _arraydescr_fromobj(type);\n\tif (conv) {\n\t\tnew->fields = conv->fields;\n\t\tPy_INCREF(new->fields);\n\t\tnew->elsize = conv->elsize;\n\t\tnew->subarray = conv->subarray;\n\t\tconv->subarray = NULL;\n\t\tPy_DECREF(conv);\n\t}\n Py_DECREF(new->typeobj);\n new->typeobj = (PyTypeObject *)type;\n Py_INCREF(type);\n\treturn new;\n}\n\n/* New reference */\n/*OBJECT_API\n Return descr object from array scalar.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromScalar(PyObject *sc)\n{\n\tint type_num;\n\tPyArray_Descr *descr;\n\n\tif PyArray_IsScalar(sc, Void) {\n\t\tdescr = ((PyVoidScalarObject *)sc)->descr;\n\t\tPy_INCREF(descr);\n\t\treturn descr;\n\t}\n descr = PyArray_DescrFromTypeObject((PyObject *)sc->ob_type);\n if (descr->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(descr);\n type_num = descr->type_num;\n\t\tif (type_num == PyArray_STRING) \n\t\t\tdescr->elsize = PyString_GET_SIZE(sc);\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tdescr->elsize = PyUnicode_GET_DATA_SIZE(sc);\n#ifndef Py_UNICODE_WIDE\n\t\t\tdescr->elsize <<= 1;\n#endif\t\t\n\t\t}\n\t\telse {\n\t\t\tdescr->elsize =\t\t\t\t\t\\\n\t\t\t\t((PyVoidScalarObject *)sc)->ob_size;\n\t\t\tdescr->fields = PyObject_GetAttrString(sc, \"fields\");\n\t\t\tif (!descr->fields || !PyDict_Check(descr->fields) || \\\n\t\t\t (descr->fields == Py_None)) {\n\t\t\t\tPy_XDECREF(descr->fields);\n\t\t\t\tdescr->fields = NULL;\n\t\t\t}\n\t\t\tPyErr_Clear();\n\t\t}\n }\n\treturn descr;\n}\n\n/* New reference */\n/*OBJECT_API\n Get a typeobject from a type-number\n*/\nstatic PyObject *\nPyArray_TypeObjectFromType(int type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr == NULL) return NULL;\n\tobj = (PyObject *)descr->typeobj;\n\tPy_INCREF(obj);\n\tPy_DECREF(descr);\n\treturn obj;\n}\n\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + " return PyArray_NewFlagsObject(NULL);" + ], + "deleted": [ + "\tstatic int flags=CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;", + "", + " return PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\",", + " self, flags, 1);" + ] + } + }, + { + "old_path": "numpy/core/src/umathmodule.c.src", + "new_path": "numpy/core/src/umathmodule.c.src", + "filename": "umathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -1394,34 +1394,31 @@ static void\n static void\n @TYP@_ones_like(char **args, intp *dimensions, intp *steps, void *data)\n {\n- intp i, is1 = steps[0], os = steps[1], n = dimensions[0];\n- char *i1 = args[0], *op = args[1];\n- c@typ@ *x, *y;\n- @typ@ xr, xi, xmag2;\n-\n- for (i = 0; i < n; i++, i1 += is1, op += os) {\n- x = (c@typ@ *)i1;\n- y = (c@typ@ *)op;\n- xr = x->real;\n- xi = x->imag;\n- xmag2 = xr*xr + xi*xi;\n- y->real = 1.0;\n- y->imag = 0.0;\n- }\n+ intp i, is1 = steps[0], os = steps[1], n = dimensions[0];\n+ char *i1 = args[0], *op = args[1];\n+ c@typ@ *x, *y;\n+ @typ@ xr, xi, xmag2;\n+ \n+ for (i = 0; i < n; i++, i1 += is1, op += os) {\n+ x = (c@typ@ *)i1;\n+ y = (c@typ@ *)op;\n+ xr = x->real;\n+ xi = x->imag;\n+ xmag2 = xr*xr + xi*xi;\n+ y->real = 1.0;\n+ y->imag = 0.0;\n+ }\n }\n /**end repeat**/\n \n-\n static PyObject *\n Py_get_one(PyObject *o)\n {\n- return PyInt_FromLong(1.0);\n+ return PyInt_FromLong(1);\n }\n \n-/**begin repeat\n \n /**begin repeat\n-\n #TYP=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n #typ=char, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n #btyp=float*4, double*6#\n@@ -1447,7 +1444,6 @@ static void\n /**end repeat**/\n \n /**begin repeat\n-\n #TYP=UBYTE, BYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE#\n #typ=ubyte, char, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n */\n", + "added_lines": 15, + "deleted_lines": 19, + "source_code": "/* -*- c -*- */\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#define _UMATHMODULE\n#include \"numpy/ufuncobject.h\"\n#include \"abstract.h\"\n#include \n\n/* A whole slew of basic math functions are provided originally\n by Konrad Hinsen. */\n\n#if !defined(__STDC__) && !defined(_MSC_VER)\nextern double fmod (double, double);\nextern double frexp (double, int *);\nextern double ldexp (double, int);\nextern double modf (double, double *);\n#endif\n#ifndef M_PI\n#define M_PI 3.14159265358979323846264338328\n#endif\n\n\n#ifndef HAVE_INVERSE_HYPERBOLIC\nstatic double acosh(double x)\n{\n\treturn 2*log(sqrt((x+1.0)/2)+sqrt((x-1.0)/2));\n}\n\ndouble log1p(double);\nstatic double asinh(double xx)\n{\n\tdouble x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e8) {\n\t\td = x;\n\t} else {\n\t\td = sqrt(x*x + 1);\n\t}\n\treturn sign*log1p(x*(1.0 + x/(d+1)));\n}\n\nstatic double atanh(double x)\n{\n\treturn 0.5*log1p(2.0*x/(1.0-x));\n}\n#endif\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC_FLOAT)\n#ifdef HAVE_FLOAT_FUNCS\n#ifdef log1pf\n#undef log1pf\n#endif\n#ifdef logf\n#undef logf\n#endif\n#ifdef sqrtf\n#undef sqrtf\n#endif\nfloat log1pf(float);\nfloat logf(float);\nfloat sqrtf(float);\n#ifdef acoshf\n#undef acoshf\n#endif\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\n#ifdef asinhf\n#undef asinhf\n#endif\nstatic float asinhf(float xx)\n{\n\tfloat x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e5) {\n\t\td = x;\n\t} else {\n\t\td = sqrtf(x*x + 1);\n\t}\n\treturn sign*log1pf(x*(1.0 + x/(d+1)));\n}\n\n#ifdef atanhf\n#undef atanhf\n#endif\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\n#ifdef acoshf\n#undef acoshf\n#endif\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\n#ifdef asinhf\n#undef asinhf\n#endif\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\n#ifdef atanhf\n#undef atanhf\n#endif\nstatic float atanhf(float x)\n{\n return (float)atanh((double)(x));\n}\n#endif\n#endif\n\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE)\n#ifdef HAVE_LONGDOUBLE_FUNCS\n#ifdef logl\n#undef logl\n#endif\n#ifdef sqrtl\n#undef sqrtl\n#endif\n#ifdef log1pl\n#undef log1pl\n#endif\nlongdouble logl(longdouble);\nlongdouble sqrtl(longdouble);\nlongdouble log1pl(longdouble);\n#ifdef acoshl\n#undef acoshl\n#endif\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\n#ifdef asinhl\n#undef asinhl\n#endif\nstatic longdouble asinhl(longdouble xx)\n{\n\tlongdouble x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e17) {\n\t\td = x;\n\t} else {\n\t\td = sqrtl(x*x + 1);\n\t}\n\treturn sign*log1pl(x*(1.0 + x/(d+1)));\n}\n\n#ifdef atanhl\n#undef atanhl\n#endif\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n\n#else\n\n#ifdef acoshl\n#undef acoshl\n#endif\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\n#ifdef asinhl\n#undef asinhl\n#endif\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\n#ifdef atanhl\n#undef atanhl\n#endif\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\n}\n\n#endif\n#endif\n\n\n#ifdef HAVE_HYPOT\n#if !defined(NeXT) && !defined(_MSC_VER)\nextern double hypot(double, double);\n#endif\n#else\nstatic double hypot(double x, double y)\n{\n\tdouble yx;\n\n\tx = fabs(x);\n\ty = fabs(y);\n\tif (x < y) {\n\t\tdouble temp = x;\n\t\tx = y;\n\t\ty = temp;\n\t}\n\tif (x == 0.)\n\t\treturn 0.;\n\telse {\n\t\tyx = y/x;\n\t\treturn x*sqrt(1.+yx*yx);\n\t}\n}\n#endif\n\n\n#ifndef HAVE_RINT\nstatic double \nrint (double x)\n{\n\tdouble y, r;\n\t\n\ty = floor(x);\n\tr = x - y;\n\t\n\tif (r > 0.5) goto rndup;\n\n\t/* Round to nearest even */\n\tif (r==0.5) {\n\t\tr = y - 2.0*floor(0.5*y);\n\t\tif (r==1.0) {\n\t\trndup:\t \n\t\t\ty+=1.0;\n\t\t}\n\t}\n\treturn y;\n}\n#endif\n\n\n\n/* Define isnan, isinf, isfinite, signbit if needed */\n/* Use fpclassify if possible */\n/* isnan, isinf --\n these will use macros and then fpclassify if available before\n defaulting to a dumb convert-to-double version...\n\n isfinite -- define a macro if not already available\n signbit -- if macro available use it, otherwise define a function\n and a dumb convert-to-double version for other types.\n*/\n\n#if defined(fpclassify)\n\n#if !defined(isnan)\n#define isnan(x) (fpclassify(x) == FP_NAN)\n#endif\n#if !defined(isinf)\n#define isinf(x) (fpclassify(x) == FP_INFINITE)\n#endif\n\n#else /* check to see if already have a function like this */\n\n#if !defined(HAVE_ISNAN)\n\n#if !defined(isnan)\n#include \"_isnan.c\"\n#endif\n#endif /* HAVE_ISNAN */\n\n#if !defined(HAVE_ISINF)\n#if !defined(isinf)\n#define isinf(x) (!isnan((x)) && isnan((x)-(x)))\n#endif\n#endif /* HAVE_ISINF */\n\n#endif /* defined(fpclassify) */\n\n\n/* Define signbit if needed */\n#if !defined(signbit)\n#include \"_signbit.c\"\n#endif\n\n/* Now defined the extended type macros */\n\n#if !defined(isnan)\n\n#if !defined(HAVE_LONGDOUBLE_FUNCS) || !defined(HAVE_ISNAN)\n#define isnanl(x) isnan((double)(x))\n#endif\n\n#if !defined(HAVE_FLOAT_FUNCS) || !defined(HAVE_ISNAN)\n#define isnanf(x) isnan((double)(x))\n#endif\n\n#else /* !defined(isnan) */\n\n#define isnanl(x) isnan((x))\n#define isnanf(x) isnan((x))\n\n#endif /* !defined(isnan) */\n\n\n#if !defined(isinf)\n\n#if !defined(HAVE_LONGDOUBLE_FUNCS) || !defined(HAVE_ISINF)\n#define isinfl(x) (!isnanl((x)) && isnanl((x)-(x)))\n#endif\n\n#if !defined(HAVE_FLOAT_FUNCS) || !defined(HAVE_ISINF)\n#define isinff(x) (!isnanf((x)) && isnanf((x)-(x)))\n#endif\n\n#else /* !defined(isinf) */\n\n#define isinfl(x) isinf((x))\n#define isinff(x) isinf((x))\n\n#endif /* !defined(isinf) */\n\n\n#if !defined(signbit)\n#define signbitl(x) ((longdouble) signbit((double)(x)))\n#define signbitf(x) ((float) signbit((double) (x)))\n#else\n#define signbitl(x) signbit((x))\n#define signbitf(x) signbit((x))\n#endif\n\n#if !defined(isfinite)\n#define isfinite(x) (!(isinf((x)) || isnan((x))))\n#endif\n#define isfinitef(x) (!(isinff((x)) || isnanf((x))))\n#define isfinitel(x) (!(isinfl((x)) || isnanl((x))))\n\n\n/* First, the C functions that do the real work */\n\n/* if C99 extensions not available then define dummy functions that use the\n double versions for\n\n sin, cos, tan\n sinh, cosh, tanh,\n fabs, floor, ceil, fmod, sqrt, log10, log, exp, fabs\n asin, acos, atan,\n asinh, acosh, atanh\n\n hypot, atan2, pow\n*/\n\n/**begin repeat\n\n#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan,rint)*2#\n#typ=longdouble*17, float*17#\n#c=l*17,f*17#\n#TYPE=LONGDOUBLE*17, FLOAT*17#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef @kind@@c@\n#undef @kind@@c@\n#endif\n@typ@ @kind@@c@(@typ@ x) {\n\treturn (@typ@) @kind@((double)x);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n\n#kind=(atan2,hypot,pow,fmod)*2#\n#typ=longdouble*4, float*4#\n#c=l*4,f*4#\n#TYPE=LONGDOUBLE*4,FLOAT*4#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef @kind@@c@\n#undef @kind@@c@\n#endif\n@typ@ @kind@@c@(@typ@ x, @typ@ y) {\n\treturn (@typ@) @kind@((double)x, (double) y);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n#kind=modf*2#\n#typ=longdouble, float#\n#c=l,f#\n#TYPE=LONGDOUBLE, FLOAT#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef modf@c@\n#undef modf@c@\n#endif\n@typ@ modf@c@(@typ@ x, @typ@ *iptr) {\n double nx, niptr, y;\n nx = (double) x;\n y = modf(nx, &niptr);\n *iptr = (@typ@) niptr;\n return (@typ@) y;\n}\n#endif\n/**end repeat**/\n\n\n\n#ifndef HAVE_LOG1P\ndouble log1p(double x)\n{\n\tdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn log(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_LONGDOUBLE_FUNCS)\n#ifdef log1pl\n#undef log1pl\n#endif\nlongdouble log1pl(longdouble x)\n{\n\tlongdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logl(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_FLOAT_FUNCS)\n#ifdef log1pf\n#undef log1pf\n#endif\nfloat log1pf(float x)\n{\n\tfloat u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logf(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#ifndef HAVE_EXPM1\nstatic double expm1(double x)\n{\n\tdouble u = exp(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/log(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_LONGDOUBLE_FUNCS)\n#ifdef expml1\n#undef expml1\n#endif\nstatic longdouble expm1l(longdouble x)\n{\n\tlongdouble u = expl(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logl(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_FLOAT_FUNCS)\n#ifdef expm1f\n#undef expm1f\n#endif\nstatic float expm1f(float x)\n{\n\tfloat u = expf(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logf(u);\n\t}\n}\n#endif\n\n\n\n\n/* Don't pass structures between functions (only pointers) because how\n structures are passed is compiler dependent and could cause\n segfaults if ufuncobject.c is compiled with a different compiler\n than an extension that makes use of the UFUNC API\n*/\n\n/**begin repeat\n\n#typ=float, double, longdouble#\n#c=f,,l#\n*/\n\n/* constants */\nstatic c@typ@ nc_1@c@ = {1., 0.};\nstatic c@typ@ nc_half@c@ = {0.5, 0.};\nstatic c@typ@ nc_i@c@ = {0., 1.};\nstatic c@typ@ nc_i2@c@ = {0., 0.5};\n/*\nstatic c@typ@ nc_mi@c@ = {0., -1.};\nstatic c@typ@ nc_pi2@c@ = {M_PI/2., 0.};\n*/\n\nstatic void\nnc_sum@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real + b->real;\n\tr->imag = a->imag + b->imag;\n\treturn;\n}\n\nstatic void\nnc_diff@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real - b->real;\n\tr->imag = a->imag - b->imag;\n\treturn;\n}\n\nstatic void\nnc_neg@c@(c@typ@ *a, c@typ@ *r)\n{\n\tr->real = -a->real;\n\tr->imag = -a->imag;\n\treturn;\n}\n\nstatic void\nnc_prod@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\tr->real = ar*br - ai*bi;\n\tr->imag = ar*bi + ai*br;\n\treturn;\n}\n\nstatic void\nnc_quot@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\n\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@typ@ d = br*br + bi*bi;\n\tr->real = (ar*br + ai*bi)/d;\n\tr->imag = (ai*br - ar*bi)/d;\n\treturn;\n}\n\nstatic void\nnc_floor_quot@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@typ@ d = br*br + bi*bi;\n\tr->real = floor@c@((ar*br + ai*bi)/d);\n\tr->imag = 0;\n\treturn;\n}\n\nstatic void\nnc_sqrt@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ s,d;\n\tif (x->real == 0. && x->imag == 0.)\n\t\t*r = *x;\n\telse {\n\t\ts = sqrt@c@(0.5*(fabs@c@(x->real) + hypot@c@(x->real,x->imag)));\n\t\td = 0.5*x->imag/s;\n\t\tif (x->real > 0.) {\n\t\t\tr->real = s;\n\t\t\tr->imag = d;\n\t\t}\n\t\telse if (x->imag >= 0.) {\n\t\t\tr->real = d;\n\t\t\tr->imag = s;\n\t\t}\n\t\telse {\n\t\t\tr->real = -d;\n\t\t\tr->imag = -s;\n\t\t}\n\t}\n\treturn;\n}\n\nstatic void\nnc_log@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ l = hypot@c@(x->real,x->imag);\n\tr->imag = atan2@c@(x->imag, x->real);\n\tr->real = log@c@(l);\n\treturn;\n}\n\nstatic void\nnc_log1p@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ l = hypot@c@(x->real + 1.0,x->imag);\n\tr->imag = atan2@c@(x->imag, x->real + 1.0);\n\tr->real = log@c@(l);\n\treturn;\n}\n\nstatic void\nnc_exp@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ a = exp@c@(x->real);\n\tr->real = a*cos@c@(x->imag);\n\tr->imag = a*sin@c@(x->imag);\n\treturn;\n}\n\nstatic void\nnc_expm1@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ a = exp@c@(x->real);\n\tr->real = a*cos@c@(x->imag) - 1.0;\n\tr->imag = a*sin@c@(x->imag);\n\treturn;\n}\n\nstatic void\nnc_pow@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n intp n;\n @typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\n\tif (br == 0. && bi == 0.) {\n\t\tr->real = 1.;\n\t\tr->imag = 0.;\n return;\n\t}\n\tif (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n return;\n\t}\n if (bi == 0 && (n=(intp)br) == br) {\n if (n > -100 && n < 100) {\n c@typ@ p, aa;\n intp mask = 1;\n if (n < 0) n = -n;\n aa = nc_1@c@;\n p.real = ar; p.imag = ai;\n while (1) {\n if (n & mask)\n nc_prod@c@(&aa,&p,&aa);\n mask <<= 1;\n if (n < mask || mask <= 0) break;\n nc_prod@c@(&p,&p,&p);\n }\n r->real = aa.real; r->imag = aa.imag;\n if (br < 0) nc_quot@c@(&nc_1@c@, r, r);\n return;\n }\n }\n /* complexobect.c uses an inline version of this formula\n investigate whether this had better performance or accuracy */\n nc_log@c@(a, r);\n nc_prod@c@(r, b, r);\n nc_exp@c@(r, r);\n return;\n}\n\n\nstatic void\nnc_prodi@c@(c@typ@ *x, c@typ@ *r)\n{\n\tr->real = -x->imag;\n\tr->imag = x->real;\n\treturn;\n}\n\n\nstatic void\nnc_acos@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x,x,r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_sum@c@(x, r, r);\n\tnc_log@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/* return nc_neg(nc_prodi(nc_log(nc_sum(x,nc_prod(nc_i,\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x))))))));\n\t*/\n}\n\nstatic void\nnc_acosh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x, x, r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_sum@c@(x, r, r);\n\tnc_log@c@(r, r);\n\treturn;\n\t/*\n\t return nc_log(nc_sum(x,nc_prod(nc_i,\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x))))));\n\t*/\n}\n\nstatic void\nnc_asin@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_prod@c@(x, x, r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(x, pa);\n\tnc_sum@c@(pa, r, r);\n\tnc_log@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/*\n\t return nc_neg(nc_prodi(nc_log(nc_sum(nc_prod(nc_i,x),\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x)))))));\n\t*/\n}\n\n\nstatic void\nnc_asinh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x, x, r);\n\tnc_sum@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_diff@c@(r, x, r);\n\tnc_log@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/*\n\t return nc_neg(nc_log(nc_diff(nc_sqrt(nc_sum(nc_1,nc_prod(x,x))),x)));\n\t*/\n}\n\nstatic void\nnc_atan@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_diff@c@(&nc_i@c@, x, pa);\n\tnc_sum@c@(&nc_i@c@, x, r);\n\tnc_quot@c@(r, pa, r);\n\tnc_log@c@(r,r);\n\tnc_prod@c@(&nc_i2@c@, r, r);\n\treturn;\n\t/*\n\t return nc_prod(nc_i2,nc_log(nc_quot(nc_sum(nc_i,x),nc_diff(nc_i,x))));\n\t*/\n}\n\nstatic void\nnc_atanh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_diff@c@(&nc_1@c@, x, r);\n\tnc_sum@c@(&nc_1@c@, x, pa);\n\tnc_quot@c@(pa, r, r);\n\tnc_log@c@(r, r);\n\tnc_prod@c@(&nc_half@c@, r, r);\n\treturn;\n\t/*\n\t return nc_prod(nc_half,nc_log(nc_quot(nc_sum(nc_1,x),nc_diff(nc_1,x))));\n\t*/\n}\n\nstatic void\nnc_cos@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos@c@(xr)*cosh@c@(xi);\n\tr->imag = -sin@c@(xr)*sinh@c@(xi);\n\treturn;\n}\n\nstatic void\nnc_cosh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos(xi)*cosh(xr);\n\tr->imag = sin(xi)*sinh(xr);\n\treturn;\n}\n\n\n#define M_LOG10_E 0.434294481903251827651128918916605082294397\n\nstatic void\nnc_log10@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_log@c@(x, r);\n\tr->real *= M_LOG10_E;\n\tr->imag *= M_LOG10_E;\n\treturn;\n}\n\nstatic void\nnc_sin@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = sin@c@(xr)*cosh@c@(xi);\n\tr->imag = cos@c@(xr)*sinh@c@(xi);\n\treturn;\n}\n\nstatic void\nnc_sinh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos@c@(xi)*sinh@c@(xr);\n\tr->imag = sin@c@(xi)*cosh@c@(xr);\n\treturn;\n}\n\nstatic void\nnc_tan@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ sr,cr,shi,chi;\n\t@typ@ rs,is,rc,ic;\n\t@typ@ d;\n\t@typ@ xr=x->real, xi=x->imag;\n\tsr = sin@c@(xr);\n\tcr = cos@c@(xr);\n\tshi = sinh(xi);\n\tchi = cosh(xi);\n\trs = sr*chi;\n\tis = cr*shi;\n\trc = cr*chi;\n\tic = -sr*shi;\n\td = rc*rc + ic*ic;\n\tr->real = (rs*rc+is*ic)/d;\n\tr->imag = (is*rc-rs*ic)/d;\n\treturn;\n}\n\nstatic void\nnc_tanh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ si,ci,shr,chr;\n\t@typ@ rs,is,rc,ic;\n\t@typ@ d;\n\t@typ@ xr=x->real, xi=x->imag;\n\tsi = sin@c@(xi);\n\tci = cos@c@(xi);\n\tshr = sinh@c@(xr);\n\tchr = cosh@c@(xr);\n\trs = ci*shr;\n\tis = si*chr;\n\trc = ci*chr;\n\tic = si*shr;\n\td = rc*rc + ic*ic;\n\tr->real = (rs*rc+is*ic)/d;\n\tr->imag = (is*rc-rs*ic)/d;\n\treturn;\n}\n\n/**end repeat**/\n\n\n/**begin repeat\n\n#TYPE=(BOOL, BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#\n#OP=||, +*13, ^, -*13#\n#kind=add*14, subtract*14#\n#typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n\t/* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>32) || (y>>32) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>64) || (y>>64) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n\treturn 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n\tulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n\tif (a0 < 0) { a = -a0; } else { a = a0; }\n\tif (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n\tah = (a >> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n /*\n\t ulonglong c = ((x + y)<<32) + w;\n\t if ((a0 < 0) ^ (b0 < 0))\n\t *c = -c;\n\t else\n\t *c = c\n\t */\n\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>31) || (y>>31) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>63) || (y>>63) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n\treturn 0;\n#endif\n}\n\n/** end direct numarray code **/\n\nstatic void\nBOOL_multiply(char **args, intp *dimensions, intp *steps, void *func) {\n\tregister intp i;\n\tintp is1=steps[0], is2=steps[1], os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nULONGLONG_multiply(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0], is2=steps[1], os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tulonglong temp;\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\telse if (temp < MIN_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nLONGLONG_multiply(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0], is2=steps[1], os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tlonglong temp;\n\tfor (i=0; ireal;\n xi = x->imag;\n y->real = xr*xr - xi*xi;\n y->imag = 2*xr*xi;\n }\n}\n/**end repeat**/\n\nstatic PyObject *\nPy_square(PyObject *o)\n{\n return PyNumber_Multiply(o, o);\n}\n\n\n/**begin repeat\n#TYP=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#typ=char, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n*/\nstatic void\n@TYP@_reciprocal(char **args, intp *dimensions, intp *steps, void *data)\n{\n intp i, is1 = steps[0], os = steps[1], n = dimensions[0];\n char *i1 = args[0], *op = args[1];\n\n for (i = 0; i < n; i++, i1 += is1, op += os) {\n @typ@ x = *((@typ@ *)i1);\n *((@typ@ *)op) = 1.0 / x;\n }\n}\n/**end repeat**/\n\n/**begin repeat\n#TYP=CFLOAT,CDOUBLE,CLONGDOUBLE#\n#typ=float, double, longdouble#\n*/\nstatic void\n@TYP@_reciprocal(char **args, intp *dimensions, intp *steps, void *data)\n{\n intp i, is1 = steps[0], os = steps[1], n = dimensions[0];\n char *i1 = args[0], *op = args[1];\n c@typ@ *x, *y;\n @typ@ xr, xi, r, denom;\n\n for (i = 0; i < n; i++, i1 += is1, op += os) {\n x = (c@typ@ *)i1;\n y = (c@typ@ *)op;\n xr = x->real;\n xi = x->imag;\n if (fabs(xi) <= fabs(xr)) {\n r = xi / xr;\n denom = xr + xi * r;\n y->real = 1 / denom;\n y->imag = -r / denom;\n } else {\n r = xr / xi;\n denom = xr * r + xi;\n y->real = r / denom;\n y->imag = -1 / denom;\n }\n }\n}\n/**end repeat**/\n\n\n\nstatic PyObject *\nPy_reciprocal(PyObject *o)\n{\n PyObject *one, *result;\n one = PyInt_FromLong(1);\n if (!one) return NULL;\n result = PyNumber_Divide(one, o);\n Py_DECREF(one);\n return result;\n}\n\n/* ones_like is defined here because it's used for x**0 */\n\n/**begin repeat\n#TYP=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#typ=char, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n*/\nstatic void\n@TYP@_ones_like(char **args, intp *dimensions, intp *steps, void *data)\n{\n intp i, os = steps[1], n = dimensions[0];\n char *op = args[1];\n\n for (i = 0; i < n; i++, op += os) {\n *((@typ@ *)op) = 1;\n }\n}\n/**end repeat**/\n\n/**begin repeat\n#TYP=CFLOAT,CDOUBLE,CLONGDOUBLE#\n#typ=float, double, longdouble#\n*/\nstatic void\n@TYP@_ones_like(char **args, intp *dimensions, intp *steps, void *data)\n{\n intp i, is1 = steps[0], os = steps[1], n = dimensions[0];\n char *i1 = args[0], *op = args[1];\n c@typ@ *x, *y;\n @typ@ xr, xi, xmag2;\n \n for (i = 0; i < n; i++, i1 += is1, op += os) {\n x = (c@typ@ *)i1;\n y = (c@typ@ *)op;\n xr = x->real;\n xi = x->imag;\n xmag2 = xr*xr + xi*xi;\n y->real = 1.0;\n y->imag = 0.0;\n }\n}\n/**end repeat**/\n\nstatic PyObject *\nPy_get_one(PyObject *o)\n{\n return PyInt_FromLong(1);\n}\n\n\n/**begin repeat\n#TYP=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n#typ=char, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n#btyp=float*4, double*6#\n*/\nstatic void\n@TYP@_power(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i, is1=steps[0],is2=steps[1];\n\tregister intp os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\t@btyp@ x, y, v;\n @typ@ z;\n\n\tfor(i=0; i, >=, <, <=, ==, !=, &&, ||, &, |, ^#\n**/\nstatic void\nBOOL_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tBool in1, in2;\n\tfor(i=0; i*13, >=*13, <*13, <=*13#\n#typ=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*4#\n#kind= greater*13, greater_equal*13, less*13, less_equal*13#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, >=*3, <*3, <=*3#\n#typ=(cfloat, cdouble, clongdouble)*4#\n#kind= greater*3, greater_equal*3, less*3, less_equal*3#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; ireal == ((@typ@ *)i2)->real)\n\t\t\t*((Bool *)op)=((@typ@ *)i1)->imag @OP@ \\\n\t\t\t\t((@typ@ *)i2)->imag;\n\t\telse\n\t\t\t*((Bool *)op)=((@typ@ *)i1)->real @OP@ \\\n\t\t\t\t((@typ@ *)i2)->real;\n\t}\n}\n/**end repeat**/\n\n\n/**begin repeat\n#TYPE=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*4#\n#typ=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*4#\n#OP= ==*13, !=*13, &&*13, ||*13#\n#kind=equal*13, not_equal*13, logical_and*13, logical_or*13#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i 0 ? 1 : ((x) < 0 ? -1 : 0))\n#define _SIGN2(x) ((x) == 0 ? 0 : 1)\n#define _SIGNC(x) (((x).real > 0) ? 1 : ((x).real < 0 ? -1 : ((x).imag > 0 ? 1 : ((x).imag < 0) ? -1 : 0)))\n/**begin repeat\n#TYPE=BYTE,SHORT,INT,LONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE,UBYTE,USHORT,UINT,ULONG,ULONGLONG#\n#typ=byte,short,int,long,longlong,float,double,longdouble,ubyte,ushort,uint,ulong,ulonglong#\n#func=_SIGN1*8,_SIGN2*5#\n */\nstatic void\n@TYPE@_sign(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],os=steps[1], n=dimensions[0];\n\tchar *i1=args[0], *op=args[1];\n @typ@ t1;\n\tfor(i=0; ireal ||\t\\\n\t\t\t\t ((@typ@ *)i1)->imag);\n\t}\n}\n/**end repeat**/\n\n\n\n\n/**begin repeat\n#TYPE=BYTE,SHORT,INT,LONG,LONGLONG#\n#typ=byte, short, int, long, longlong#\n#ftyp=float*2,double*2,longdouble*1#\n#c=f*2,,,l*1#\n*/\nstatic void\n@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tregister @typ@ ix,iy, tmp;\n\tfor(i=0; i 0) == (iy > 0)) {\n\t\t\t*((@typ@ *)op) = ix % iy;\n\t\t}\n\t\telse { /* handle mixed case the way Python does */\n\t\t\ttmp = ix % iy;\n\t\t\tif (tmp) tmp += iy;\n\t\t\t*((@typ@ *)op)= tmp;\n\t\t}\n\t}\n}\n/**end repeat**/\n\n/**begin repeat\n#TYPE=UBYTE,USHORT,UINT,ULONG,ULONGLONG#\n#typ=ubyte, ushort, uint, ulong, ulonglong#\n*/\nstatic void\n@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tregister @typ@ ix,iy;\n\tfor(i=0; i>*10#\n#kind=bitwise_and*10, bitwise_or*10, bitwise_xor*10, left_shift*10, right_shift*10#\n\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tregister char *i1=args[0], *i2=args[1], *op=args[2];\n\tif (is1 == 0) {\n\t\tregister @typ@ t1 = *((@typ@ *)i1);\n\t\tfor (i=0; ireal || ((@typ@ *)i1)->imag;\n\t\tp2 = ((@typ@ *)i2)->real || ((@typ@ *)i2)->imag;\n\t\t*((Bool *)op)= (p1 || p2) && !(p1 && p2);\n\t}\n}\n/**end repeat**/\n\n\n\n/**begin repeat\n\n#TYPE=(BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#\n#OP= >*14, <*14#\n#typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#\n#kind= maximum*14, minimum*14#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, <*3#\n#typ=(cfloat, cdouble, clongdouble)*2#\n#kind= maximum*3, minimum*3#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n @typ@ *i1c, *i2c;\n\tfor(i=0; ireal @OP@ i2c->real) || \\\n ((i1c->real==i2c->real) && (i1c->imag @OP@ i2c->imag)))\n memcpy(op, i1, sizeof(@typ@));\n else\n memcpy(op, i2, sizeof(@typ@));\n\t}\n}\n/**end repeat**/\n\n\n\n/*** isinf, isinf, isfinite, signbit ***/\n/**begin repeat\n#kind=isnan*3, isinf*3, isfinite*3, signbit*3#\n#TYPE=(FLOAT, DOUBLE, LONGDOUBLE)*4#\n#typ=(float, double, longdouble)*4#\n#c=(f,,l)*4#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n register intp i;\n intp is=steps[0], os=steps[1], n=dimensions[0];\n char *ip=args[0], *op=args[1];\n for(i=0; i\n\n/* A whole slew of basic math functions are provided originally\n by Konrad Hinsen. */\n\n#if !defined(__STDC__) && !defined(_MSC_VER)\nextern double fmod (double, double);\nextern double frexp (double, int *);\nextern double ldexp (double, int);\nextern double modf (double, double *);\n#endif\n#ifndef M_PI\n#define M_PI 3.14159265358979323846264338328\n#endif\n\n\n#ifndef HAVE_INVERSE_HYPERBOLIC\nstatic double acosh(double x)\n{\n\treturn 2*log(sqrt((x+1.0)/2)+sqrt((x-1.0)/2));\n}\n\ndouble log1p(double);\nstatic double asinh(double xx)\n{\n\tdouble x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e8) {\n\t\td = x;\n\t} else {\n\t\td = sqrt(x*x + 1);\n\t}\n\treturn sign*log1p(x*(1.0 + x/(d+1)));\n}\n\nstatic double atanh(double x)\n{\n\treturn 0.5*log1p(2.0*x/(1.0-x));\n}\n#endif\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC_FLOAT)\n#ifdef HAVE_FLOAT_FUNCS\n#ifdef log1pf\n#undef log1pf\n#endif\n#ifdef logf\n#undef logf\n#endif\n#ifdef sqrtf\n#undef sqrtf\n#endif\nfloat log1pf(float);\nfloat logf(float);\nfloat sqrtf(float);\n#ifdef acoshf\n#undef acoshf\n#endif\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\n#ifdef asinhf\n#undef asinhf\n#endif\nstatic float asinhf(float xx)\n{\n\tfloat x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e5) {\n\t\td = x;\n\t} else {\n\t\td = sqrtf(x*x + 1);\n\t}\n\treturn sign*log1pf(x*(1.0 + x/(d+1)));\n}\n\n#ifdef atanhf\n#undef atanhf\n#endif\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\n#ifdef acoshf\n#undef acoshf\n#endif\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\n#ifdef asinhf\n#undef asinhf\n#endif\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\n#ifdef atanhf\n#undef atanhf\n#endif\nstatic float atanhf(float x)\n{\n return (float)atanh((double)(x));\n}\n#endif\n#endif\n\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE)\n#ifdef HAVE_LONGDOUBLE_FUNCS\n#ifdef logl\n#undef logl\n#endif\n#ifdef sqrtl\n#undef sqrtl\n#endif\n#ifdef log1pl\n#undef log1pl\n#endif\nlongdouble logl(longdouble);\nlongdouble sqrtl(longdouble);\nlongdouble log1pl(longdouble);\n#ifdef acoshl\n#undef acoshl\n#endif\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\n#ifdef asinhl\n#undef asinhl\n#endif\nstatic longdouble asinhl(longdouble xx)\n{\n\tlongdouble x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e17) {\n\t\td = x;\n\t} else {\n\t\td = sqrtl(x*x + 1);\n\t}\n\treturn sign*log1pl(x*(1.0 + x/(d+1)));\n}\n\n#ifdef atanhl\n#undef atanhl\n#endif\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n\n#else\n\n#ifdef acoshl\n#undef acoshl\n#endif\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\n#ifdef asinhl\n#undef asinhl\n#endif\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\n#ifdef atanhl\n#undef atanhl\n#endif\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\n}\n\n#endif\n#endif\n\n\n#ifdef HAVE_HYPOT\n#if !defined(NeXT) && !defined(_MSC_VER)\nextern double hypot(double, double);\n#endif\n#else\nstatic double hypot(double x, double y)\n{\n\tdouble yx;\n\n\tx = fabs(x);\n\ty = fabs(y);\n\tif (x < y) {\n\t\tdouble temp = x;\n\t\tx = y;\n\t\ty = temp;\n\t}\n\tif (x == 0.)\n\t\treturn 0.;\n\telse {\n\t\tyx = y/x;\n\t\treturn x*sqrt(1.+yx*yx);\n\t}\n}\n#endif\n\n\n#ifndef HAVE_RINT\nstatic double \nrint (double x)\n{\n\tdouble y, r;\n\t\n\ty = floor(x);\n\tr = x - y;\n\t\n\tif (r > 0.5) goto rndup;\n\n\t/* Round to nearest even */\n\tif (r==0.5) {\n\t\tr = y - 2.0*floor(0.5*y);\n\t\tif (r==1.0) {\n\t\trndup:\t \n\t\t\ty+=1.0;\n\t\t}\n\t}\n\treturn y;\n}\n#endif\n\n\n\n/* Define isnan, isinf, isfinite, signbit if needed */\n/* Use fpclassify if possible */\n/* isnan, isinf --\n these will use macros and then fpclassify if available before\n defaulting to a dumb convert-to-double version...\n\n isfinite -- define a macro if not already available\n signbit -- if macro available use it, otherwise define a function\n and a dumb convert-to-double version for other types.\n*/\n\n#if defined(fpclassify)\n\n#if !defined(isnan)\n#define isnan(x) (fpclassify(x) == FP_NAN)\n#endif\n#if !defined(isinf)\n#define isinf(x) (fpclassify(x) == FP_INFINITE)\n#endif\n\n#else /* check to see if already have a function like this */\n\n#if !defined(HAVE_ISNAN)\n\n#if !defined(isnan)\n#include \"_isnan.c\"\n#endif\n#endif /* HAVE_ISNAN */\n\n#if !defined(HAVE_ISINF)\n#if !defined(isinf)\n#define isinf(x) (!isnan((x)) && isnan((x)-(x)))\n#endif\n#endif /* HAVE_ISINF */\n\n#endif /* defined(fpclassify) */\n\n\n/* Define signbit if needed */\n#if !defined(signbit)\n#include \"_signbit.c\"\n#endif\n\n/* Now defined the extended type macros */\n\n#if !defined(isnan)\n\n#if !defined(HAVE_LONGDOUBLE_FUNCS) || !defined(HAVE_ISNAN)\n#define isnanl(x) isnan((double)(x))\n#endif\n\n#if !defined(HAVE_FLOAT_FUNCS) || !defined(HAVE_ISNAN)\n#define isnanf(x) isnan((double)(x))\n#endif\n\n#else /* !defined(isnan) */\n\n#define isnanl(x) isnan((x))\n#define isnanf(x) isnan((x))\n\n#endif /* !defined(isnan) */\n\n\n#if !defined(isinf)\n\n#if !defined(HAVE_LONGDOUBLE_FUNCS) || !defined(HAVE_ISINF)\n#define isinfl(x) (!isnanl((x)) && isnanl((x)-(x)))\n#endif\n\n#if !defined(HAVE_FLOAT_FUNCS) || !defined(HAVE_ISINF)\n#define isinff(x) (!isnanf((x)) && isnanf((x)-(x)))\n#endif\n\n#else /* !defined(isinf) */\n\n#define isinfl(x) isinf((x))\n#define isinff(x) isinf((x))\n\n#endif /* !defined(isinf) */\n\n\n#if !defined(signbit)\n#define signbitl(x) ((longdouble) signbit((double)(x)))\n#define signbitf(x) ((float) signbit((double) (x)))\n#else\n#define signbitl(x) signbit((x))\n#define signbitf(x) signbit((x))\n#endif\n\n#if !defined(isfinite)\n#define isfinite(x) (!(isinf((x)) || isnan((x))))\n#endif\n#define isfinitef(x) (!(isinff((x)) || isnanf((x))))\n#define isfinitel(x) (!(isinfl((x)) || isnanl((x))))\n\n\n/* First, the C functions that do the real work */\n\n/* if C99 extensions not available then define dummy functions that use the\n double versions for\n\n sin, cos, tan\n sinh, cosh, tanh,\n fabs, floor, ceil, fmod, sqrt, log10, log, exp, fabs\n asin, acos, atan,\n asinh, acosh, atanh\n\n hypot, atan2, pow\n*/\n\n/**begin repeat\n\n#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan,rint)*2#\n#typ=longdouble*17, float*17#\n#c=l*17,f*17#\n#TYPE=LONGDOUBLE*17, FLOAT*17#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef @kind@@c@\n#undef @kind@@c@\n#endif\n@typ@ @kind@@c@(@typ@ x) {\n\treturn (@typ@) @kind@((double)x);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n\n#kind=(atan2,hypot,pow,fmod)*2#\n#typ=longdouble*4, float*4#\n#c=l*4,f*4#\n#TYPE=LONGDOUBLE*4,FLOAT*4#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef @kind@@c@\n#undef @kind@@c@\n#endif\n@typ@ @kind@@c@(@typ@ x, @typ@ y) {\n\treturn (@typ@) @kind@((double)x, (double) y);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n#kind=modf*2#\n#typ=longdouble, float#\n#c=l,f#\n#TYPE=LONGDOUBLE, FLOAT#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef modf@c@\n#undef modf@c@\n#endif\n@typ@ modf@c@(@typ@ x, @typ@ *iptr) {\n double nx, niptr, y;\n nx = (double) x;\n y = modf(nx, &niptr);\n *iptr = (@typ@) niptr;\n return (@typ@) y;\n}\n#endif\n/**end repeat**/\n\n\n\n#ifndef HAVE_LOG1P\ndouble log1p(double x)\n{\n\tdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn log(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_LONGDOUBLE_FUNCS)\n#ifdef log1pl\n#undef log1pl\n#endif\nlongdouble log1pl(longdouble x)\n{\n\tlongdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logl(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_FLOAT_FUNCS)\n#ifdef log1pf\n#undef log1pf\n#endif\nfloat log1pf(float x)\n{\n\tfloat u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logf(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#ifndef HAVE_EXPM1\nstatic double expm1(double x)\n{\n\tdouble u = exp(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/log(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_LONGDOUBLE_FUNCS)\n#ifdef expml1\n#undef expml1\n#endif\nstatic longdouble expm1l(longdouble x)\n{\n\tlongdouble u = expl(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logl(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_FLOAT_FUNCS)\n#ifdef expm1f\n#undef expm1f\n#endif\nstatic float expm1f(float x)\n{\n\tfloat u = expf(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logf(u);\n\t}\n}\n#endif\n\n\n\n\n/* Don't pass structures between functions (only pointers) because how\n structures are passed is compiler dependent and could cause\n segfaults if ufuncobject.c is compiled with a different compiler\n than an extension that makes use of the UFUNC API\n*/\n\n/**begin repeat\n\n#typ=float, double, longdouble#\n#c=f,,l#\n*/\n\n/* constants */\nstatic c@typ@ nc_1@c@ = {1., 0.};\nstatic c@typ@ nc_half@c@ = {0.5, 0.};\nstatic c@typ@ nc_i@c@ = {0., 1.};\nstatic c@typ@ nc_i2@c@ = {0., 0.5};\n/*\nstatic c@typ@ nc_mi@c@ = {0., -1.};\nstatic c@typ@ nc_pi2@c@ = {M_PI/2., 0.};\n*/\n\nstatic void\nnc_sum@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real + b->real;\n\tr->imag = a->imag + b->imag;\n\treturn;\n}\n\nstatic void\nnc_diff@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real - b->real;\n\tr->imag = a->imag - b->imag;\n\treturn;\n}\n\nstatic void\nnc_neg@c@(c@typ@ *a, c@typ@ *r)\n{\n\tr->real = -a->real;\n\tr->imag = -a->imag;\n\treturn;\n}\n\nstatic void\nnc_prod@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\tr->real = ar*br - ai*bi;\n\tr->imag = ar*bi + ai*br;\n\treturn;\n}\n\nstatic void\nnc_quot@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\n\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@typ@ d = br*br + bi*bi;\n\tr->real = (ar*br + ai*bi)/d;\n\tr->imag = (ai*br - ar*bi)/d;\n\treturn;\n}\n\nstatic void\nnc_floor_quot@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@typ@ d = br*br + bi*bi;\n\tr->real = floor@c@((ar*br + ai*bi)/d);\n\tr->imag = 0;\n\treturn;\n}\n\nstatic void\nnc_sqrt@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ s,d;\n\tif (x->real == 0. && x->imag == 0.)\n\t\t*r = *x;\n\telse {\n\t\ts = sqrt@c@(0.5*(fabs@c@(x->real) + hypot@c@(x->real,x->imag)));\n\t\td = 0.5*x->imag/s;\n\t\tif (x->real > 0.) {\n\t\t\tr->real = s;\n\t\t\tr->imag = d;\n\t\t}\n\t\telse if (x->imag >= 0.) {\n\t\t\tr->real = d;\n\t\t\tr->imag = s;\n\t\t}\n\t\telse {\n\t\t\tr->real = -d;\n\t\t\tr->imag = -s;\n\t\t}\n\t}\n\treturn;\n}\n\nstatic void\nnc_log@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ l = hypot@c@(x->real,x->imag);\n\tr->imag = atan2@c@(x->imag, x->real);\n\tr->real = log@c@(l);\n\treturn;\n}\n\nstatic void\nnc_log1p@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ l = hypot@c@(x->real + 1.0,x->imag);\n\tr->imag = atan2@c@(x->imag, x->real + 1.0);\n\tr->real = log@c@(l);\n\treturn;\n}\n\nstatic void\nnc_exp@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ a = exp@c@(x->real);\n\tr->real = a*cos@c@(x->imag);\n\tr->imag = a*sin@c@(x->imag);\n\treturn;\n}\n\nstatic void\nnc_expm1@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ a = exp@c@(x->real);\n\tr->real = a*cos@c@(x->imag) - 1.0;\n\tr->imag = a*sin@c@(x->imag);\n\treturn;\n}\n\nstatic void\nnc_pow@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n intp n;\n @typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\n\tif (br == 0. && bi == 0.) {\n\t\tr->real = 1.;\n\t\tr->imag = 0.;\n return;\n\t}\n\tif (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n return;\n\t}\n if (bi == 0 && (n=(intp)br) == br) {\n if (n > -100 && n < 100) {\n c@typ@ p, aa;\n intp mask = 1;\n if (n < 0) n = -n;\n aa = nc_1@c@;\n p.real = ar; p.imag = ai;\n while (1) {\n if (n & mask)\n nc_prod@c@(&aa,&p,&aa);\n mask <<= 1;\n if (n < mask || mask <= 0) break;\n nc_prod@c@(&p,&p,&p);\n }\n r->real = aa.real; r->imag = aa.imag;\n if (br < 0) nc_quot@c@(&nc_1@c@, r, r);\n return;\n }\n }\n /* complexobect.c uses an inline version of this formula\n investigate whether this had better performance or accuracy */\n nc_log@c@(a, r);\n nc_prod@c@(r, b, r);\n nc_exp@c@(r, r);\n return;\n}\n\n\nstatic void\nnc_prodi@c@(c@typ@ *x, c@typ@ *r)\n{\n\tr->real = -x->imag;\n\tr->imag = x->real;\n\treturn;\n}\n\n\nstatic void\nnc_acos@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x,x,r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_sum@c@(x, r, r);\n\tnc_log@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/* return nc_neg(nc_prodi(nc_log(nc_sum(x,nc_prod(nc_i,\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x))))))));\n\t*/\n}\n\nstatic void\nnc_acosh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x, x, r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_sum@c@(x, r, r);\n\tnc_log@c@(r, r);\n\treturn;\n\t/*\n\t return nc_log(nc_sum(x,nc_prod(nc_i,\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x))))));\n\t*/\n}\n\nstatic void\nnc_asin@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_prod@c@(x, x, r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(x, pa);\n\tnc_sum@c@(pa, r, r);\n\tnc_log@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/*\n\t return nc_neg(nc_prodi(nc_log(nc_sum(nc_prod(nc_i,x),\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x)))))));\n\t*/\n}\n\n\nstatic void\nnc_asinh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x, x, r);\n\tnc_sum@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_diff@c@(r, x, r);\n\tnc_log@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/*\n\t return nc_neg(nc_log(nc_diff(nc_sqrt(nc_sum(nc_1,nc_prod(x,x))),x)));\n\t*/\n}\n\nstatic void\nnc_atan@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_diff@c@(&nc_i@c@, x, pa);\n\tnc_sum@c@(&nc_i@c@, x, r);\n\tnc_quot@c@(r, pa, r);\n\tnc_log@c@(r,r);\n\tnc_prod@c@(&nc_i2@c@, r, r);\n\treturn;\n\t/*\n\t return nc_prod(nc_i2,nc_log(nc_quot(nc_sum(nc_i,x),nc_diff(nc_i,x))));\n\t*/\n}\n\nstatic void\nnc_atanh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_diff@c@(&nc_1@c@, x, r);\n\tnc_sum@c@(&nc_1@c@, x, pa);\n\tnc_quot@c@(pa, r, r);\n\tnc_log@c@(r, r);\n\tnc_prod@c@(&nc_half@c@, r, r);\n\treturn;\n\t/*\n\t return nc_prod(nc_half,nc_log(nc_quot(nc_sum(nc_1,x),nc_diff(nc_1,x))));\n\t*/\n}\n\nstatic void\nnc_cos@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos@c@(xr)*cosh@c@(xi);\n\tr->imag = -sin@c@(xr)*sinh@c@(xi);\n\treturn;\n}\n\nstatic void\nnc_cosh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos(xi)*cosh(xr);\n\tr->imag = sin(xi)*sinh(xr);\n\treturn;\n}\n\n\n#define M_LOG10_E 0.434294481903251827651128918916605082294397\n\nstatic void\nnc_log10@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_log@c@(x, r);\n\tr->real *= M_LOG10_E;\n\tr->imag *= M_LOG10_E;\n\treturn;\n}\n\nstatic void\nnc_sin@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = sin@c@(xr)*cosh@c@(xi);\n\tr->imag = cos@c@(xr)*sinh@c@(xi);\n\treturn;\n}\n\nstatic void\nnc_sinh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos@c@(xi)*sinh@c@(xr);\n\tr->imag = sin@c@(xi)*cosh@c@(xr);\n\treturn;\n}\n\nstatic void\nnc_tan@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ sr,cr,shi,chi;\n\t@typ@ rs,is,rc,ic;\n\t@typ@ d;\n\t@typ@ xr=x->real, xi=x->imag;\n\tsr = sin@c@(xr);\n\tcr = cos@c@(xr);\n\tshi = sinh(xi);\n\tchi = cosh(xi);\n\trs = sr*chi;\n\tis = cr*shi;\n\trc = cr*chi;\n\tic = -sr*shi;\n\td = rc*rc + ic*ic;\n\tr->real = (rs*rc+is*ic)/d;\n\tr->imag = (is*rc-rs*ic)/d;\n\treturn;\n}\n\nstatic void\nnc_tanh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ si,ci,shr,chr;\n\t@typ@ rs,is,rc,ic;\n\t@typ@ d;\n\t@typ@ xr=x->real, xi=x->imag;\n\tsi = sin@c@(xi);\n\tci = cos@c@(xi);\n\tshr = sinh@c@(xr);\n\tchr = cosh@c@(xr);\n\trs = ci*shr;\n\tis = si*chr;\n\trc = ci*chr;\n\tic = si*shr;\n\td = rc*rc + ic*ic;\n\tr->real = (rs*rc+is*ic)/d;\n\tr->imag = (is*rc-rs*ic)/d;\n\treturn;\n}\n\n/**end repeat**/\n\n\n/**begin repeat\n\n#TYPE=(BOOL, BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#\n#OP=||, +*13, ^, -*13#\n#kind=add*14, subtract*14#\n#typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n\t/* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>32) || (y>>32) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>64) || (y>>64) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n\treturn 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n\tulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n\tif (a0 < 0) { a = -a0; } else { a = a0; }\n\tif (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n\tah = (a >> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n /*\n\t ulonglong c = ((x + y)<<32) + w;\n\t if ((a0 < 0) ^ (b0 < 0))\n\t *c = -c;\n\t else\n\t *c = c\n\t */\n\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>31) || (y>>31) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>63) || (y>>63) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n\treturn 0;\n#endif\n}\n\n/** end direct numarray code **/\n\nstatic void\nBOOL_multiply(char **args, intp *dimensions, intp *steps, void *func) {\n\tregister intp i;\n\tintp is1=steps[0], is2=steps[1], os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nULONGLONG_multiply(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0], is2=steps[1], os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tulonglong temp;\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\telse if (temp < MIN_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nLONGLONG_multiply(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0], is2=steps[1], os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tlonglong temp;\n\tfor (i=0; ireal;\n xi = x->imag;\n y->real = xr*xr - xi*xi;\n y->imag = 2*xr*xi;\n }\n}\n/**end repeat**/\n\nstatic PyObject *\nPy_square(PyObject *o)\n{\n return PyNumber_Multiply(o, o);\n}\n\n\n/**begin repeat\n#TYP=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#typ=char, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n*/\nstatic void\n@TYP@_reciprocal(char **args, intp *dimensions, intp *steps, void *data)\n{\n intp i, is1 = steps[0], os = steps[1], n = dimensions[0];\n char *i1 = args[0], *op = args[1];\n\n for (i = 0; i < n; i++, i1 += is1, op += os) {\n @typ@ x = *((@typ@ *)i1);\n *((@typ@ *)op) = 1.0 / x;\n }\n}\n/**end repeat**/\n\n/**begin repeat\n#TYP=CFLOAT,CDOUBLE,CLONGDOUBLE#\n#typ=float, double, longdouble#\n*/\nstatic void\n@TYP@_reciprocal(char **args, intp *dimensions, intp *steps, void *data)\n{\n intp i, is1 = steps[0], os = steps[1], n = dimensions[0];\n char *i1 = args[0], *op = args[1];\n c@typ@ *x, *y;\n @typ@ xr, xi, r, denom;\n\n for (i = 0; i < n; i++, i1 += is1, op += os) {\n x = (c@typ@ *)i1;\n y = (c@typ@ *)op;\n xr = x->real;\n xi = x->imag;\n if (fabs(xi) <= fabs(xr)) {\n r = xi / xr;\n denom = xr + xi * r;\n y->real = 1 / denom;\n y->imag = -r / denom;\n } else {\n r = xr / xi;\n denom = xr * r + xi;\n y->real = r / denom;\n y->imag = -1 / denom;\n }\n }\n}\n/**end repeat**/\n\n\n\nstatic PyObject *\nPy_reciprocal(PyObject *o)\n{\n PyObject *one, *result;\n one = PyInt_FromLong(1);\n if (!one) return NULL;\n result = PyNumber_Divide(one, o);\n Py_DECREF(one);\n return result;\n}\n\n/* ones_like is defined here because it's used for x**0 */\n\n/**begin repeat\n#TYP=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#typ=char, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n*/\nstatic void\n@TYP@_ones_like(char **args, intp *dimensions, intp *steps, void *data)\n{\n intp i, os = steps[1], n = dimensions[0];\n char *op = args[1];\n\n for (i = 0; i < n; i++, op += os) {\n *((@typ@ *)op) = 1;\n }\n}\n/**end repeat**/\n\n/**begin repeat\n#TYP=CFLOAT,CDOUBLE,CLONGDOUBLE#\n#typ=float, double, longdouble#\n*/\nstatic void\n@TYP@_ones_like(char **args, intp *dimensions, intp *steps, void *data)\n{\n intp i, is1 = steps[0], os = steps[1], n = dimensions[0];\n char *i1 = args[0], *op = args[1];\n c@typ@ *x, *y;\n @typ@ xr, xi, xmag2;\n\n for (i = 0; i < n; i++, i1 += is1, op += os) {\n x = (c@typ@ *)i1;\n y = (c@typ@ *)op;\n xr = x->real;\n xi = x->imag;\n xmag2 = xr*xr + xi*xi;\n y->real = 1.0;\n y->imag = 0.0;\n }\n}\n/**end repeat**/\n\n\nstatic PyObject *\nPy_get_one(PyObject *o)\n{\n return PyInt_FromLong(1.0);\n}\n\n/**begin repeat\n\n/**begin repeat\n\n#TYP=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n#typ=char, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n#btyp=float*4, double*6#\n*/\nstatic void\n@TYP@_power(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i, is1=steps[0],is2=steps[1];\n\tregister intp os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\t@btyp@ x, y, v;\n @typ@ z;\n\n\tfor(i=0; i, >=, <, <=, ==, !=, &&, ||, &, |, ^#\n**/\nstatic void\nBOOL_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tBool in1, in2;\n\tfor(i=0; i*13, >=*13, <*13, <=*13#\n#typ=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*4#\n#kind= greater*13, greater_equal*13, less*13, less_equal*13#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, >=*3, <*3, <=*3#\n#typ=(cfloat, cdouble, clongdouble)*4#\n#kind= greater*3, greater_equal*3, less*3, less_equal*3#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; ireal == ((@typ@ *)i2)->real)\n\t\t\t*((Bool *)op)=((@typ@ *)i1)->imag @OP@ \\\n\t\t\t\t((@typ@ *)i2)->imag;\n\t\telse\n\t\t\t*((Bool *)op)=((@typ@ *)i1)->real @OP@ \\\n\t\t\t\t((@typ@ *)i2)->real;\n\t}\n}\n/**end repeat**/\n\n\n/**begin repeat\n#TYPE=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*4#\n#typ=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*4#\n#OP= ==*13, !=*13, &&*13, ||*13#\n#kind=equal*13, not_equal*13, logical_and*13, logical_or*13#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i 0 ? 1 : ((x) < 0 ? -1 : 0))\n#define _SIGN2(x) ((x) == 0 ? 0 : 1)\n#define _SIGNC(x) (((x).real > 0) ? 1 : ((x).real < 0 ? -1 : ((x).imag > 0 ? 1 : ((x).imag < 0) ? -1 : 0)))\n/**begin repeat\n#TYPE=BYTE,SHORT,INT,LONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE,UBYTE,USHORT,UINT,ULONG,ULONGLONG#\n#typ=byte,short,int,long,longlong,float,double,longdouble,ubyte,ushort,uint,ulong,ulonglong#\n#func=_SIGN1*8,_SIGN2*5#\n */\nstatic void\n@TYPE@_sign(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],os=steps[1], n=dimensions[0];\n\tchar *i1=args[0], *op=args[1];\n @typ@ t1;\n\tfor(i=0; ireal ||\t\\\n\t\t\t\t ((@typ@ *)i1)->imag);\n\t}\n}\n/**end repeat**/\n\n\n\n\n/**begin repeat\n#TYPE=BYTE,SHORT,INT,LONG,LONGLONG#\n#typ=byte, short, int, long, longlong#\n#ftyp=float*2,double*2,longdouble*1#\n#c=f*2,,,l*1#\n*/\nstatic void\n@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tregister @typ@ ix,iy, tmp;\n\tfor(i=0; i 0) == (iy > 0)) {\n\t\t\t*((@typ@ *)op) = ix % iy;\n\t\t}\n\t\telse { /* handle mixed case the way Python does */\n\t\t\ttmp = ix % iy;\n\t\t\tif (tmp) tmp += iy;\n\t\t\t*((@typ@ *)op)= tmp;\n\t\t}\n\t}\n}\n/**end repeat**/\n\n/**begin repeat\n#TYPE=UBYTE,USHORT,UINT,ULONG,ULONGLONG#\n#typ=ubyte, ushort, uint, ulong, ulonglong#\n*/\nstatic void\n@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tregister @typ@ ix,iy;\n\tfor(i=0; i>*10#\n#kind=bitwise_and*10, bitwise_or*10, bitwise_xor*10, left_shift*10, right_shift*10#\n\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tregister char *i1=args[0], *i2=args[1], *op=args[2];\n\tif (is1 == 0) {\n\t\tregister @typ@ t1 = *((@typ@ *)i1);\n\t\tfor (i=0; ireal || ((@typ@ *)i1)->imag;\n\t\tp2 = ((@typ@ *)i2)->real || ((@typ@ *)i2)->imag;\n\t\t*((Bool *)op)= (p1 || p2) && !(p1 && p2);\n\t}\n}\n/**end repeat**/\n\n\n\n/**begin repeat\n\n#TYPE=(BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#\n#OP= >*14, <*14#\n#typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#\n#kind= maximum*14, minimum*14#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, <*3#\n#typ=(cfloat, cdouble, clongdouble)*2#\n#kind= maximum*3, minimum*3#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n @typ@ *i1c, *i2c;\n\tfor(i=0; ireal @OP@ i2c->real) || \\\n ((i1c->real==i2c->real) && (i1c->imag @OP@ i2c->imag)))\n memcpy(op, i1, sizeof(@typ@));\n else\n memcpy(op, i2, sizeof(@typ@));\n\t}\n}\n/**end repeat**/\n\n\n\n/*** isinf, isinf, isfinite, signbit ***/\n/**begin repeat\n#kind=isnan*3, isinf*3, isfinite*3, signbit*3#\n#TYPE=(FLOAT, DOUBLE, LONGDOUBLE)*4#\n#typ=(float, double, longdouble)*4#\n#c=(f,,l)*4#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n register intp i;\n intp is=steps[0], os=steps[1], n=dimensions[0];\n char *ip=args[0], *op=args[1];\n for(i=0; ireal;", + " xi = x->imag;", + " xmag2 = xr*xr + xi*xi;", + " y->real = 1.0;", + " y->imag = 0.0;", + " }", + " return PyInt_FromLong(1);" + ], + "deleted": [ + " intp i, is1 = steps[0], os = steps[1], n = dimensions[0];", + " char *i1 = args[0], *op = args[1];", + " c@typ@ *x, *y;", + " @typ@ xr, xi, xmag2;", + "", + " for (i = 0; i < n; i++, i1 += is1, op += os) {", + " x = (c@typ@ *)i1;", + " y = (c@typ@ *)op;", + " xr = x->real;", + " xi = x->imag;", + " xmag2 = xr*xr + xi*xi;", + " y->real = 1.0;", + " y->imag = 0.0;", + " }", + "", + " return PyInt_FromLong(1.0);", + "/**begin repeat", + "", + "" + ] + } + }, + { + "old_path": "numpy/linalg/linalg.py", + "new_path": "numpy/linalg/linalg.py", + "filename": "linalg.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -15,6 +15,7 @@\n ]\n \n from numpy.core import *\n+from numpy.lib import *\n import lapack_lite\n \n # Error object\n@@ -113,7 +114,8 @@ def solve_linear_equations(a, b):\n # Matrix inversion\n \n def inverse(a):\n- return solve_linear_equations(a, identity(a.shape[0]))\n+ a, wrap = _makearray(a)\n+ return wrap(solve_linear_equations(a, identity(a.shape[0])))\n \n \n # Cholesky decomposition\n", + "added_lines": 3, + "deleted_lines": 1, + "source_code": "\n\"\"\"Lite version of scipy.linalg.\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n__all__ = ['LinAlgError', 'solve_linear_equations', 'solve',\n 'inverse', 'inv', 'cholesky_decomposition', 'cholesky', 'eigenvalues',\n 'eigvals', 'Heigenvalues', 'eigvalsh', 'generalized_inverse', 'pinv',\n 'determinant', 'det', 'singular_value_decomposition', 'svd',\n 'eigenvectors', 'eig', 'Heigenvectors', 'eigh','lstsq',\n 'linear_least_squares'\n ]\n\nfrom numpy.core import *\nfrom numpy.lib import *\nimport lapack_lite\n\n# Error object\nclass LinAlgError(Exception):\n pass\n\n# Helper routines\n_lapack_type = {'f': 0, 'd': 1, 'F': 2, 'D': 3}\n_lapack_letter = ['s', 'd', 'c', 'z']\n_array_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\n_array_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\n_array_type = [['f', 'd'], ['F', 'D']]\n\ndef _makearray(a):\n new = asarray(a)\n wrap = getattr(a, \"__array_wrap__\", new.__array_wrap__)\n return new, wrap\n\ndef _commonType(*arrays):\n kind = 0\n# precision = 0\n# force higher precision in lite version\n precision = 1\n for a in arrays:\n t = a.dtype.char\n kind = max(kind, _array_kind[t])\n precision = max(precision, _array_precision[t])\n return _array_type[kind][precision]\n\ndef _castCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n cast_arrays = cast_arrays + (transpose(a).astype(type),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\n# _fastCopyAndTranpose is an optimized version of _castCopyAndTranspose.\n# It assumes the input is 2D (as all the calls in here are).\n\n_fastCT = fastCopyAndTranspose\n\ndef _fastCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.dtype.char == type:\n cast_arrays = cast_arrays + (_fastCT(a),)\n else:\n cast_arrays = cast_arrays + (_fastCT(a.astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\ndef _assertRank2(*arrays):\n for a in arrays:\n if len(a.shape) != 2:\n raise LinAlgError, 'Array must be two-dimensional'\n\ndef _assertSquareness(*arrays):\n for a in arrays:\n if max(a.shape) != min(a.shape):\n raise LinAlgError, 'Array must be square'\n\n\n# Linear equations\n\ndef solve_linear_equations(a, b):\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n _assertSquareness(a)\n n_eq = a.shape[0]\n n_rhs = b.shape[1]\n if n_eq != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n# lapack_routine = _findLapackRoutine('gesv', t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesv\n else:\n lapack_routine = lapack_lite.dgesv\n a, b = _fastCopyAndTranspose(t, a, b)\n pivots = zeros(n_eq, 'i')\n results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Singular matrix'\n if one_eq:\n return ravel(b) # I see no need to copy here\n else:\n return transpose(b) # no need to copy\n\n\n# Matrix inversion\n\ndef inverse(a):\n a, wrap = _makearray(a)\n return wrap(solve_linear_equations(a, identity(a.shape[0])))\n\n\n# Cholesky decomposition\n\ndef cholesky_decomposition(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _castCopyAndTranspose(t, a)\n m = a.shape[0]\n n = a.shape[1]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zpotrf\n else:\n lapack_routine = lapack_lite.dpotrf\n results = lapack_routine('L', n, a, m, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Matrix is not positive definite - Cholesky decomposition cannot be computed'\n return transpose(triu(a,k=0)).copy()\n\n\n# Eigenvalues\n\ndef eigenvalues(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n dummy = zeros((1,), t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n rwork = zeros((n,),real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n else:\n w = wr+1j*wi\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\n\ndef Heigenvalues(a, UPLO='L'):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\ndef _convertarray(a):\n if issubclass(a.dtype.type, complexfloating):\n if a.dtype.char == 'D':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('D'))\n else:\n if a.dtype.char == 'd':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('d'))\n return a, a.dtype.char\n\n# Eigenvectors\n\ndef eig(a):\n \"\"\"eig(a) returns u,v where u is the eigenvalues and\nv is a matrix of eigenvectors with vector v[:,i] corresponds to\neigenvalue u[i]. Satisfies the equation dot(a, v[:,i]) = u[i]*v[:,i]\n\"\"\"\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n a,t = _convertarray(a) # convert to float_ or complex_ type\n real_t = 'd'\n n = a.shape[0]\n dummy = zeros((1,), t)\n if t == 'D': # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n v = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n rwork = zeros((2*n,),real_t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n vr = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n v = vr\n else:\n w = wr+1j*wi\n v = array(vr,Complex)\n ind = nonzero(\n equal(\n equal(wi,0.0) # true for real e-vals\n ,0) # true for complex e-vals\n ) # indices of complex e-vals\n for i in range(len(ind)/2):\n v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]]\n v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]]\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(v.transpose())\n\n\ndef eigh(a, UPLO='L'):\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(a.transpose())\n\n\n# Singular value decomposition\n\ndef svd(a, full_matrices=1):\n a, wrap = _makearray(a)\n _assertRank2(a)\n m, n = a.shape\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n if full_matrices:\n nu = m\n nvt = n\n option = 'A'\n else:\n nu = min(n,m)\n nvt = min(n,m)\n option = 'S'\n s = zeros((min(n,m),), real_t)\n u = zeros((nu, m), t)\n vt = zeros((n, nvt), t)\n iwork = zeros((8*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesdd\n rwork = zeros((5*min(m,n)*min(m,n) + 5*min(m,n),), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, rwork, iwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, rwork, iwork, 0)\n else:\n lapack_routine = lapack_lite.dgesdd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, iwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, iwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge'\n return wrap(transpose(u)), s, \\\n wrap(transpose(vt)) # why copy here?\n\n\n# Generalized inverse\n\ndef generalized_inverse(a, rcond = 1.e-10):\n a, wrap = _makearray(a)\n if a.dtype.char in typecodes['Complex']:\n a = conjugate(a)\n u, s, vt = svd(a, 0)\n m = u.shape[0]\n n = vt.shape[1]\n cutoff = rcond*maximum.reduce(s)\n for i in range(min(n,m)):\n if s[i] > cutoff:\n s[i] = 1./s[i]\n else:\n s[i] = 0.;\n return wrap(dot(transpose(vt),\n multiply(s[:, NewAxis],transpose(u))))\n\n# Determinant\n\ndef determinant(a):\n a = asarray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zgetrf\n else:\n lapack_routine = lapack_lite.dgetrf\n pivots = zeros((n,), 'i')\n results = lapack_routine(n, n, a, n, pivots, 0)\n sign = add.reduce(not_equal(pivots,\n arrayrange(1, n+1))) % 2\n return (1.-2.*sign)*multiply.reduce(diagonal(a),axis=-1)\n\n# Linear Least Squares\n\ndef linear_least_squares(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n import math\n a = asarray(a)\n b, wrap = _makearray(b)\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n m = a.shape[0]\n n = a.shape[1]\n n_rhs = b.shape[1]\n ldb = max(n,m)\n if m != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n real_t = _array_type[0][_array_precision[t]]\n bstar = zeros((ldb,n_rhs),t)\n bstar[:b.shape[0],:n_rhs] = b.copy()\n a,bstar = _castCopyAndTranspose(t, a, bstar)\n s = zeros((min(m,n),),real_t)\n nlvl = max( 0, int( math.log( float(min( m,n ))/2. ) ) + 1 )\n iwork = zeros((3*min(m,n)*nlvl+11*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgelsd\n lwork = 1\n rwork = zeros((lwork,), real_t)\n work = zeros((lwork,),t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,rwork,iwork,0 )\n lwork = int(abs(work[0]))\n rwork = zeros((lwork,),real_t)\n a_real = zeros((m,n),real_t)\n bstar_real = zeros((ldb,n_rhs,),real_t)\n results = lapack_lite.dgelsd( m, n, n_rhs, a_real, m, bstar_real,ldb , s, rcond,\n 0,rwork,-1,iwork,0 )\n lrwork = int(rwork[0])\n work = zeros((lwork,), t)\n rwork = zeros((lrwork,), real_t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,rwork,iwork,0 )\n else:\n lapack_routine = lapack_lite.dgelsd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,iwork,0 )\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,iwork,0 )\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge in Linear Least Squares'\n resids = array([],t)\n if one_eq:\n x = ravel(bstar)[:n].copy()\n if (results['rank']==n) and (m>n):\n resids = array([sum((ravel(bstar)[n:])**2)])\n else:\n x = transpose(bstar)[:n,:].copy()\n if (results['rank']==n) and (m>n):\n resids = sum((transpose(bstar)[n:,:])**2).copy()\n return wrap(x),resids,results['rank'],s[:min(n,m)].copy()\n\ndef singular_value_decomposition(A, full_matrices=0):\n return svd(A, full_matrices)\n\ndef eigenvectors(A):\n w, v = eig(A)\n return w, transpose(v)\n\ndef Heigenvectors(A):\n w, v = eigh(A)\n return w, transpose(v)\n\ninv = inverse\nsolve = solve_linear_equations\ncholesky = cholesky_decomposition\neigvals = eigenvalues\neigvalsh = Heigenvalues\npinv = generalized_inverse\ndet = determinant\nlstsq = linear_least_squares\n\nif __name__ == '__main__':\n def test(a, b):\n\n print \"All numbers printed should be (almost) zero:\"\n\n x = solve_linear_equations(a, b)\n check = b - matrixmultiply(a, x)\n print check\n\n\n a_inv = inverse(a)\n check = matrixmultiply(a, a_inv)-identity(a.shape[0])\n print check\n\n\n ev = eigenvalues(a)\n\n evalues, evectors = eig(a)\n check = ev-evalues\n print check\n\n evectors = transpose(evectors)\n check = matrixmultiply(a, evectors)-evectors*evalues\n print check\n\n\n u, s, vt = svd(a,0)\n check = a - matrixmultiply(u*s, vt)\n print check\n\n\n a_ginv = generalized_inverse(a)\n check = matrixmultiply(a, a_ginv)-identity(a.shape[0])\n print check\n\n\n det = determinant(a)\n check = det-multiply.reduce(evalues)\n print check\n\n x, residuals, rank, sv = linear_least_squares(a, b)\n check = b - matrixmultiply(a, x)\n print check\n print rank-a.shape[0]\n print sv-s\n\n a = array([[1.,2.], [3.,4.]])\n b = array([2., 1.])\n test(a, b)\n\n a = a+0j\n b = b+0j\n test(a, b)\n", + "source_code_before": "\n\"\"\"Lite version of scipy.linalg.\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n__all__ = ['LinAlgError', 'solve_linear_equations', 'solve',\n 'inverse', 'inv', 'cholesky_decomposition', 'cholesky', 'eigenvalues',\n 'eigvals', 'Heigenvalues', 'eigvalsh', 'generalized_inverse', 'pinv',\n 'determinant', 'det', 'singular_value_decomposition', 'svd',\n 'eigenvectors', 'eig', 'Heigenvectors', 'eigh','lstsq',\n 'linear_least_squares'\n ]\n\nfrom numpy.core import *\nimport lapack_lite\n\n# Error object\nclass LinAlgError(Exception):\n pass\n\n# Helper routines\n_lapack_type = {'f': 0, 'd': 1, 'F': 2, 'D': 3}\n_lapack_letter = ['s', 'd', 'c', 'z']\n_array_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\n_array_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\n_array_type = [['f', 'd'], ['F', 'D']]\n\ndef _makearray(a):\n new = asarray(a)\n wrap = getattr(a, \"__array_wrap__\", new.__array_wrap__)\n return new, wrap\n\ndef _commonType(*arrays):\n kind = 0\n# precision = 0\n# force higher precision in lite version\n precision = 1\n for a in arrays:\n t = a.dtype.char\n kind = max(kind, _array_kind[t])\n precision = max(precision, _array_precision[t])\n return _array_type[kind][precision]\n\ndef _castCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n cast_arrays = cast_arrays + (transpose(a).astype(type),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\n# _fastCopyAndTranpose is an optimized version of _castCopyAndTranspose.\n# It assumes the input is 2D (as all the calls in here are).\n\n_fastCT = fastCopyAndTranspose\n\ndef _fastCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.dtype.char == type:\n cast_arrays = cast_arrays + (_fastCT(a),)\n else:\n cast_arrays = cast_arrays + (_fastCT(a.astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\ndef _assertRank2(*arrays):\n for a in arrays:\n if len(a.shape) != 2:\n raise LinAlgError, 'Array must be two-dimensional'\n\ndef _assertSquareness(*arrays):\n for a in arrays:\n if max(a.shape) != min(a.shape):\n raise LinAlgError, 'Array must be square'\n\n\n# Linear equations\n\ndef solve_linear_equations(a, b):\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n _assertSquareness(a)\n n_eq = a.shape[0]\n n_rhs = b.shape[1]\n if n_eq != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n# lapack_routine = _findLapackRoutine('gesv', t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesv\n else:\n lapack_routine = lapack_lite.dgesv\n a, b = _fastCopyAndTranspose(t, a, b)\n pivots = zeros(n_eq, 'i')\n results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Singular matrix'\n if one_eq:\n return ravel(b) # I see no need to copy here\n else:\n return transpose(b) # no need to copy\n\n\n# Matrix inversion\n\ndef inverse(a):\n return solve_linear_equations(a, identity(a.shape[0]))\n\n\n# Cholesky decomposition\n\ndef cholesky_decomposition(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _castCopyAndTranspose(t, a)\n m = a.shape[0]\n n = a.shape[1]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zpotrf\n else:\n lapack_routine = lapack_lite.dpotrf\n results = lapack_routine('L', n, a, m, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Matrix is not positive definite - Cholesky decomposition cannot be computed'\n return transpose(triu(a,k=0)).copy()\n\n\n# Eigenvalues\n\ndef eigenvalues(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n dummy = zeros((1,), t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n rwork = zeros((n,),real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n else:\n w = wr+1j*wi\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\n\ndef Heigenvalues(a, UPLO='L'):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\ndef _convertarray(a):\n if issubclass(a.dtype.type, complexfloating):\n if a.dtype.char == 'D':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('D'))\n else:\n if a.dtype.char == 'd':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('d'))\n return a, a.dtype.char\n\n# Eigenvectors\n\ndef eig(a):\n \"\"\"eig(a) returns u,v where u is the eigenvalues and\nv is a matrix of eigenvectors with vector v[:,i] corresponds to\neigenvalue u[i]. Satisfies the equation dot(a, v[:,i]) = u[i]*v[:,i]\n\"\"\"\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n a,t = _convertarray(a) # convert to float_ or complex_ type\n real_t = 'd'\n n = a.shape[0]\n dummy = zeros((1,), t)\n if t == 'D': # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n v = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n rwork = zeros((2*n,),real_t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n vr = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n v = vr\n else:\n w = wr+1j*wi\n v = array(vr,Complex)\n ind = nonzero(\n equal(\n equal(wi,0.0) # true for real e-vals\n ,0) # true for complex e-vals\n ) # indices of complex e-vals\n for i in range(len(ind)/2):\n v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]]\n v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]]\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(v.transpose())\n\n\ndef eigh(a, UPLO='L'):\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(a.transpose())\n\n\n# Singular value decomposition\n\ndef svd(a, full_matrices=1):\n a, wrap = _makearray(a)\n _assertRank2(a)\n m, n = a.shape\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n if full_matrices:\n nu = m\n nvt = n\n option = 'A'\n else:\n nu = min(n,m)\n nvt = min(n,m)\n option = 'S'\n s = zeros((min(n,m),), real_t)\n u = zeros((nu, m), t)\n vt = zeros((n, nvt), t)\n iwork = zeros((8*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesdd\n rwork = zeros((5*min(m,n)*min(m,n) + 5*min(m,n),), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, rwork, iwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, rwork, iwork, 0)\n else:\n lapack_routine = lapack_lite.dgesdd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, iwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, iwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge'\n return wrap(transpose(u)), s, \\\n wrap(transpose(vt)) # why copy here?\n\n\n# Generalized inverse\n\ndef generalized_inverse(a, rcond = 1.e-10):\n a, wrap = _makearray(a)\n if a.dtype.char in typecodes['Complex']:\n a = conjugate(a)\n u, s, vt = svd(a, 0)\n m = u.shape[0]\n n = vt.shape[1]\n cutoff = rcond*maximum.reduce(s)\n for i in range(min(n,m)):\n if s[i] > cutoff:\n s[i] = 1./s[i]\n else:\n s[i] = 0.;\n return wrap(dot(transpose(vt),\n multiply(s[:, NewAxis],transpose(u))))\n\n# Determinant\n\ndef determinant(a):\n a = asarray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zgetrf\n else:\n lapack_routine = lapack_lite.dgetrf\n pivots = zeros((n,), 'i')\n results = lapack_routine(n, n, a, n, pivots, 0)\n sign = add.reduce(not_equal(pivots,\n arrayrange(1, n+1))) % 2\n return (1.-2.*sign)*multiply.reduce(diagonal(a),axis=-1)\n\n# Linear Least Squares\n\ndef linear_least_squares(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n import math\n a = asarray(a)\n b, wrap = _makearray(b)\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n m = a.shape[0]\n n = a.shape[1]\n n_rhs = b.shape[1]\n ldb = max(n,m)\n if m != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n real_t = _array_type[0][_array_precision[t]]\n bstar = zeros((ldb,n_rhs),t)\n bstar[:b.shape[0],:n_rhs] = b.copy()\n a,bstar = _castCopyAndTranspose(t, a, bstar)\n s = zeros((min(m,n),),real_t)\n nlvl = max( 0, int( math.log( float(min( m,n ))/2. ) ) + 1 )\n iwork = zeros((3*min(m,n)*nlvl+11*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgelsd\n lwork = 1\n rwork = zeros((lwork,), real_t)\n work = zeros((lwork,),t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,rwork,iwork,0 )\n lwork = int(abs(work[0]))\n rwork = zeros((lwork,),real_t)\n a_real = zeros((m,n),real_t)\n bstar_real = zeros((ldb,n_rhs,),real_t)\n results = lapack_lite.dgelsd( m, n, n_rhs, a_real, m, bstar_real,ldb , s, rcond,\n 0,rwork,-1,iwork,0 )\n lrwork = int(rwork[0])\n work = zeros((lwork,), t)\n rwork = zeros((lrwork,), real_t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,rwork,iwork,0 )\n else:\n lapack_routine = lapack_lite.dgelsd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,iwork,0 )\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,iwork,0 )\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge in Linear Least Squares'\n resids = array([],t)\n if one_eq:\n x = ravel(bstar)[:n].copy()\n if (results['rank']==n) and (m>n):\n resids = array([sum((ravel(bstar)[n:])**2)])\n else:\n x = transpose(bstar)[:n,:].copy()\n if (results['rank']==n) and (m>n):\n resids = sum((transpose(bstar)[n:,:])**2).copy()\n return wrap(x),resids,results['rank'],s[:min(n,m)].copy()\n\ndef singular_value_decomposition(A, full_matrices=0):\n return svd(A, full_matrices)\n\ndef eigenvectors(A):\n w, v = eig(A)\n return w, transpose(v)\n\ndef Heigenvectors(A):\n w, v = eigh(A)\n return w, transpose(v)\n\ninv = inverse\nsolve = solve_linear_equations\ncholesky = cholesky_decomposition\neigvals = eigenvalues\neigvalsh = Heigenvalues\npinv = generalized_inverse\ndet = determinant\nlstsq = linear_least_squares\n\nif __name__ == '__main__':\n def test(a, b):\n\n print \"All numbers printed should be (almost) zero:\"\n\n x = solve_linear_equations(a, b)\n check = b - matrixmultiply(a, x)\n print check\n\n\n a_inv = inverse(a)\n check = matrixmultiply(a, a_inv)-identity(a.shape[0])\n print check\n\n\n ev = eigenvalues(a)\n\n evalues, evectors = eig(a)\n check = ev-evalues\n print check\n\n evectors = transpose(evectors)\n check = matrixmultiply(a, evectors)-evectors*evalues\n print check\n\n\n u, s, vt = svd(a,0)\n check = a - matrixmultiply(u*s, vt)\n print check\n\n\n a_ginv = generalized_inverse(a)\n check = matrixmultiply(a, a_ginv)-identity(a.shape[0])\n print check\n\n\n det = determinant(a)\n check = det-multiply.reduce(evalues)\n print check\n\n x, residuals, rank, sv = linear_least_squares(a, b)\n check = b - matrixmultiply(a, x)\n print check\n print rank-a.shape[0]\n print sv-s\n\n a = array([[1.,2.], [3.,4.]])\n b = array([2., 1.])\n test(a, b)\n\n a = a+0j\n b = b+0j\n test(a, b)\n", + "methods": [ + { + "name": "_makearray", + "long_name": "_makearray( a )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a" + ], + "start_line": 32, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_commonType", + "long_name": "_commonType( * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 2, + "token_count": 54, + "parameters": [ + "arrays" + ], + "start_line": 37, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_castCopyAndTranspose", + "long_name": "_castCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "type", + "arrays" + ], + "start_line": 48, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "_fastCopyAndTranspose", + "long_name": "_fastCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 11, + "complexity": 4, + "token_count": 72, + "parameters": [ + "type", + "arrays" + ], + "start_line": 62, + "end_line": 72, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_assertRank2", + "long_name": "_assertRank2( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 25, + "parameters": [ + "arrays" + ], + "start_line": 74, + "end_line": 77, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_assertSquareness", + "long_name": "_assertSquareness( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 30, + "parameters": [ + "arrays" + ], + "start_line": 79, + "end_line": 82, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "solve_linear_equations", + "long_name": "solve_linear_equations( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 87, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "inverse", + "long_name": "inverse( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 116, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cholesky_decomposition", + "long_name": "cholesky_decomposition( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 3, + "token_count": 105, + "parameters": [ + "a" + ], + "start_line": 123, + "end_line": 137, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "eigenvalues", + "long_name": "eigenvalues( a )", + "filename": "linalg.py", + "nloc": 39, + "complexity": 4, + "token_count": 363, + "parameters": [ + "a" + ], + "start_line": 142, + "end_line": 180, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Heigenvalues", + "long_name": "Heigenvalues( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 34, + "complexity": 3, + "token_count": 345, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 183, + "end_line": 216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convertarray", + "long_name": "_convertarray( a )", + "filename": "linalg.py", + "nloc": 12, + "complexity": 4, + "token_count": 83, + "parameters": [ + "a" + ], + "start_line": 218, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "eig", + "long_name": "eig( a )", + "filename": "linalg.py", + "nloc": 51, + "complexity": 5, + "token_count": 499, + "parameters": [ + "a" + ], + "start_line": 233, + "end_line": 287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "eigh", + "long_name": "eigh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 3, + "token_count": 362, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 290, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "svd", + "long_name": "svd( a , full_matrices = 1 )", + "filename": "linalg.py", + "nloc": 44, + "complexity": 4, + "token_count": 435, + "parameters": [ + "a", + "full_matrices" + ], + "start_line": 329, + "end_line": 372, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "generalized_inverse", + "long_name": "generalized_inverse( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 377, + "end_line": 391, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "determinant", + "long_name": "determinant( a )", + "filename": "linalg.py", + "nloc": 16, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 395, + "end_line": 410, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "linear_least_squares", + "long_name": "linear_least_squares( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 414, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "singular_value_decomposition", + "long_name": "singular_value_decomposition( A , full_matrices = 0 )", + "filename": "linalg.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "A", + "full_matrices" + ], + "start_line": 489, + "end_line": 490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvectors", + "long_name": "eigenvectors( A )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "A" + ], + "start_line": 492, + "end_line": 494, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "Heigenvectors", + "long_name": "Heigenvectors( A )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "A" + ], + "start_line": 496, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "test", + "long_name": "test( a , b )", + "filename": "linalg.py", + "nloc": 29, + "complexity": 1, + "token_count": 205, + "parameters": [ + "a", + "b" + ], + "start_line": 510, + "end_line": 553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "_makearray", + "long_name": "_makearray( a )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a" + ], + "start_line": 31, + "end_line": 34, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_commonType", + "long_name": "_commonType( * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 2, + "token_count": 54, + "parameters": [ + "arrays" + ], + "start_line": 36, + "end_line": 45, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_castCopyAndTranspose", + "long_name": "_castCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "type", + "arrays" + ], + "start_line": 47, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "_fastCopyAndTranspose", + "long_name": "_fastCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 11, + "complexity": 4, + "token_count": 72, + "parameters": [ + "type", + "arrays" + ], + "start_line": 61, + "end_line": 71, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_assertRank2", + "long_name": "_assertRank2( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 25, + "parameters": [ + "arrays" + ], + "start_line": 73, + "end_line": 76, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_assertSquareness", + "long_name": "_assertSquareness( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 30, + "parameters": [ + "arrays" + ], + "start_line": 78, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "solve_linear_equations", + "long_name": "solve_linear_equations( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 86, + "end_line": 110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "inverse", + "long_name": "inverse( a )", + "filename": "linalg.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a" + ], + "start_line": 115, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "cholesky_decomposition", + "long_name": "cholesky_decomposition( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 3, + "token_count": 105, + "parameters": [ + "a" + ], + "start_line": 121, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "eigenvalues", + "long_name": "eigenvalues( a )", + "filename": "linalg.py", + "nloc": 39, + "complexity": 4, + "token_count": 363, + "parameters": [ + "a" + ], + "start_line": 140, + "end_line": 178, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Heigenvalues", + "long_name": "Heigenvalues( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 34, + "complexity": 3, + "token_count": 345, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 181, + "end_line": 214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convertarray", + "long_name": "_convertarray( a )", + "filename": "linalg.py", + "nloc": 12, + "complexity": 4, + "token_count": 83, + "parameters": [ + "a" + ], + "start_line": 216, + "end_line": 227, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "eig", + "long_name": "eig( a )", + "filename": "linalg.py", + "nloc": 51, + "complexity": 5, + "token_count": 499, + "parameters": [ + "a" + ], + "start_line": 231, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "eigh", + "long_name": "eigh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 3, + "token_count": 362, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 288, + "end_line": 322, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "svd", + "long_name": "svd( a , full_matrices = 1 )", + "filename": "linalg.py", + "nloc": 44, + "complexity": 4, + "token_count": 435, + "parameters": [ + "a", + "full_matrices" + ], + "start_line": 327, + "end_line": 370, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "generalized_inverse", + "long_name": "generalized_inverse( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 375, + "end_line": 389, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "determinant", + "long_name": "determinant( a )", + "filename": "linalg.py", + "nloc": 16, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 393, + "end_line": 408, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "linear_least_squares", + "long_name": "linear_least_squares( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 412, + "end_line": 485, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "singular_value_decomposition", + "long_name": "singular_value_decomposition( A , full_matrices = 0 )", + "filename": "linalg.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "A", + "full_matrices" + ], + "start_line": 487, + "end_line": 488, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvectors", + "long_name": "eigenvectors( A )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "A" + ], + "start_line": 490, + "end_line": 492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "Heigenvectors", + "long_name": "Heigenvectors( A )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "A" + ], + "start_line": 494, + "end_line": 496, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "test", + "long_name": "test( a , b )", + "filename": "linalg.py", + "nloc": 29, + "complexity": 1, + "token_count": 205, + "parameters": [ + "a", + "b" + ], + "start_line": 508, + "end_line": 551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "inverse", + "long_name": "inverse( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 116, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + } + ], + "nloc": 461, + "complexity": 69, + "token_count": 4195, + "diff_parsed": { + "added": [ + "from numpy.lib import *", + " a, wrap = _makearray(a)", + " return wrap(solve_linear_equations(a, identity(a.shape[0])))" + ], + "deleted": [ + " return solve_linear_equations(a, identity(a.shape[0]))" + ] + } + } + ] + }, + { + "hash": "9682b2c4abe69d055d7e56c2a53e5e0955e75ab3", + "msg": "Committed much of ticket #36", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-15T01:34:50+00:00", + "author_timezone": 0, + "committer_date": "2006-03-15T01:34:50+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "03736884e2fb993e096ef801dd49135b9292b823" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 29, + "insertions": 118, + "lines": 147, + "files": 3, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/dual.py", + "new_path": "numpy/dual.py", + "filename": "dual.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -4,8 +4,8 @@\n # Usage --- from numpy.dual import fft, inv\n \n __all__ = ['fft','ifft','fftn','ifftn','fft2','ifft2',\n- 'inv','svd','solve','det','eig','eigvals','lstsq',\n- 'pinv','cholesky','i0']\n+ 'norm','inv','svd','solve','det','eig','eigvals',\n+ 'eigh','eigvalsh','lstsq', 'pinv','cholesky','i0']\n \n import numpy.linalg as linpkg\n import numpy.dft as fftpkg\n@@ -20,12 +20,15 @@\n fft2 = fftpkg.fft2\n ifft2 = fftpkg.ifft2\n \n+norm = linpkg.norm\n inv = linpkg.inv\n svd = linpkg.svd\n solve = linpkg.solve\n det = linpkg.det\n eig = linpkg.eig\n eigvals = linpkg.eigvals\n+eigh = linpkg.eigh\n+eigvalsh = linpkg.eigvalsh\n lstsq = linpkg.lstsq\n pinv = linpkg.pinv\n cholesky = linpkg.cholesky\n", + "added_lines": 5, + "deleted_lines": 2, + "source_code": "# This module should be used for functions both in numpy and scipy if\n# you want to use the numpy version if available but the scipy version\n# otherwise.\n# Usage --- from numpy.dual import fft, inv\n\n__all__ = ['fft','ifft','fftn','ifftn','fft2','ifft2',\n 'norm','inv','svd','solve','det','eig','eigvals',\n 'eigh','eigvalsh','lstsq', 'pinv','cholesky','i0']\n\nimport numpy.linalg as linpkg\nimport numpy.dft as fftpkg\nfrom numpy.lib import i0\nimport sys\n\n\nfft = fftpkg.fft\nifft = fftpkg.ifft\nfftn = fftpkg.fftn\nifftn = fftpkg.ifftn\nfft2 = fftpkg.fft2\nifft2 = fftpkg.ifft2\n\nnorm = linpkg.norm\ninv = linpkg.inv\nsvd = linpkg.svd\nsolve = linpkg.solve\ndet = linpkg.det\neig = linpkg.eig\neigvals = linpkg.eigvals\neigh = linpkg.eigh\neigvalsh = linpkg.eigvalsh\nlstsq = linpkg.lstsq\npinv = linpkg.pinv\ncholesky = linpkg.cholesky\n\n_restore_dict = {}\n\ndef register_func(name, func):\n if name not in __all__:\n raise ValueError, \"%s not a dual function.\" % name\n f = sys._getframe(0).f_globals\n _restore_dict[name] = f[name]\n f[name] = func\n\ndef restore_func(name):\n if name not in __all__:\n raise ValueError, \"%s not a dual function.\" % name\n try:\n val = _restore_dict[name]\n except KeyError:\n return\n else:\n sys._getframe(0).f_globals[name] = val\n\ndef restore_all():\n for name in _restore_dict.keys():\n restore_func(name)\n", + "source_code_before": "# This module should be used for functions both in numpy and scipy if\n# you want to use the numpy version if available but the scipy version\n# otherwise.\n# Usage --- from numpy.dual import fft, inv\n\n__all__ = ['fft','ifft','fftn','ifftn','fft2','ifft2',\n 'inv','svd','solve','det','eig','eigvals','lstsq',\n 'pinv','cholesky','i0']\n\nimport numpy.linalg as linpkg\nimport numpy.dft as fftpkg\nfrom numpy.lib import i0\nimport sys\n\n\nfft = fftpkg.fft\nifft = fftpkg.ifft\nfftn = fftpkg.fftn\nifftn = fftpkg.ifftn\nfft2 = fftpkg.fft2\nifft2 = fftpkg.ifft2\n\ninv = linpkg.inv\nsvd = linpkg.svd\nsolve = linpkg.solve\ndet = linpkg.det\neig = linpkg.eig\neigvals = linpkg.eigvals\nlstsq = linpkg.lstsq\npinv = linpkg.pinv\ncholesky = linpkg.cholesky\n\n_restore_dict = {}\n\ndef register_func(name, func):\n if name not in __all__:\n raise ValueError, \"%s not a dual function.\" % name\n f = sys._getframe(0).f_globals\n _restore_dict[name] = f[name]\n f[name] = func\n\ndef restore_func(name):\n if name not in __all__:\n raise ValueError, \"%s not a dual function.\" % name\n try:\n val = _restore_dict[name]\n except KeyError:\n return\n else:\n sys._getframe(0).f_globals[name] = val\n\ndef restore_all():\n for name in _restore_dict.keys():\n restore_func(name)\n", + "methods": [ + { + "name": "register_func", + "long_name": "register_func( name , func )", + "filename": "dual.py", + "nloc": 6, + "complexity": 2, + "token_count": 44, + "parameters": [ + "name", + "func" + ], + "start_line": 38, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "restore_func", + "long_name": "restore_func( name )", + "filename": "dual.py", + "nloc": 9, + "complexity": 3, + "token_count": 44, + "parameters": [ + "name" + ], + "start_line": 45, + "end_line": 53, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "restore_all", + "long_name": "restore_all( )", + "filename": "dual.py", + "nloc": 3, + "complexity": 2, + "token_count": 17, + "parameters": [], + "start_line": 55, + "end_line": 57, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "register_func", + "long_name": "register_func( name , func )", + "filename": "dual.py", + "nloc": 6, + "complexity": 2, + "token_count": 44, + "parameters": [ + "name", + "func" + ], + "start_line": 35, + "end_line": 40, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "restore_func", + "long_name": "restore_func( name )", + "filename": "dual.py", + "nloc": 9, + "complexity": 3, + "token_count": 44, + "parameters": [ + "name" + ], + "start_line": 42, + "end_line": 50, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "restore_all", + "long_name": "restore_all( )", + "filename": "dual.py", + "nloc": 3, + "complexity": 2, + "token_count": 17, + "parameters": [], + "start_line": 52, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 44, + "complexity": 7, + "token_count": 263, + "diff_parsed": { + "added": [ + " 'norm','inv','svd','solve','det','eig','eigvals',", + " 'eigh','eigvalsh','lstsq', 'pinv','cholesky','i0']", + "norm = linpkg.norm", + "eigh = linpkg.eigh", + "eigvalsh = linpkg.eigvalsh" + ], + "deleted": [ + " 'inv','svd','solve','det','eig','eigvals','lstsq',", + " 'pinv','cholesky','i0']" + ] + } + }, + { + "old_path": "numpy/linalg/info.py", + "new_path": "numpy/linalg/info.py", + "filename": "info.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -4,18 +4,19 @@\n \n Linear Algebra Basics:\n \n- inv --- Find the inverse of a square matrix\n+ norm --- Vector or matrix norm \n+ inv --- Inverse of a square matrix\n solve --- Solve a linear system of equations\n- det --- Find the determinant of a square matrix\n+ det --- Determinant of a square matrix\n lstsq --- Solve linear least-squares problem\n pinv --- Pseudo-inverse (Moore-Penrose) using lstsq\n \n Eigenvalues and Decompositions:\n \n- eig --- Find the eigenvalues and vectors of a square matrix\n- eigh --- Find the eigenvalues and eigenvectors of a Hermitian matrix\n- eigvals --- Find the eigenvalues of a square matrix\n- eigvalsh --- Find the eigenvalues of a Hermitian matrix.\n+ eig --- Eigenvalues and vectors of a square matrix\n+ eigh --- Eigenvalues and eigenvectors of a Hermitian matrix\n+ eigvals --- Eigenvalues of a square matrix\n+ eigvalsh --- Eigenvalues of a Hermitian matrix.\n svd --- Singular value decomposition of a matrix\n cholesky --- Cholesky decomposition of a matrix\n \n", + "added_lines": 7, + "deleted_lines": 6, + "source_code": "\"\"\"\\\nCore Linear Algebra Tools\n===========\n\n Linear Algebra Basics:\n\n norm --- Vector or matrix norm \n inv --- Inverse of a square matrix\n solve --- Solve a linear system of equations\n det --- Determinant of a square matrix\n lstsq --- Solve linear least-squares problem\n pinv --- Pseudo-inverse (Moore-Penrose) using lstsq\n\n Eigenvalues and Decompositions:\n\n eig --- Eigenvalues and vectors of a square matrix\n eigh --- Eigenvalues and eigenvectors of a Hermitian matrix\n eigvals --- Eigenvalues of a square matrix\n eigvalsh --- Eigenvalues of a Hermitian matrix.\n svd --- Singular value decomposition of a matrix\n cholesky --- Cholesky decomposition of a matrix\n\n\"\"\"\n\ndepends = ['core']\n", + "source_code_before": "\"\"\"\\\nCore Linear Algebra Tools\n===========\n\n Linear Algebra Basics:\n\n inv --- Find the inverse of a square matrix\n solve --- Solve a linear system of equations\n det --- Find the determinant of a square matrix\n lstsq --- Solve linear least-squares problem\n pinv --- Pseudo-inverse (Moore-Penrose) using lstsq\n\n Eigenvalues and Decompositions:\n\n eig --- Find the eigenvalues and vectors of a square matrix\n eigh --- Find the eigenvalues and eigenvectors of a Hermitian matrix\n eigvals --- Find the eigenvalues of a square matrix\n eigvalsh --- Find the eigenvalues of a Hermitian matrix.\n svd --- Singular value decomposition of a matrix\n cholesky --- Cholesky decomposition of a matrix\n\n\"\"\"\n\ndepends = ['core']\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": 24, + "complexity": 0, + "token_count": 6, + "diff_parsed": { + "added": [ + " norm --- Vector or matrix norm", + " inv --- Inverse of a square matrix", + " det --- Determinant of a square matrix", + " eig --- Eigenvalues and vectors of a square matrix", + " eigh --- Eigenvalues and eigenvectors of a Hermitian matrix", + " eigvals --- Eigenvalues of a square matrix", + " eigvalsh --- Eigenvalues of a Hermitian matrix." + ], + "deleted": [ + " inv --- Find the inverse of a square matrix", + " det --- Find the determinant of a square matrix", + " eig --- Find the eigenvalues and vectors of a square matrix", + " eigh --- Find the eigenvalues and eigenvectors of a Hermitian matrix", + " eigvals --- Find the eigenvalues of a square matrix", + " eigvalsh --- Find the eigenvalues of a Hermitian matrix." + ] + } + }, + { + "old_path": "numpy/linalg/linalg.py", + "new_path": "numpy/linalg/linalg.py", + "filename": "linalg.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -10,7 +10,7 @@\n 'inverse', 'inv', 'cholesky_decomposition', 'cholesky', 'eigenvalues',\n 'eigvals', 'Heigenvalues', 'eigvalsh', 'generalized_inverse', 'pinv',\n 'determinant', 'det', 'singular_value_decomposition', 'svd',\n- 'eigenvectors', 'eig', 'Heigenvectors', 'eigh','lstsq',\n+ 'eigenvectors', 'eig', 'Heigenvectors', 'eigh','lstsq', 'norm',\n 'linear_least_squares'\n ]\n \n@@ -46,13 +46,10 @@ def _commonType(*arrays):\n return _array_type[kind][precision]\n \n def _castCopyAndTranspose(type, *arrays):\n- cast_arrays = ()\n- for a in arrays:\n- cast_arrays = cast_arrays + (transpose(a).astype(type),)\n- if len(cast_arrays) == 1:\n- return cast_arrays[0]\n+ if len(arrays) == 1:\n+ return transpose(arrays[0]).astype(type)\n else:\n- return cast_arrays\n+ return [transpose(a).astype(type) for a in arrays]\n \n # _fastCopyAndTranpose is an optimized version of _castCopyAndTranspose.\n # It assumes the input is 2D (as all the calls in here are).\n@@ -326,24 +323,32 @@ def eigh(a, UPLO='L'):\n \n # Singular value decomposition\n \n-def svd(a, full_matrices=1):\n+def svd(a, full_matrices=1, compute_uv=1):\n a, wrap = _makearray(a)\n _assertRank2(a)\n m, n = a.shape\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n- if full_matrices:\n- nu = m\n- nvt = n\n- option = 'A'\n- else:\n- nu = min(n,m)\n- nvt = min(n,m)\n- option = 'S'\n s = zeros((min(n,m),), real_t)\n- u = zeros((nu, m), t)\n- vt = zeros((n, nvt), t)\n+ if compute_uv:\n+ if full_matrices:\n+ nu = m\n+ nvt = n\n+ option = 'A'\n+ else:\n+ nu = min(n,m)\n+ nvt = min(n,m)\n+ option = 'S'\n+ u = zeros((nu, m), t)\n+ vt = zeros((n, nvt), t)\n+ else:\n+ option = 'N'\n+ nu = 1\n+ nvt = 1\n+ u = empty((1,1),t) \n+ vt = empty((1,1),t) \n+\n iwork = zeros((8*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesdd\n@@ -363,14 +368,25 @@ def svd(a, full_matrices=1):\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, iwork, 0)\n lwork = int(work[0])\n+ if option == 'N' and lwork==1:\n+ # there seems to be a bug in dgesdd of lapack\n+ # (NNemec, 060310)\n+ # returning the wrong lwork size for option == 'N'\n+ results = lapack_routine('A', m, n, a, m, s, u, m, vt, n,\n+ work, -1, iwork, 0)\n+ lwork = int(work[0])\n+ assert lwork > 1\n+\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, iwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge'\n- return wrap(transpose(u)), s, \\\n- wrap(transpose(vt)) # why copy here?\n-\n+ if compute_uv:\n+ return wrap(transpose(u)), s, \\\n+ wrap(transpose(vt)) # why copy here?\n+ else:\n+ return s\n \n # Generalized inverse\n \n@@ -497,6 +513,75 @@ def Heigenvectors(A):\n w, v = eigh(A)\n return w, transpose(v)\n \n+def norm(x, ord=None):\n+ \"\"\" norm(x, ord=None) -> n\n+\n+ Matrix or vector norm.\n+\n+ Inputs:\n+\n+ x -- a rank-1 (vector) or rank-2 (matrix) array\n+ ord -- the order of the norm.\n+\n+ Comments:\n+ For arrays of any rank, if ord is None:\n+ calculate the square norm (Euclidean norm for vectors, Frobenius norm for matrices)\n+\n+ For vectors ord can be any real number including Inf or -Inf.\n+ ord = Inf, computes the maximum of the magnitudes\n+ ord = -Inf, computes minimum of the magnitudes\n+ ord is finite, computes sum(abs(x)**ord)**(1.0/ord)\n+\n+ For matrices ord can only be one of the following values:\n+ ord = 2 computes the largest singular value\n+ ord = -2 computes the smallest singular value\n+ ord = 1 computes the largest column sum of absolute values\n+ ord = -1 computes the smallest column sum of absolute values\n+ ord = Inf computes the largest row sum of absolute values\n+ ord = -Inf computes the smallest row sum of absolute values\n+ ord = 'fro' computes the frobenius norm sqrt(sum(diag(X.H * X)))\n+\n+ For values ord < 0, the result is, strictly speaking, not a\n+ mathematical 'norm', but it may still be useful for numerical purposes.\n+ \"\"\"\n+ x = asarray(x)\n+ nd = len(x.shape) \n+ if ord is None: # check the default case first and handle it immediately\n+ return sqrt(add.reduce((x.conj() * x).ravel().real))\n+\n+ if nd == 1:\n+ if ord == Inf:\n+ return abs(x).max()\n+ elif ord == -Inf:\n+ return abs(x).min()\n+ elif ord == 1:\n+ return abs(x).sum() # special case for speedup\n+ elif ord == 2:\n+ return sqrt(((x.conj()*x).real).sum()) # special case for speedup\n+ else:\n+ return ((abs(x)**ord).sum())**(1.0/ord)\n+ elif nd == 2:\n+ if ord == 2:\n+ return svd(x,compute_uv=0).max()\n+ elif ord == -2:\n+ return svd(x,compute_uv=0).min()\n+ elif ord == 1:\n+ return abs(x).sum(axis=0).max()\n+ elif ord == Inf:\n+ return abs(x).sum(axis=1).max()\n+ elif ord == -1:\n+ return abs(x).sum(axis=0).min()\n+ elif ord == -Inf:\n+ return abs(x).sum(axis=1).min()\n+ elif ord in ['fro','f']:\n+ return sqrt(add.reduce((x.conj() * x).real.ravel()))\n+ else:\n+ raise ValueError, \"Invalid norm order for matrices.\"\n+ else:\n+ raise ValueError, \"Improper number of dimensions to norm.\"\n+\n+\n+\n inv = inverse\n solve = solve_linear_equations\n cholesky = cholesky_decomposition\n", + "added_lines": 106, + "deleted_lines": 21, + "source_code": "\n\"\"\"Lite version of scipy.linalg.\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n__all__ = ['LinAlgError', 'solve_linear_equations', 'solve',\n 'inverse', 'inv', 'cholesky_decomposition', 'cholesky', 'eigenvalues',\n 'eigvals', 'Heigenvalues', 'eigvalsh', 'generalized_inverse', 'pinv',\n 'determinant', 'det', 'singular_value_decomposition', 'svd',\n 'eigenvectors', 'eig', 'Heigenvectors', 'eigh','lstsq', 'norm',\n 'linear_least_squares'\n ]\n\nfrom numpy.core import *\nfrom numpy.lib import *\nimport lapack_lite\n\n# Error object\nclass LinAlgError(Exception):\n pass\n\n# Helper routines\n_lapack_type = {'f': 0, 'd': 1, 'F': 2, 'D': 3}\n_lapack_letter = ['s', 'd', 'c', 'z']\n_array_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\n_array_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\n_array_type = [['f', 'd'], ['F', 'D']]\n\ndef _makearray(a):\n new = asarray(a)\n wrap = getattr(a, \"__array_wrap__\", new.__array_wrap__)\n return new, wrap\n\ndef _commonType(*arrays):\n kind = 0\n# precision = 0\n# force higher precision in lite version\n precision = 1\n for a in arrays:\n t = a.dtype.char\n kind = max(kind, _array_kind[t])\n precision = max(precision, _array_precision[t])\n return _array_type[kind][precision]\n\ndef _castCopyAndTranspose(type, *arrays):\n if len(arrays) == 1:\n return transpose(arrays[0]).astype(type)\n else:\n return [transpose(a).astype(type) for a in arrays]\n\n# _fastCopyAndTranpose is an optimized version of _castCopyAndTranspose.\n# It assumes the input is 2D (as all the calls in here are).\n\n_fastCT = fastCopyAndTranspose\n\ndef _fastCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.dtype.char == type:\n cast_arrays = cast_arrays + (_fastCT(a),)\n else:\n cast_arrays = cast_arrays + (_fastCT(a.astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\ndef _assertRank2(*arrays):\n for a in arrays:\n if len(a.shape) != 2:\n raise LinAlgError, 'Array must be two-dimensional'\n\ndef _assertSquareness(*arrays):\n for a in arrays:\n if max(a.shape) != min(a.shape):\n raise LinAlgError, 'Array must be square'\n\n\n# Linear equations\n\ndef solve_linear_equations(a, b):\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n _assertSquareness(a)\n n_eq = a.shape[0]\n n_rhs = b.shape[1]\n if n_eq != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n# lapack_routine = _findLapackRoutine('gesv', t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesv\n else:\n lapack_routine = lapack_lite.dgesv\n a, b = _fastCopyAndTranspose(t, a, b)\n pivots = zeros(n_eq, 'i')\n results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Singular matrix'\n if one_eq:\n return ravel(b) # I see no need to copy here\n else:\n return transpose(b) # no need to copy\n\n\n# Matrix inversion\n\ndef inverse(a):\n a, wrap = _makearray(a)\n return wrap(solve_linear_equations(a, identity(a.shape[0])))\n\n\n# Cholesky decomposition\n\ndef cholesky_decomposition(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _castCopyAndTranspose(t, a)\n m = a.shape[0]\n n = a.shape[1]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zpotrf\n else:\n lapack_routine = lapack_lite.dpotrf\n results = lapack_routine('L', n, a, m, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Matrix is not positive definite - Cholesky decomposition cannot be computed'\n return transpose(triu(a,k=0)).copy()\n\n\n# Eigenvalues\n\ndef eigenvalues(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n dummy = zeros((1,), t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n rwork = zeros((n,),real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n else:\n w = wr+1j*wi\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\n\ndef Heigenvalues(a, UPLO='L'):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\ndef _convertarray(a):\n if issubclass(a.dtype.type, complexfloating):\n if a.dtype.char == 'D':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('D'))\n else:\n if a.dtype.char == 'd':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('d'))\n return a, a.dtype.char\n\n# Eigenvectors\n\ndef eig(a):\n \"\"\"eig(a) returns u,v where u is the eigenvalues and\nv is a matrix of eigenvectors with vector v[:,i] corresponds to\neigenvalue u[i]. Satisfies the equation dot(a, v[:,i]) = u[i]*v[:,i]\n\"\"\"\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n a,t = _convertarray(a) # convert to float_ or complex_ type\n real_t = 'd'\n n = a.shape[0]\n dummy = zeros((1,), t)\n if t == 'D': # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n v = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n rwork = zeros((2*n,),real_t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n vr = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n v = vr\n else:\n w = wr+1j*wi\n v = array(vr,Complex)\n ind = nonzero(\n equal(\n equal(wi,0.0) # true for real e-vals\n ,0) # true for complex e-vals\n ) # indices of complex e-vals\n for i in range(len(ind)/2):\n v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]]\n v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]]\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(v.transpose())\n\n\ndef eigh(a, UPLO='L'):\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(a.transpose())\n\n\n# Singular value decomposition\n\ndef svd(a, full_matrices=1, compute_uv=1):\n a, wrap = _makearray(a)\n _assertRank2(a)\n m, n = a.shape\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n s = zeros((min(n,m),), real_t)\n if compute_uv:\n if full_matrices:\n nu = m\n nvt = n\n option = 'A'\n else:\n nu = min(n,m)\n nvt = min(n,m)\n option = 'S'\n u = zeros((nu, m), t)\n vt = zeros((n, nvt), t)\n else:\n option = 'N'\n nu = 1\n nvt = 1\n u = empty((1,1),t) \n vt = empty((1,1),t) \n\n iwork = zeros((8*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesdd\n rwork = zeros((5*min(m,n)*min(m,n) + 5*min(m,n),), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, rwork, iwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, rwork, iwork, 0)\n else:\n lapack_routine = lapack_lite.dgesdd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, iwork, 0)\n lwork = int(work[0])\n if option == 'N' and lwork==1:\n # there seems to be a bug in dgesdd of lapack\n # (NNemec, 060310)\n # returning the wrong lwork size for option == 'N'\n results = lapack_routine('A', m, n, a, m, s, u, m, vt, n,\n work, -1, iwork, 0)\n lwork = int(work[0])\n assert lwork > 1\n\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, iwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge'\n if compute_uv:\n return wrap(transpose(u)), s, \\\n wrap(transpose(vt)) # why copy here?\n else:\n return s\n\n# Generalized inverse\n\ndef generalized_inverse(a, rcond = 1.e-10):\n a, wrap = _makearray(a)\n if a.dtype.char in typecodes['Complex']:\n a = conjugate(a)\n u, s, vt = svd(a, 0)\n m = u.shape[0]\n n = vt.shape[1]\n cutoff = rcond*maximum.reduce(s)\n for i in range(min(n,m)):\n if s[i] > cutoff:\n s[i] = 1./s[i]\n else:\n s[i] = 0.;\n return wrap(dot(transpose(vt),\n multiply(s[:, NewAxis],transpose(u))))\n\n# Determinant\n\ndef determinant(a):\n a = asarray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zgetrf\n else:\n lapack_routine = lapack_lite.dgetrf\n pivots = zeros((n,), 'i')\n results = lapack_routine(n, n, a, n, pivots, 0)\n sign = add.reduce(not_equal(pivots,\n arrayrange(1, n+1))) % 2\n return (1.-2.*sign)*multiply.reduce(diagonal(a),axis=-1)\n\n# Linear Least Squares\n\ndef linear_least_squares(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n import math\n a = asarray(a)\n b, wrap = _makearray(b)\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n m = a.shape[0]\n n = a.shape[1]\n n_rhs = b.shape[1]\n ldb = max(n,m)\n if m != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n real_t = _array_type[0][_array_precision[t]]\n bstar = zeros((ldb,n_rhs),t)\n bstar[:b.shape[0],:n_rhs] = b.copy()\n a,bstar = _castCopyAndTranspose(t, a, bstar)\n s = zeros((min(m,n),),real_t)\n nlvl = max( 0, int( math.log( float(min( m,n ))/2. ) ) + 1 )\n iwork = zeros((3*min(m,n)*nlvl+11*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgelsd\n lwork = 1\n rwork = zeros((lwork,), real_t)\n work = zeros((lwork,),t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,rwork,iwork,0 )\n lwork = int(abs(work[0]))\n rwork = zeros((lwork,),real_t)\n a_real = zeros((m,n),real_t)\n bstar_real = zeros((ldb,n_rhs,),real_t)\n results = lapack_lite.dgelsd( m, n, n_rhs, a_real, m, bstar_real,ldb , s, rcond,\n 0,rwork,-1,iwork,0 )\n lrwork = int(rwork[0])\n work = zeros((lwork,), t)\n rwork = zeros((lrwork,), real_t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,rwork,iwork,0 )\n else:\n lapack_routine = lapack_lite.dgelsd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,iwork,0 )\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,iwork,0 )\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge in Linear Least Squares'\n resids = array([],t)\n if one_eq:\n x = ravel(bstar)[:n].copy()\n if (results['rank']==n) and (m>n):\n resids = array([sum((ravel(bstar)[n:])**2)])\n else:\n x = transpose(bstar)[:n,:].copy()\n if (results['rank']==n) and (m>n):\n resids = sum((transpose(bstar)[n:,:])**2).copy()\n return wrap(x),resids,results['rank'],s[:min(n,m)].copy()\n\ndef singular_value_decomposition(A, full_matrices=0):\n return svd(A, full_matrices)\n\ndef eigenvectors(A):\n w, v = eig(A)\n return w, transpose(v)\n\ndef Heigenvectors(A):\n w, v = eigh(A)\n return w, transpose(v)\n\ndef norm(x, ord=None):\n \"\"\" norm(x, ord=None) -> n\n\n Matrix or vector norm.\n\n Inputs:\n\n x -- a rank-1 (vector) or rank-2 (matrix) array\n ord -- the order of the norm.\n\n Comments:\n For arrays of any rank, if ord is None:\n calculate the square norm (Euclidean norm for vectors, Frobenius norm for matrices)\n\n For vectors ord can be any real number including Inf or -Inf.\n ord = Inf, computes the maximum of the magnitudes\n ord = -Inf, computes minimum of the magnitudes\n ord is finite, computes sum(abs(x)**ord)**(1.0/ord)\n\n For matrices ord can only be one of the following values:\n ord = 2 computes the largest singular value\n ord = -2 computes the smallest singular value\n ord = 1 computes the largest column sum of absolute values\n ord = -1 computes the smallest column sum of absolute values\n ord = Inf computes the largest row sum of absolute values\n ord = -Inf computes the smallest row sum of absolute values\n ord = 'fro' computes the frobenius norm sqrt(sum(diag(X.H * X)))\n\n For values ord < 0, the result is, strictly speaking, not a\n mathematical 'norm', but it may still be useful for numerical purposes.\n \"\"\"\n x = asarray(x)\n nd = len(x.shape) \n if ord is None: # check the default case first and handle it immediately\n return sqrt(add.reduce((x.conj() * x).ravel().real))\n\n if nd == 1:\n if ord == Inf:\n return abs(x).max()\n elif ord == -Inf:\n return abs(x).min()\n elif ord == 1:\n return abs(x).sum() # special case for speedup\n elif ord == 2:\n return sqrt(((x.conj()*x).real).sum()) # special case for speedup\n else:\n return ((abs(x)**ord).sum())**(1.0/ord)\n elif nd == 2:\n if ord == 2:\n return svd(x,compute_uv=0).max()\n elif ord == -2:\n return svd(x,compute_uv=0).min()\n elif ord == 1:\n return abs(x).sum(axis=0).max()\n elif ord == Inf:\n return abs(x).sum(axis=1).max()\n elif ord == -1:\n return abs(x).sum(axis=0).min()\n elif ord == -Inf:\n return abs(x).sum(axis=1).min()\n elif ord in ['fro','f']:\n return sqrt(add.reduce((x.conj() * x).real.ravel()))\n else:\n raise ValueError, \"Invalid norm order for matrices.\"\n else:\n raise ValueError, \"Improper number of dimensions to norm.\"\n\n\n\ninv = inverse\nsolve = solve_linear_equations\ncholesky = cholesky_decomposition\neigvals = eigenvalues\neigvalsh = Heigenvalues\npinv = generalized_inverse\ndet = determinant\nlstsq = linear_least_squares\n\nif __name__ == '__main__':\n def test(a, b):\n\n print \"All numbers printed should be (almost) zero:\"\n\n x = solve_linear_equations(a, b)\n check = b - matrixmultiply(a, x)\n print check\n\n\n a_inv = inverse(a)\n check = matrixmultiply(a, a_inv)-identity(a.shape[0])\n print check\n\n\n ev = eigenvalues(a)\n\n evalues, evectors = eig(a)\n check = ev-evalues\n print check\n\n evectors = transpose(evectors)\n check = matrixmultiply(a, evectors)-evectors*evalues\n print check\n\n\n u, s, vt = svd(a,0)\n check = a - matrixmultiply(u*s, vt)\n print check\n\n\n a_ginv = generalized_inverse(a)\n check = matrixmultiply(a, a_ginv)-identity(a.shape[0])\n print check\n\n\n det = determinant(a)\n check = det-multiply.reduce(evalues)\n print check\n\n x, residuals, rank, sv = linear_least_squares(a, b)\n check = b - matrixmultiply(a, x)\n print check\n print rank-a.shape[0]\n print sv-s\n\n a = array([[1.,2.], [3.,4.]])\n b = array([2., 1.])\n test(a, b)\n\n a = a+0j\n b = b+0j\n test(a, b)\n", + "source_code_before": "\n\"\"\"Lite version of scipy.linalg.\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n__all__ = ['LinAlgError', 'solve_linear_equations', 'solve',\n 'inverse', 'inv', 'cholesky_decomposition', 'cholesky', 'eigenvalues',\n 'eigvals', 'Heigenvalues', 'eigvalsh', 'generalized_inverse', 'pinv',\n 'determinant', 'det', 'singular_value_decomposition', 'svd',\n 'eigenvectors', 'eig', 'Heigenvectors', 'eigh','lstsq',\n 'linear_least_squares'\n ]\n\nfrom numpy.core import *\nfrom numpy.lib import *\nimport lapack_lite\n\n# Error object\nclass LinAlgError(Exception):\n pass\n\n# Helper routines\n_lapack_type = {'f': 0, 'd': 1, 'F': 2, 'D': 3}\n_lapack_letter = ['s', 'd', 'c', 'z']\n_array_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\n_array_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\n_array_type = [['f', 'd'], ['F', 'D']]\n\ndef _makearray(a):\n new = asarray(a)\n wrap = getattr(a, \"__array_wrap__\", new.__array_wrap__)\n return new, wrap\n\ndef _commonType(*arrays):\n kind = 0\n# precision = 0\n# force higher precision in lite version\n precision = 1\n for a in arrays:\n t = a.dtype.char\n kind = max(kind, _array_kind[t])\n precision = max(precision, _array_precision[t])\n return _array_type[kind][precision]\n\ndef _castCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n cast_arrays = cast_arrays + (transpose(a).astype(type),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\n# _fastCopyAndTranpose is an optimized version of _castCopyAndTranspose.\n# It assumes the input is 2D (as all the calls in here are).\n\n_fastCT = fastCopyAndTranspose\n\ndef _fastCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.dtype.char == type:\n cast_arrays = cast_arrays + (_fastCT(a),)\n else:\n cast_arrays = cast_arrays + (_fastCT(a.astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\ndef _assertRank2(*arrays):\n for a in arrays:\n if len(a.shape) != 2:\n raise LinAlgError, 'Array must be two-dimensional'\n\ndef _assertSquareness(*arrays):\n for a in arrays:\n if max(a.shape) != min(a.shape):\n raise LinAlgError, 'Array must be square'\n\n\n# Linear equations\n\ndef solve_linear_equations(a, b):\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n _assertSquareness(a)\n n_eq = a.shape[0]\n n_rhs = b.shape[1]\n if n_eq != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n# lapack_routine = _findLapackRoutine('gesv', t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesv\n else:\n lapack_routine = lapack_lite.dgesv\n a, b = _fastCopyAndTranspose(t, a, b)\n pivots = zeros(n_eq, 'i')\n results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Singular matrix'\n if one_eq:\n return ravel(b) # I see no need to copy here\n else:\n return transpose(b) # no need to copy\n\n\n# Matrix inversion\n\ndef inverse(a):\n a, wrap = _makearray(a)\n return wrap(solve_linear_equations(a, identity(a.shape[0])))\n\n\n# Cholesky decomposition\n\ndef cholesky_decomposition(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _castCopyAndTranspose(t, a)\n m = a.shape[0]\n n = a.shape[1]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zpotrf\n else:\n lapack_routine = lapack_lite.dpotrf\n results = lapack_routine('L', n, a, m, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Matrix is not positive definite - Cholesky decomposition cannot be computed'\n return transpose(triu(a,k=0)).copy()\n\n\n# Eigenvalues\n\ndef eigenvalues(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n dummy = zeros((1,), t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n rwork = zeros((n,),real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n else:\n w = wr+1j*wi\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\n\ndef Heigenvalues(a, UPLO='L'):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\ndef _convertarray(a):\n if issubclass(a.dtype.type, complexfloating):\n if a.dtype.char == 'D':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('D'))\n else:\n if a.dtype.char == 'd':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('d'))\n return a, a.dtype.char\n\n# Eigenvectors\n\ndef eig(a):\n \"\"\"eig(a) returns u,v where u is the eigenvalues and\nv is a matrix of eigenvectors with vector v[:,i] corresponds to\neigenvalue u[i]. Satisfies the equation dot(a, v[:,i]) = u[i]*v[:,i]\n\"\"\"\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n a,t = _convertarray(a) # convert to float_ or complex_ type\n real_t = 'd'\n n = a.shape[0]\n dummy = zeros((1,), t)\n if t == 'D': # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n v = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n rwork = zeros((2*n,),real_t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n vr = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n v = vr\n else:\n w = wr+1j*wi\n v = array(vr,Complex)\n ind = nonzero(\n equal(\n equal(wi,0.0) # true for real e-vals\n ,0) # true for complex e-vals\n ) # indices of complex e-vals\n for i in range(len(ind)/2):\n v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]]\n v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]]\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(v.transpose())\n\n\ndef eigh(a, UPLO='L'):\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(a.transpose())\n\n\n# Singular value decomposition\n\ndef svd(a, full_matrices=1):\n a, wrap = _makearray(a)\n _assertRank2(a)\n m, n = a.shape\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n if full_matrices:\n nu = m\n nvt = n\n option = 'A'\n else:\n nu = min(n,m)\n nvt = min(n,m)\n option = 'S'\n s = zeros((min(n,m),), real_t)\n u = zeros((nu, m), t)\n vt = zeros((n, nvt), t)\n iwork = zeros((8*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesdd\n rwork = zeros((5*min(m,n)*min(m,n) + 5*min(m,n),), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, rwork, iwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, rwork, iwork, 0)\n else:\n lapack_routine = lapack_lite.dgesdd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, iwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, iwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge'\n return wrap(transpose(u)), s, \\\n wrap(transpose(vt)) # why copy here?\n\n\n# Generalized inverse\n\ndef generalized_inverse(a, rcond = 1.e-10):\n a, wrap = _makearray(a)\n if a.dtype.char in typecodes['Complex']:\n a = conjugate(a)\n u, s, vt = svd(a, 0)\n m = u.shape[0]\n n = vt.shape[1]\n cutoff = rcond*maximum.reduce(s)\n for i in range(min(n,m)):\n if s[i] > cutoff:\n s[i] = 1./s[i]\n else:\n s[i] = 0.;\n return wrap(dot(transpose(vt),\n multiply(s[:, NewAxis],transpose(u))))\n\n# Determinant\n\ndef determinant(a):\n a = asarray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zgetrf\n else:\n lapack_routine = lapack_lite.dgetrf\n pivots = zeros((n,), 'i')\n results = lapack_routine(n, n, a, n, pivots, 0)\n sign = add.reduce(not_equal(pivots,\n arrayrange(1, n+1))) % 2\n return (1.-2.*sign)*multiply.reduce(diagonal(a),axis=-1)\n\n# Linear Least Squares\n\ndef linear_least_squares(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n import math\n a = asarray(a)\n b, wrap = _makearray(b)\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n m = a.shape[0]\n n = a.shape[1]\n n_rhs = b.shape[1]\n ldb = max(n,m)\n if m != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n real_t = _array_type[0][_array_precision[t]]\n bstar = zeros((ldb,n_rhs),t)\n bstar[:b.shape[0],:n_rhs] = b.copy()\n a,bstar = _castCopyAndTranspose(t, a, bstar)\n s = zeros((min(m,n),),real_t)\n nlvl = max( 0, int( math.log( float(min( m,n ))/2. ) ) + 1 )\n iwork = zeros((3*min(m,n)*nlvl+11*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgelsd\n lwork = 1\n rwork = zeros((lwork,), real_t)\n work = zeros((lwork,),t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,rwork,iwork,0 )\n lwork = int(abs(work[0]))\n rwork = zeros((lwork,),real_t)\n a_real = zeros((m,n),real_t)\n bstar_real = zeros((ldb,n_rhs,),real_t)\n results = lapack_lite.dgelsd( m, n, n_rhs, a_real, m, bstar_real,ldb , s, rcond,\n 0,rwork,-1,iwork,0 )\n lrwork = int(rwork[0])\n work = zeros((lwork,), t)\n rwork = zeros((lrwork,), real_t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,rwork,iwork,0 )\n else:\n lapack_routine = lapack_lite.dgelsd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,iwork,0 )\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,iwork,0 )\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge in Linear Least Squares'\n resids = array([],t)\n if one_eq:\n x = ravel(bstar)[:n].copy()\n if (results['rank']==n) and (m>n):\n resids = array([sum((ravel(bstar)[n:])**2)])\n else:\n x = transpose(bstar)[:n,:].copy()\n if (results['rank']==n) and (m>n):\n resids = sum((transpose(bstar)[n:,:])**2).copy()\n return wrap(x),resids,results['rank'],s[:min(n,m)].copy()\n\ndef singular_value_decomposition(A, full_matrices=0):\n return svd(A, full_matrices)\n\ndef eigenvectors(A):\n w, v = eig(A)\n return w, transpose(v)\n\ndef Heigenvectors(A):\n w, v = eigh(A)\n return w, transpose(v)\n\ninv = inverse\nsolve = solve_linear_equations\ncholesky = cholesky_decomposition\neigvals = eigenvalues\neigvalsh = Heigenvalues\npinv = generalized_inverse\ndet = determinant\nlstsq = linear_least_squares\n\nif __name__ == '__main__':\n def test(a, b):\n\n print \"All numbers printed should be (almost) zero:\"\n\n x = solve_linear_equations(a, b)\n check = b - matrixmultiply(a, x)\n print check\n\n\n a_inv = inverse(a)\n check = matrixmultiply(a, a_inv)-identity(a.shape[0])\n print check\n\n\n ev = eigenvalues(a)\n\n evalues, evectors = eig(a)\n check = ev-evalues\n print check\n\n evectors = transpose(evectors)\n check = matrixmultiply(a, evectors)-evectors*evalues\n print check\n\n\n u, s, vt = svd(a,0)\n check = a - matrixmultiply(u*s, vt)\n print check\n\n\n a_ginv = generalized_inverse(a)\n check = matrixmultiply(a, a_ginv)-identity(a.shape[0])\n print check\n\n\n det = determinant(a)\n check = det-multiply.reduce(evalues)\n print check\n\n x, residuals, rank, sv = linear_least_squares(a, b)\n check = b - matrixmultiply(a, x)\n print check\n print rank-a.shape[0]\n print sv-s\n\n a = array([[1.,2.], [3.,4.]])\n b = array([2., 1.])\n test(a, b)\n\n a = a+0j\n b = b+0j\n test(a, b)\n", + "methods": [ + { + "name": "_makearray", + "long_name": "_makearray( a )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a" + ], + "start_line": 32, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_commonType", + "long_name": "_commonType( * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 2, + "token_count": 54, + "parameters": [ + "arrays" + ], + "start_line": 37, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_castCopyAndTranspose", + "long_name": "_castCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 5, + "complexity": 3, + "token_count": 47, + "parameters": [ + "type", + "arrays" + ], + "start_line": 48, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_fastCopyAndTranspose", + "long_name": "_fastCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 11, + "complexity": 4, + "token_count": 72, + "parameters": [ + "type", + "arrays" + ], + "start_line": 59, + "end_line": 69, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_assertRank2", + "long_name": "_assertRank2( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 25, + "parameters": [ + "arrays" + ], + "start_line": 71, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_assertSquareness", + "long_name": "_assertSquareness( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 30, + "parameters": [ + "arrays" + ], + "start_line": 76, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "solve_linear_equations", + "long_name": "solve_linear_equations( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 84, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "inverse", + "long_name": "inverse( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 113, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cholesky_decomposition", + "long_name": "cholesky_decomposition( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 3, + "token_count": 105, + "parameters": [ + "a" + ], + "start_line": 120, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "eigenvalues", + "long_name": "eigenvalues( a )", + "filename": "linalg.py", + "nloc": 39, + "complexity": 4, + "token_count": 363, + "parameters": [ + "a" + ], + "start_line": 139, + "end_line": 177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Heigenvalues", + "long_name": "Heigenvalues( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 34, + "complexity": 3, + "token_count": 345, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 180, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convertarray", + "long_name": "_convertarray( a )", + "filename": "linalg.py", + "nloc": 12, + "complexity": 4, + "token_count": 83, + "parameters": [ + "a" + ], + "start_line": 215, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "eig", + "long_name": "eig( a )", + "filename": "linalg.py", + "nloc": 51, + "complexity": 5, + "token_count": 499, + "parameters": [ + "a" + ], + "start_line": 230, + "end_line": 284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "eigh", + "long_name": "eigh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 3, + "token_count": 362, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 287, + "end_line": 321, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "svd", + "long_name": "svd( a , full_matrices = 1 , compute_uv = 1 )", + "filename": "linalg.py", + "nloc": 59, + "complexity": 8, + "token_count": 539, + "parameters": [ + "a", + "full_matrices", + "compute_uv" + ], + "start_line": 326, + "end_line": 389, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "generalized_inverse", + "long_name": "generalized_inverse( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 393, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "determinant", + "long_name": "determinant( a )", + "filename": "linalg.py", + "nloc": 16, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 411, + "end_line": 426, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "linear_least_squares", + "long_name": "linear_least_squares( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 430, + "end_line": 503, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "singular_value_decomposition", + "long_name": "singular_value_decomposition( A , full_matrices = 0 )", + "filename": "linalg.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "A", + "full_matrices" + ], + "start_line": 505, + "end_line": 506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvectors", + "long_name": "eigenvectors( A )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "A" + ], + "start_line": 508, + "end_line": 510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "Heigenvectors", + "long_name": "Heigenvectors( A )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "A" + ], + "start_line": 512, + "end_line": 514, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "norm", + "long_name": "norm( x , ord = None )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 15, + "token_count": 325, + "parameters": [ + "x", + "ord" + ], + "start_line": 516, + "end_line": 581, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "test", + "long_name": "test( a , b )", + "filename": "linalg.py", + "nloc": 29, + "complexity": 1, + "token_count": 205, + "parameters": [ + "a", + "b" + ], + "start_line": 595, + "end_line": 638, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "_makearray", + "long_name": "_makearray( a )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a" + ], + "start_line": 32, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_commonType", + "long_name": "_commonType( * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 2, + "token_count": 54, + "parameters": [ + "arrays" + ], + "start_line": 37, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_castCopyAndTranspose", + "long_name": "_castCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "type", + "arrays" + ], + "start_line": 48, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "_fastCopyAndTranspose", + "long_name": "_fastCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 11, + "complexity": 4, + "token_count": 72, + "parameters": [ + "type", + "arrays" + ], + "start_line": 62, + "end_line": 72, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_assertRank2", + "long_name": "_assertRank2( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 25, + "parameters": [ + "arrays" + ], + "start_line": 74, + "end_line": 77, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_assertSquareness", + "long_name": "_assertSquareness( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 30, + "parameters": [ + "arrays" + ], + "start_line": 79, + "end_line": 82, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "solve_linear_equations", + "long_name": "solve_linear_equations( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 87, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "inverse", + "long_name": "inverse( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 116, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cholesky_decomposition", + "long_name": "cholesky_decomposition( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 3, + "token_count": 105, + "parameters": [ + "a" + ], + "start_line": 123, + "end_line": 137, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "eigenvalues", + "long_name": "eigenvalues( a )", + "filename": "linalg.py", + "nloc": 39, + "complexity": 4, + "token_count": 363, + "parameters": [ + "a" + ], + "start_line": 142, + "end_line": 180, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Heigenvalues", + "long_name": "Heigenvalues( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 34, + "complexity": 3, + "token_count": 345, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 183, + "end_line": 216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convertarray", + "long_name": "_convertarray( a )", + "filename": "linalg.py", + "nloc": 12, + "complexity": 4, + "token_count": 83, + "parameters": [ + "a" + ], + "start_line": 218, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "eig", + "long_name": "eig( a )", + "filename": "linalg.py", + "nloc": 51, + "complexity": 5, + "token_count": 499, + "parameters": [ + "a" + ], + "start_line": 233, + "end_line": 287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "eigh", + "long_name": "eigh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 3, + "token_count": 362, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 290, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "svd", + "long_name": "svd( a , full_matrices = 1 )", + "filename": "linalg.py", + "nloc": 44, + "complexity": 4, + "token_count": 435, + "parameters": [ + "a", + "full_matrices" + ], + "start_line": 329, + "end_line": 372, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "generalized_inverse", + "long_name": "generalized_inverse( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 377, + "end_line": 391, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "determinant", + "long_name": "determinant( a )", + "filename": "linalg.py", + "nloc": 16, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 395, + "end_line": 410, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "linear_least_squares", + "long_name": "linear_least_squares( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 414, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "singular_value_decomposition", + "long_name": "singular_value_decomposition( A , full_matrices = 0 )", + "filename": "linalg.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "A", + "full_matrices" + ], + "start_line": 489, + "end_line": 490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvectors", + "long_name": "eigenvectors( A )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "A" + ], + "start_line": 492, + "end_line": 494, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "Heigenvectors", + "long_name": "Heigenvectors( A )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "A" + ], + "start_line": 496, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "test", + "long_name": "test( a , b )", + "filename": "linalg.py", + "nloc": 29, + "complexity": 1, + "token_count": 205, + "parameters": [ + "a", + "b" + ], + "start_line": 510, + "end_line": 553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "norm", + "long_name": "norm( x , ord = None )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 15, + "token_count": 325, + "parameters": [ + "x", + "ord" + ], + "start_line": 516, + "end_line": 581, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "_castCopyAndTranspose", + "long_name": "_castCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 5, + "complexity": 3, + "token_count": 47, + "parameters": [ + "type", + "arrays" + ], + "start_line": 48, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "svd", + "long_name": "svd( a , full_matrices = 1 , compute_uv = 1 )", + "filename": "linalg.py", + "nloc": 59, + "complexity": 8, + "token_count": 539, + "parameters": [ + "a", + "full_matrices", + "compute_uv" + ], + "start_line": 326, + "end_line": 389, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "svd", + "long_name": "svd( a , full_matrices = 1 )", + "filename": "linalg.py", + "nloc": 44, + "complexity": 4, + "token_count": 435, + "parameters": [ + "a", + "full_matrices" + ], + "start_line": 329, + "end_line": 372, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + } + ], + "nloc": 508, + "complexity": 88, + "token_count": 4624, + "diff_parsed": { + "added": [ + " 'eigenvectors', 'eig', 'Heigenvectors', 'eigh','lstsq', 'norm',", + " if len(arrays) == 1:", + " return transpose(arrays[0]).astype(type)", + " return [transpose(a).astype(type) for a in arrays]", + "def svd(a, full_matrices=1, compute_uv=1):", + " if compute_uv:", + " if full_matrices:", + " nu = m", + " nvt = n", + " option = 'A'", + " else:", + " nu = min(n,m)", + " nvt = min(n,m)", + " option = 'S'", + " u = zeros((nu, m), t)", + " vt = zeros((n, nvt), t)", + " else:", + " option = 'N'", + " nu = 1", + " nvt = 1", + " u = empty((1,1),t)", + " vt = empty((1,1),t)", + "", + " if option == 'N' and lwork==1:", + " # there seems to be a bug in dgesdd of lapack", + " # (NNemec, 060310)", + " # returning the wrong lwork size for option == 'N'", + " results = lapack_routine('A', m, n, a, m, s, u, m, vt, n,", + " work, -1, iwork, 0)", + " lwork = int(work[0])", + " assert lwork > 1", + "", + " if compute_uv:", + " return wrap(transpose(u)), s, \\", + " wrap(transpose(vt)) # why copy here?", + " else:", + " return s", + "def norm(x, ord=None):", + " \"\"\" norm(x, ord=None) -> n", + "", + " Matrix or vector norm.", + "", + " Inputs:", + "", + " x -- a rank-1 (vector) or rank-2 (matrix) array", + " ord -- the order of the norm.", + "", + " Comments:", + " For arrays of any rank, if ord is None:", + " calculate the square norm (Euclidean norm for vectors, Frobenius norm for matrices)", + "", + " For vectors ord can be any real number including Inf or -Inf.", + " ord = Inf, computes the maximum of the magnitudes", + " ord = -Inf, computes minimum of the magnitudes", + " ord is finite, computes sum(abs(x)**ord)**(1.0/ord)", + "", + " For matrices ord can only be one of the following values:", + " ord = 2 computes the largest singular value", + " ord = -2 computes the smallest singular value", + " ord = 1 computes the largest column sum of absolute values", + " ord = -1 computes the smallest column sum of absolute values", + " ord = Inf computes the largest row sum of absolute values", + " ord = -Inf computes the smallest row sum of absolute values", + " ord = 'fro' computes the frobenius norm sqrt(sum(diag(X.H * X)))", + "", + " For values ord < 0, the result is, strictly speaking, not a", + " mathematical 'norm', but it may still be useful for numerical purposes.", + " \"\"\"", + " x = asarray(x)", + " nd = len(x.shape)", + " if ord is None: # check the default case first and handle it immediately", + " return sqrt(add.reduce((x.conj() * x).ravel().real))", + "", + " if nd == 1:", + " if ord == Inf:", + " return abs(x).max()", + " elif ord == -Inf:", + " return abs(x).min()", + " elif ord == 1:", + " return abs(x).sum() # special case for speedup", + " elif ord == 2:", + " return sqrt(((x.conj()*x).real).sum()) # special case for speedup", + " else:", + " return ((abs(x)**ord).sum())**(1.0/ord)", + " elif nd == 2:", + " if ord == 2:", + " return svd(x,compute_uv=0).max()", + " elif ord == -2:", + " return svd(x,compute_uv=0).min()", + " elif ord == 1:", + " return abs(x).sum(axis=0).max()", + " elif ord == Inf:", + " return abs(x).sum(axis=1).max()", + " elif ord == -1:", + " return abs(x).sum(axis=0).min()", + " elif ord == -Inf:", + " return abs(x).sum(axis=1).min()", + " elif ord in ['fro','f']:", + " return sqrt(add.reduce((x.conj() * x).real.ravel()))", + " else:", + " raise ValueError, \"Invalid norm order for matrices.\"", + " else:", + " raise ValueError, \"Improper number of dimensions to norm.\"", + "", + "", + "" + ], + "deleted": [ + " 'eigenvectors', 'eig', 'Heigenvectors', 'eigh','lstsq',", + " cast_arrays = ()", + " for a in arrays:", + " cast_arrays = cast_arrays + (transpose(a).astype(type),)", + " if len(cast_arrays) == 1:", + " return cast_arrays[0]", + " return cast_arrays", + "def svd(a, full_matrices=1):", + " if full_matrices:", + " nu = m", + " nvt = n", + " option = 'A'", + " else:", + " nu = min(n,m)", + " nvt = min(n,m)", + " option = 'S'", + " u = zeros((nu, m), t)", + " vt = zeros((n, nvt), t)", + " return wrap(transpose(u)), s, \\", + " wrap(transpose(vt)) # why copy here?", + "" + ] + } + } + ] + }, + { + "hash": "db77da02aced7b10bd3fd8306cf66d88a0e8800e", + "msg": "Isolate Numeric compatibility to numpy.linalg.old", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-15T02:53:57+00:00", + "author_timezone": 0, + "committer_date": "2006-03-15T02:53:57+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "9682b2c4abe69d055d7e56c2a53e5e0955e75ab3" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 50, + "insertions": 108, + "lines": 158, + "files": 3, + "dmm_unit_size": 0.9411764705882353, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 0.8823529411764706, + "modified_files": [ + { + "old_path": "numpy/lib/convertcode.py", + "new_path": "numpy/lib/convertcode.py", + "filename": "convertcode.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -99,7 +99,8 @@ def fromstr(filestr):\n filestr, fromall2 = changeimports(filestr, 'numerix', 'numpy')\n filestr, fromall3 = changeimports(filestr, 'numpy_base', 'numpy')\n filestr, fromall3 = changeimports(filestr, 'MLab', 'numpy.lib.mlab')\n- filestr, fromall3 = changeimports(filestr, 'LinearAlgebra', 'numpy.linalg')\n+ filestr, fromall3 = changeimports(filestr, 'LinearAlgebra',\n+ 'numpy.linalg.old')\n filestr, fromall3 = changeimports(filestr, 'RNG', 'numpy.random')\n filestr, fromall3 = changeimports(filestr, 'RandomArray', 'numpy.random')\n filestr, fromall3 = changeimports(filestr, 'FFT', 'numpy.dft')\n", + "added_lines": 2, + "deleted_lines": 1, + "source_code": "\n# This module converts code written for Numeric to run with numpy\n\n# Makes the following changes:\n# * Converts typecharacters\n# * Changes import statements (warns of use of from Numeric import *)\n# * Changes import statements (using numerix) ...\n# * Makes search and replace changes to:\n# - .typecode()\n# - .iscontiguous()\n# - .byteswapped()\n# - .itemsize()\n# * Converts .flat to .ravel() except for .flat = xxx or .flat[xxx]\n# * Change typecode= to dtype=\n# * Eliminates savespace=xxx\n# * Replace xxx.spacesaver() with True\n# * Convert xx.savespace(?) to pass + ## xx.savespace(?)\n# #### -- not * Convert a.shape = ? to a.reshape(?)\n# * Prints warning for use of bool, int, float, copmlex, object, and unicode\n#\n\n__all__ = ['fromfile', 'fromstr']\n\nimport sys\nimport os\nimport re\nimport glob\n\nflatindex_re = re.compile('([.]flat(\\s*?[[=]))')\n\ndef replacetypechars(astr):\n# astr = astr.replace(\"'s'\",\"'h'\")\n# astr = astr.replace(\"'c'\",\"'S1'\")\n astr = astr.replace(\"'b'\",\"'B'\")\n astr = astr.replace(\"'1'\",\"'b'\")\n# astr = astr.replace(\"'w'\",\"'H'\")\n astr = astr.replace(\"'u'\",\"'I'\")\n return astr\n\ndef changeimports(fstr, name, newname):\n importstr = 'import %s' % name\n importasstr = 'import %s as ' % name\n fromstr = 'from %s import ' % name\n fromall=0\n\n fstr = fstr.replace(importasstr, 'import %s as ' % newname)\n fstr = fstr.replace(importstr, 'import %s as %s' % (newname,name))\n\n ind = 0\n Nlen = len(fromstr)\n Nlen2 = len(\"from %s import \" % newname)\n while 1:\n found = fstr.find(fromstr,ind)\n if (found < 0):\n break\n ind = found + Nlen\n if fstr[ind] == '*':\n continue\n fstr = \"%sfrom %s import %s\" % (fstr[:found], newname, fstr[ind:])\n ind += Nlen2 - Nlen\n return fstr, fromall\n\ndef replaceattr(astr):\n astr = astr.replace(\".typecode()\",\".dtype.char\")\n astr = astr.replace(\".iscontiguous()\",\".flags.contiguous\")\n astr = astr.replace(\".byteswapped()\",\".byteswap()\")\n astr = astr.replace(\".toscalar()\", \".item()\")\n astr = astr.replace(\".itemsize()\",\".itemsize\")\n # preserve uses of flat that should be o.k.\n tmpstr = flatindex_re.sub(\"@@@@\\\\2\",astr)\n # replace other uses of flat\n tmpstr = tmpstr.replace(\".flat\",\".ravel()\")\n # put back .flat where it was valid\n astr = tmpstr.replace(\"@@@@\", \".flat\")\n return astr\n\nsvspc = re.compile(r'(\\S+\\s*[(].+),\\s*savespace\\s*=.+\\s*[)]')\nsvspc2 = re.compile(r'([^,(\\s]+[.]spacesaver[(][)])')\nsvspc3 = re.compile(r'(\\S+[.]savespace[(].*[)])')\n#shpe = re.compile(r'(\\S+\\s*)[.]shape\\s*=[^=]\\s*(.+)')\ndef replaceother(astr):\n astr = astr.replace(\"typecode=\",\"dtype=\")\n astr = astr.replace(\"UserArray\",\"ndarray\")\n astr = svspc.sub('\\\\1)',astr)\n astr = svspc2.sub('True',astr)\n astr = svspc3.sub('pass ## \\\\1', astr)\n #astr = shpe.sub('\\\\1=\\\\1.reshape(\\\\2)', astr)\n return astr\n\nimport datetime\ndef fromstr(filestr):\n filestr = replacetypechars(filestr)\n filestr, fromall1 = changeimports(filestr, 'Numeric', 'numpy')\n filestr, fromall1 = changeimports(filestr, 'multiarray',\n 'numpy.core.multiarray')\n filestr, fromall1 = changeimports(filestr, 'umath',\n 'numpy.core.umath')\n filestr, fromall1 = changeimports(filestr, 'Precision', 'numpy')\n filestr, fromall2 = changeimports(filestr, 'numerix', 'numpy')\n filestr, fromall3 = changeimports(filestr, 'numpy_base', 'numpy')\n filestr, fromall3 = changeimports(filestr, 'MLab', 'numpy.lib.mlab')\n filestr, fromall3 = changeimports(filestr, 'LinearAlgebra',\n 'numpy.linalg.old')\n filestr, fromall3 = changeimports(filestr, 'RNG', 'numpy.random')\n filestr, fromall3 = changeimports(filestr, 'RandomArray', 'numpy.random')\n filestr, fromall3 = changeimports(filestr, 'FFT', 'numpy.dft')\n filestr, fromall3 = changeimports(filestr, 'MA', 'numpy.core.ma')\n fromall = fromall1 or fromall2 or fromall3\n filestr = replaceattr(filestr)\n filestr = replaceother(filestr)\n today = datetime.date.today().strftime('%b %d, %Y')\n name = os.path.split(sys.argv[0])[-1]\n filestr = '## Automatically adapted for '\\\n 'numpy %s by %s\\n\\n%s' % (today, name, filestr)\n return filestr\n\ndef makenewfile(name, filestr):\n fid = file(name, 'w')\n fid.write(filestr)\n fid.close()\n\ndef getandcopy(name):\n fid = file(name)\n filestr = fid.read()\n fid.close()\n base, ext = os.path.splitext(name)\n makenewfile(base+'.orig', filestr)\n return filestr\n\ndef convertfile(filename):\n \"\"\"Convert the filename given from using Numeric to using NumPy\n\n Copies the file to filename.orig and then over-writes the file\n with the updated code\n \"\"\"\n filestr = getandcopy(filename)\n filestr = fromstr(filestr)\n makenewfile(filename, filestr)\n\ndef fromargs(args):\n filename = args[1]\n convertfile(filename)\n\ndef convertall(direc=os.path.curdir):\n \"\"\"Convert all .py files to use NumPy (from Numeric) in the directory given\n\n For each file, a backup of .py is made as\n .py.orig. A new file named .py\n is then written with the updated code.\n \"\"\"\n files = glob.glob(os.path.join(direc,'*.py'))\n for afile in files:\n convertfile(afile)\n\nif __name__ == '__main__':\n fromargs(sys.argv)\n", + "source_code_before": "\n# This module converts code written for Numeric to run with numpy\n\n# Makes the following changes:\n# * Converts typecharacters\n# * Changes import statements (warns of use of from Numeric import *)\n# * Changes import statements (using numerix) ...\n# * Makes search and replace changes to:\n# - .typecode()\n# - .iscontiguous()\n# - .byteswapped()\n# - .itemsize()\n# * Converts .flat to .ravel() except for .flat = xxx or .flat[xxx]\n# * Change typecode= to dtype=\n# * Eliminates savespace=xxx\n# * Replace xxx.spacesaver() with True\n# * Convert xx.savespace(?) to pass + ## xx.savespace(?)\n# #### -- not * Convert a.shape = ? to a.reshape(?)\n# * Prints warning for use of bool, int, float, copmlex, object, and unicode\n#\n\n__all__ = ['fromfile', 'fromstr']\n\nimport sys\nimport os\nimport re\nimport glob\n\nflatindex_re = re.compile('([.]flat(\\s*?[[=]))')\n\ndef replacetypechars(astr):\n# astr = astr.replace(\"'s'\",\"'h'\")\n# astr = astr.replace(\"'c'\",\"'S1'\")\n astr = astr.replace(\"'b'\",\"'B'\")\n astr = astr.replace(\"'1'\",\"'b'\")\n# astr = astr.replace(\"'w'\",\"'H'\")\n astr = astr.replace(\"'u'\",\"'I'\")\n return astr\n\ndef changeimports(fstr, name, newname):\n importstr = 'import %s' % name\n importasstr = 'import %s as ' % name\n fromstr = 'from %s import ' % name\n fromall=0\n\n fstr = fstr.replace(importasstr, 'import %s as ' % newname)\n fstr = fstr.replace(importstr, 'import %s as %s' % (newname,name))\n\n ind = 0\n Nlen = len(fromstr)\n Nlen2 = len(\"from %s import \" % newname)\n while 1:\n found = fstr.find(fromstr,ind)\n if (found < 0):\n break\n ind = found + Nlen\n if fstr[ind] == '*':\n continue\n fstr = \"%sfrom %s import %s\" % (fstr[:found], newname, fstr[ind:])\n ind += Nlen2 - Nlen\n return fstr, fromall\n\ndef replaceattr(astr):\n astr = astr.replace(\".typecode()\",\".dtype.char\")\n astr = astr.replace(\".iscontiguous()\",\".flags.contiguous\")\n astr = astr.replace(\".byteswapped()\",\".byteswap()\")\n astr = astr.replace(\".toscalar()\", \".item()\")\n astr = astr.replace(\".itemsize()\",\".itemsize\")\n # preserve uses of flat that should be o.k.\n tmpstr = flatindex_re.sub(\"@@@@\\\\2\",astr)\n # replace other uses of flat\n tmpstr = tmpstr.replace(\".flat\",\".ravel()\")\n # put back .flat where it was valid\n astr = tmpstr.replace(\"@@@@\", \".flat\")\n return astr\n\nsvspc = re.compile(r'(\\S+\\s*[(].+),\\s*savespace\\s*=.+\\s*[)]')\nsvspc2 = re.compile(r'([^,(\\s]+[.]spacesaver[(][)])')\nsvspc3 = re.compile(r'(\\S+[.]savespace[(].*[)])')\n#shpe = re.compile(r'(\\S+\\s*)[.]shape\\s*=[^=]\\s*(.+)')\ndef replaceother(astr):\n astr = astr.replace(\"typecode=\",\"dtype=\")\n astr = astr.replace(\"UserArray\",\"ndarray\")\n astr = svspc.sub('\\\\1)',astr)\n astr = svspc2.sub('True',astr)\n astr = svspc3.sub('pass ## \\\\1', astr)\n #astr = shpe.sub('\\\\1=\\\\1.reshape(\\\\2)', astr)\n return astr\n\nimport datetime\ndef fromstr(filestr):\n filestr = replacetypechars(filestr)\n filestr, fromall1 = changeimports(filestr, 'Numeric', 'numpy')\n filestr, fromall1 = changeimports(filestr, 'multiarray',\n 'numpy.core.multiarray')\n filestr, fromall1 = changeimports(filestr, 'umath',\n 'numpy.core.umath')\n filestr, fromall1 = changeimports(filestr, 'Precision', 'numpy')\n filestr, fromall2 = changeimports(filestr, 'numerix', 'numpy')\n filestr, fromall3 = changeimports(filestr, 'numpy_base', 'numpy')\n filestr, fromall3 = changeimports(filestr, 'MLab', 'numpy.lib.mlab')\n filestr, fromall3 = changeimports(filestr, 'LinearAlgebra', 'numpy.linalg')\n filestr, fromall3 = changeimports(filestr, 'RNG', 'numpy.random')\n filestr, fromall3 = changeimports(filestr, 'RandomArray', 'numpy.random')\n filestr, fromall3 = changeimports(filestr, 'FFT', 'numpy.dft')\n filestr, fromall3 = changeimports(filestr, 'MA', 'numpy.core.ma')\n fromall = fromall1 or fromall2 or fromall3\n filestr = replaceattr(filestr)\n filestr = replaceother(filestr)\n today = datetime.date.today().strftime('%b %d, %Y')\n name = os.path.split(sys.argv[0])[-1]\n filestr = '## Automatically adapted for '\\\n 'numpy %s by %s\\n\\n%s' % (today, name, filestr)\n return filestr\n\ndef makenewfile(name, filestr):\n fid = file(name, 'w')\n fid.write(filestr)\n fid.close()\n\ndef getandcopy(name):\n fid = file(name)\n filestr = fid.read()\n fid.close()\n base, ext = os.path.splitext(name)\n makenewfile(base+'.orig', filestr)\n return filestr\n\ndef convertfile(filename):\n \"\"\"Convert the filename given from using Numeric to using NumPy\n\n Copies the file to filename.orig and then over-writes the file\n with the updated code\n \"\"\"\n filestr = getandcopy(filename)\n filestr = fromstr(filestr)\n makenewfile(filename, filestr)\n\ndef fromargs(args):\n filename = args[1]\n convertfile(filename)\n\ndef convertall(direc=os.path.curdir):\n \"\"\"Convert all .py files to use NumPy (from Numeric) in the directory given\n\n For each file, a backup of .py is made as\n .py.orig. A new file named .py\n is then written with the updated code.\n \"\"\"\n files = glob.glob(os.path.join(direc,'*.py'))\n for afile in files:\n convertfile(afile)\n\nif __name__ == '__main__':\n fromargs(sys.argv)\n", + "methods": [ + { + "name": "replacetypechars", + "long_name": "replacetypechars( astr )", + "filename": "convertcode.py", + "nloc": 5, + "complexity": 1, + "token_count": 37, + "parameters": [ + "astr" + ], + "start_line": 31, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "changeimports", + "long_name": "changeimports( fstr , name , newname )", + "filename": "convertcode.py", + "nloc": 20, + "complexity": 4, + "token_count": 135, + "parameters": [ + "fstr", + "name", + "newname" + ], + "start_line": 40, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "replaceattr", + "long_name": "replaceattr( astr )", + "filename": "convertcode.py", + "nloc": 10, + "complexity": 1, + "token_count": 87, + "parameters": [ + "astr" + ], + "start_line": 63, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "replaceother", + "long_name": "replaceother( astr )", + "filename": "convertcode.py", + "nloc": 7, + "complexity": 1, + "token_count": 57, + "parameters": [ + "astr" + ], + "start_line": 81, + "end_line": 88, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "fromstr", + "long_name": "fromstr( filestr )", + "filename": "convertcode.py", + "nloc": 25, + "complexity": 3, + "token_count": 222, + "parameters": [ + "filestr" + ], + "start_line": 91, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "makenewfile", + "long_name": "makenewfile( name , filestr )", + "filename": "convertcode.py", + "nloc": 4, + "complexity": 1, + "token_count": 26, + "parameters": [ + "name", + "filestr" + ], + "start_line": 117, + "end_line": 120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "getandcopy", + "long_name": "getandcopy( name )", + "filename": "convertcode.py", + "nloc": 7, + "complexity": 1, + "token_count": 45, + "parameters": [ + "name" + ], + "start_line": 122, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "convertfile", + "long_name": "convertfile( filename )", + "filename": "convertcode.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "filename" + ], + "start_line": 130, + "end_line": 138, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "fromargs", + "long_name": "fromargs( args )", + "filename": "convertcode.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "args" + ], + "start_line": 140, + "end_line": 142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "convertall", + "long_name": "convertall( direc = os . path . curdir )", + "filename": "convertcode.py", + "nloc": 4, + "complexity": 2, + "token_count": 38, + "parameters": [ + "direc" + ], + "start_line": 144, + "end_line": 153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "replacetypechars", + "long_name": "replacetypechars( astr )", + "filename": "convertcode.py", + "nloc": 5, + "complexity": 1, + "token_count": 37, + "parameters": [ + "astr" + ], + "start_line": 31, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "changeimports", + "long_name": "changeimports( fstr , name , newname )", + "filename": "convertcode.py", + "nloc": 20, + "complexity": 4, + "token_count": 135, + "parameters": [ + "fstr", + "name", + "newname" + ], + "start_line": 40, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "replaceattr", + "long_name": "replaceattr( astr )", + "filename": "convertcode.py", + "nloc": 10, + "complexity": 1, + "token_count": 87, + "parameters": [ + "astr" + ], + "start_line": 63, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "replaceother", + "long_name": "replaceother( astr )", + "filename": "convertcode.py", + "nloc": 7, + "complexity": 1, + "token_count": 57, + "parameters": [ + "astr" + ], + "start_line": 81, + "end_line": 88, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "fromstr", + "long_name": "fromstr( filestr )", + "filename": "convertcode.py", + "nloc": 24, + "complexity": 3, + "token_count": 222, + "parameters": [ + "filestr" + ], + "start_line": 91, + "end_line": 114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "makenewfile", + "long_name": "makenewfile( name , filestr )", + "filename": "convertcode.py", + "nloc": 4, + "complexity": 1, + "token_count": 26, + "parameters": [ + "name", + "filestr" + ], + "start_line": 116, + "end_line": 119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "getandcopy", + "long_name": "getandcopy( name )", + "filename": "convertcode.py", + "nloc": 7, + "complexity": 1, + "token_count": 45, + "parameters": [ + "name" + ], + "start_line": 121, + "end_line": 127, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "convertfile", + "long_name": "convertfile( filename )", + "filename": "convertcode.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "filename" + ], + "start_line": 129, + "end_line": 137, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "fromargs", + "long_name": "fromargs( args )", + "filename": "convertcode.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "args" + ], + "start_line": 139, + "end_line": 141, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "convertall", + "long_name": "convertall( direc = os . path . curdir )", + "filename": "convertcode.py", + "nloc": 4, + "complexity": 2, + "token_count": 38, + "parameters": [ + "direc" + ], + "start_line": 143, + "end_line": 152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "fromstr", + "long_name": "fromstr( filestr )", + "filename": "convertcode.py", + "nloc": 25, + "complexity": 3, + "token_count": 222, + "parameters": [ + "filestr" + ], + "start_line": 91, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + } + ], + "nloc": 101, + "complexity": 16, + "token_count": 759, + "diff_parsed": { + "added": [ + " filestr, fromall3 = changeimports(filestr, 'LinearAlgebra',", + " 'numpy.linalg.old')" + ], + "deleted": [ + " filestr, fromall3 = changeimports(filestr, 'LinearAlgebra', 'numpy.linalg')" + ] + } + }, + { + "old_path": "numpy/linalg/linalg.py", + "new_path": "numpy/linalg/linalg.py", + "filename": "linalg.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -6,22 +6,18 @@\n # only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n # zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n \n-__all__ = ['LinAlgError', 'solve_linear_equations', 'solve',\n- 'inverse', 'inv', 'cholesky_decomposition', 'cholesky', 'eigenvalues',\n- 'eigvals', 'Heigenvalues', 'eigvalsh', 'generalized_inverse', 'pinv',\n- 'determinant', 'det', 'singular_value_decomposition', 'svd',\n- 'eigenvectors', 'eig', 'Heigenvectors', 'eigh','lstsq', 'norm',\n- 'linear_least_squares'\n+__all__ = ['solve',\n+ 'inv', 'cholesky',\n+ 'eigvals',\n+ 'eigvalsh', 'pinv',\n+ 'det', 'svd',\n+ 'eig', 'eigh','lstsq', 'norm',\n ]\n \n from numpy.core import *\n from numpy.lib import *\n import lapack_lite\n \n-# Error object\n-class LinAlgError(Exception):\n- pass\n-\n # Helper routines\n _lapack_type = {'f': 0, 'd': 1, 'F': 2, 'D': 3}\n _lapack_letter = ['s', 'd', 'c', 'z']\n@@ -78,10 +74,9 @@ def _assertSquareness(*arrays):\n if max(a.shape) != min(a.shape):\n raise LinAlgError, 'Array must be square'\n \n-\n # Linear equations\n \n-def solve_linear_equations(a, b):\n+def solve(a, b):\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n@@ -110,14 +105,13 @@ def solve_linear_equations(a, b):\n \n # Matrix inversion\n \n-def inverse(a):\n+def inv(a):\n a, wrap = _makearray(a)\n return wrap(solve_linear_equations(a, identity(a.shape[0])))\n \n-\n # Cholesky decomposition\n \n-def cholesky_decomposition(a):\n+def cholesky(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n@@ -135,8 +129,7 @@ def cholesky_decomposition(a):\n \n \n # Eigenvalues\n-\n-def eigenvalues(a):\n+def eigvals(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n@@ -177,7 +170,7 @@ def eigenvalues(a):\n return w\n \n \n-def Heigenvalues(a, UPLO='L'):\n+def eigvalsh(a, UPLO='L'):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n@@ -390,7 +383,7 @@ def svd(a, full_matrices=1, compute_uv=1):\n \n # Generalized inverse\n \n-def generalized_inverse(a, rcond = 1.e-10):\n+def pinv(a, rcond = 1.e-10):\n a, wrap = _makearray(a)\n if a.dtype.char in typecodes['Complex']:\n a = conjugate(a)\n@@ -408,7 +401,7 @@ def generalized_inverse(a, rcond = 1.e-10):\n \n # Determinant\n \n-def determinant(a):\n+def det(a):\n a = asarray(a)\n _assertRank2(a)\n _assertSquareness(a)\n@@ -427,7 +420,7 @@ def determinant(a):\n \n # Linear Least Squares\n \n-def linear_least_squares(a, b, rcond=1.e-10):\n+def lstsq(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\n where x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n@@ -502,17 +495,6 @@ def linear_least_squares(a, b, rcond=1.e-10):\n resids = sum((transpose(bstar)[n:,:])**2).copy()\n return wrap(x),resids,results['rank'],s[:min(n,m)].copy()\n \n-def singular_value_decomposition(A, full_matrices=0):\n- return svd(A, full_matrices)\n-\n-def eigenvectors(A):\n- w, v = eig(A)\n- return w, transpose(v)\n-\n-def Heigenvectors(A):\n- w, v = eigh(A)\n- return w, transpose(v)\n-\n def norm(x, ord=None):\n \"\"\" norm(x, ord=None) -> n\n \n@@ -580,33 +562,22 @@ def norm(x, ord=None):\n else:\n raise ValueError, \"Improper number of dimensions to norm.\"\n \n-\n-\n-inv = inverse\n-solve = solve_linear_equations\n-cholesky = cholesky_decomposition\n-eigvals = eigenvalues\n-eigvalsh = Heigenvalues\n-pinv = generalized_inverse\n-det = determinant\n-lstsq = linear_least_squares\n-\n if __name__ == '__main__':\n def test(a, b):\n \n print \"All numbers printed should be (almost) zero:\"\n \n- x = solve_linear_equations(a, b)\n+ x = solve(a, b)\n check = b - matrixmultiply(a, x)\n print check\n \n \n- a_inv = inverse(a)\n+ a_inv = inv(a)\n check = matrixmultiply(a, a_inv)-identity(a.shape[0])\n print check\n \n \n- ev = eigenvalues(a)\n+ ev = eigvals(a)\n \n evalues, evectors = eig(a)\n check = ev-evalues\n@@ -622,16 +593,16 @@ def test(a, b):\n print check\n \n \n- a_ginv = generalized_inverse(a)\n+ a_ginv = pinv(a)\n check = matrixmultiply(a, a_ginv)-identity(a.shape[0])\n print check\n \n \n- det = determinant(a)\n+ det = det(a)\n check = det-multiply.reduce(evalues)\n print check\n \n- x, residuals, rank, sv = linear_least_squares(a, b)\n+ x, residuals, rank, sv = lstsq(a, b)\n check = b - matrixmultiply(a, x)\n print check\n print rank-a.shape[0]\n", + "added_lines": 20, + "deleted_lines": 49, + "source_code": "\n\"\"\"Lite version of scipy.linalg.\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n__all__ = ['solve',\n 'inv', 'cholesky',\n 'eigvals',\n 'eigvalsh', 'pinv',\n 'det', 'svd',\n 'eig', 'eigh','lstsq', 'norm',\n ]\n\nfrom numpy.core import *\nfrom numpy.lib import *\nimport lapack_lite\n\n# Helper routines\n_lapack_type = {'f': 0, 'd': 1, 'F': 2, 'D': 3}\n_lapack_letter = ['s', 'd', 'c', 'z']\n_array_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\n_array_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\n_array_type = [['f', 'd'], ['F', 'D']]\n\ndef _makearray(a):\n new = asarray(a)\n wrap = getattr(a, \"__array_wrap__\", new.__array_wrap__)\n return new, wrap\n\ndef _commonType(*arrays):\n kind = 0\n# precision = 0\n# force higher precision in lite version\n precision = 1\n for a in arrays:\n t = a.dtype.char\n kind = max(kind, _array_kind[t])\n precision = max(precision, _array_precision[t])\n return _array_type[kind][precision]\n\ndef _castCopyAndTranspose(type, *arrays):\n if len(arrays) == 1:\n return transpose(arrays[0]).astype(type)\n else:\n return [transpose(a).astype(type) for a in arrays]\n\n# _fastCopyAndTranpose is an optimized version of _castCopyAndTranspose.\n# It assumes the input is 2D (as all the calls in here are).\n\n_fastCT = fastCopyAndTranspose\n\ndef _fastCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.dtype.char == type:\n cast_arrays = cast_arrays + (_fastCT(a),)\n else:\n cast_arrays = cast_arrays + (_fastCT(a.astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\ndef _assertRank2(*arrays):\n for a in arrays:\n if len(a.shape) != 2:\n raise LinAlgError, 'Array must be two-dimensional'\n\ndef _assertSquareness(*arrays):\n for a in arrays:\n if max(a.shape) != min(a.shape):\n raise LinAlgError, 'Array must be square'\n\n# Linear equations\n\ndef solve(a, b):\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n _assertSquareness(a)\n n_eq = a.shape[0]\n n_rhs = b.shape[1]\n if n_eq != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n# lapack_routine = _findLapackRoutine('gesv', t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesv\n else:\n lapack_routine = lapack_lite.dgesv\n a, b = _fastCopyAndTranspose(t, a, b)\n pivots = zeros(n_eq, 'i')\n results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Singular matrix'\n if one_eq:\n return ravel(b) # I see no need to copy here\n else:\n return transpose(b) # no need to copy\n\n\n# Matrix inversion\n\ndef inv(a):\n a, wrap = _makearray(a)\n return wrap(solve_linear_equations(a, identity(a.shape[0])))\n\n# Cholesky decomposition\n\ndef cholesky(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _castCopyAndTranspose(t, a)\n m = a.shape[0]\n n = a.shape[1]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zpotrf\n else:\n lapack_routine = lapack_lite.dpotrf\n results = lapack_routine('L', n, a, m, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Matrix is not positive definite - Cholesky decomposition cannot be computed'\n return transpose(triu(a,k=0)).copy()\n\n\n# Eigenvalues\ndef eigvals(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n dummy = zeros((1,), t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n rwork = zeros((n,),real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n else:\n w = wr+1j*wi\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\n\ndef eigvalsh(a, UPLO='L'):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\ndef _convertarray(a):\n if issubclass(a.dtype.type, complexfloating):\n if a.dtype.char == 'D':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('D'))\n else:\n if a.dtype.char == 'd':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('d'))\n return a, a.dtype.char\n\n# Eigenvectors\n\ndef eig(a):\n \"\"\"eig(a) returns u,v where u is the eigenvalues and\nv is a matrix of eigenvectors with vector v[:,i] corresponds to\neigenvalue u[i]. Satisfies the equation dot(a, v[:,i]) = u[i]*v[:,i]\n\"\"\"\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n a,t = _convertarray(a) # convert to float_ or complex_ type\n real_t = 'd'\n n = a.shape[0]\n dummy = zeros((1,), t)\n if t == 'D': # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n v = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n rwork = zeros((2*n,),real_t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n vr = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n v = vr\n else:\n w = wr+1j*wi\n v = array(vr,Complex)\n ind = nonzero(\n equal(\n equal(wi,0.0) # true for real e-vals\n ,0) # true for complex e-vals\n ) # indices of complex e-vals\n for i in range(len(ind)/2):\n v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]]\n v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]]\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(v.transpose())\n\n\ndef eigh(a, UPLO='L'):\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(a.transpose())\n\n\n# Singular value decomposition\n\ndef svd(a, full_matrices=1, compute_uv=1):\n a, wrap = _makearray(a)\n _assertRank2(a)\n m, n = a.shape\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n s = zeros((min(n,m),), real_t)\n if compute_uv:\n if full_matrices:\n nu = m\n nvt = n\n option = 'A'\n else:\n nu = min(n,m)\n nvt = min(n,m)\n option = 'S'\n u = zeros((nu, m), t)\n vt = zeros((n, nvt), t)\n else:\n option = 'N'\n nu = 1\n nvt = 1\n u = empty((1,1),t) \n vt = empty((1,1),t) \n\n iwork = zeros((8*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesdd\n rwork = zeros((5*min(m,n)*min(m,n) + 5*min(m,n),), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, rwork, iwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, rwork, iwork, 0)\n else:\n lapack_routine = lapack_lite.dgesdd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, iwork, 0)\n lwork = int(work[0])\n if option == 'N' and lwork==1:\n # there seems to be a bug in dgesdd of lapack\n # (NNemec, 060310)\n # returning the wrong lwork size for option == 'N'\n results = lapack_routine('A', m, n, a, m, s, u, m, vt, n,\n work, -1, iwork, 0)\n lwork = int(work[0])\n assert lwork > 1\n\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, iwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge'\n if compute_uv:\n return wrap(transpose(u)), s, \\\n wrap(transpose(vt)) # why copy here?\n else:\n return s\n\n# Generalized inverse\n\ndef pinv(a, rcond = 1.e-10):\n a, wrap = _makearray(a)\n if a.dtype.char in typecodes['Complex']:\n a = conjugate(a)\n u, s, vt = svd(a, 0)\n m = u.shape[0]\n n = vt.shape[1]\n cutoff = rcond*maximum.reduce(s)\n for i in range(min(n,m)):\n if s[i] > cutoff:\n s[i] = 1./s[i]\n else:\n s[i] = 0.;\n return wrap(dot(transpose(vt),\n multiply(s[:, NewAxis],transpose(u))))\n\n# Determinant\n\ndef det(a):\n a = asarray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zgetrf\n else:\n lapack_routine = lapack_lite.dgetrf\n pivots = zeros((n,), 'i')\n results = lapack_routine(n, n, a, n, pivots, 0)\n sign = add.reduce(not_equal(pivots,\n arrayrange(1, n+1))) % 2\n return (1.-2.*sign)*multiply.reduce(diagonal(a),axis=-1)\n\n# Linear Least Squares\n\ndef lstsq(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n import math\n a = asarray(a)\n b, wrap = _makearray(b)\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n m = a.shape[0]\n n = a.shape[1]\n n_rhs = b.shape[1]\n ldb = max(n,m)\n if m != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n real_t = _array_type[0][_array_precision[t]]\n bstar = zeros((ldb,n_rhs),t)\n bstar[:b.shape[0],:n_rhs] = b.copy()\n a,bstar = _castCopyAndTranspose(t, a, bstar)\n s = zeros((min(m,n),),real_t)\n nlvl = max( 0, int( math.log( float(min( m,n ))/2. ) ) + 1 )\n iwork = zeros((3*min(m,n)*nlvl+11*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgelsd\n lwork = 1\n rwork = zeros((lwork,), real_t)\n work = zeros((lwork,),t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,rwork,iwork,0 )\n lwork = int(abs(work[0]))\n rwork = zeros((lwork,),real_t)\n a_real = zeros((m,n),real_t)\n bstar_real = zeros((ldb,n_rhs,),real_t)\n results = lapack_lite.dgelsd( m, n, n_rhs, a_real, m, bstar_real,ldb , s, rcond,\n 0,rwork,-1,iwork,0 )\n lrwork = int(rwork[0])\n work = zeros((lwork,), t)\n rwork = zeros((lrwork,), real_t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,rwork,iwork,0 )\n else:\n lapack_routine = lapack_lite.dgelsd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,iwork,0 )\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,iwork,0 )\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge in Linear Least Squares'\n resids = array([],t)\n if one_eq:\n x = ravel(bstar)[:n].copy()\n if (results['rank']==n) and (m>n):\n resids = array([sum((ravel(bstar)[n:])**2)])\n else:\n x = transpose(bstar)[:n,:].copy()\n if (results['rank']==n) and (m>n):\n resids = sum((transpose(bstar)[n:,:])**2).copy()\n return wrap(x),resids,results['rank'],s[:min(n,m)].copy()\n\ndef norm(x, ord=None):\n \"\"\" norm(x, ord=None) -> n\n\n Matrix or vector norm.\n\n Inputs:\n\n x -- a rank-1 (vector) or rank-2 (matrix) array\n ord -- the order of the norm.\n\n Comments:\n For arrays of any rank, if ord is None:\n calculate the square norm (Euclidean norm for vectors, Frobenius norm for matrices)\n\n For vectors ord can be any real number including Inf or -Inf.\n ord = Inf, computes the maximum of the magnitudes\n ord = -Inf, computes minimum of the magnitudes\n ord is finite, computes sum(abs(x)**ord)**(1.0/ord)\n\n For matrices ord can only be one of the following values:\n ord = 2 computes the largest singular value\n ord = -2 computes the smallest singular value\n ord = 1 computes the largest column sum of absolute values\n ord = -1 computes the smallest column sum of absolute values\n ord = Inf computes the largest row sum of absolute values\n ord = -Inf computes the smallest row sum of absolute values\n ord = 'fro' computes the frobenius norm sqrt(sum(diag(X.H * X)))\n\n For values ord < 0, the result is, strictly speaking, not a\n mathematical 'norm', but it may still be useful for numerical purposes.\n \"\"\"\n x = asarray(x)\n nd = len(x.shape) \n if ord is None: # check the default case first and handle it immediately\n return sqrt(add.reduce((x.conj() * x).ravel().real))\n\n if nd == 1:\n if ord == Inf:\n return abs(x).max()\n elif ord == -Inf:\n return abs(x).min()\n elif ord == 1:\n return abs(x).sum() # special case for speedup\n elif ord == 2:\n return sqrt(((x.conj()*x).real).sum()) # special case for speedup\n else:\n return ((abs(x)**ord).sum())**(1.0/ord)\n elif nd == 2:\n if ord == 2:\n return svd(x,compute_uv=0).max()\n elif ord == -2:\n return svd(x,compute_uv=0).min()\n elif ord == 1:\n return abs(x).sum(axis=0).max()\n elif ord == Inf:\n return abs(x).sum(axis=1).max()\n elif ord == -1:\n return abs(x).sum(axis=0).min()\n elif ord == -Inf:\n return abs(x).sum(axis=1).min()\n elif ord in ['fro','f']:\n return sqrt(add.reduce((x.conj() * x).real.ravel()))\n else:\n raise ValueError, \"Invalid norm order for matrices.\"\n else:\n raise ValueError, \"Improper number of dimensions to norm.\"\n\nif __name__ == '__main__':\n def test(a, b):\n\n print \"All numbers printed should be (almost) zero:\"\n\n x = solve(a, b)\n check = b - matrixmultiply(a, x)\n print check\n\n\n a_inv = inv(a)\n check = matrixmultiply(a, a_inv)-identity(a.shape[0])\n print check\n\n\n ev = eigvals(a)\n\n evalues, evectors = eig(a)\n check = ev-evalues\n print check\n\n evectors = transpose(evectors)\n check = matrixmultiply(a, evectors)-evectors*evalues\n print check\n\n\n u, s, vt = svd(a,0)\n check = a - matrixmultiply(u*s, vt)\n print check\n\n\n a_ginv = pinv(a)\n check = matrixmultiply(a, a_ginv)-identity(a.shape[0])\n print check\n\n\n det = det(a)\n check = det-multiply.reduce(evalues)\n print check\n\n x, residuals, rank, sv = lstsq(a, b)\n check = b - matrixmultiply(a, x)\n print check\n print rank-a.shape[0]\n print sv-s\n\n a = array([[1.,2.], [3.,4.]])\n b = array([2., 1.])\n test(a, b)\n\n a = a+0j\n b = b+0j\n test(a, b)\n", + "source_code_before": "\n\"\"\"Lite version of scipy.linalg.\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n__all__ = ['LinAlgError', 'solve_linear_equations', 'solve',\n 'inverse', 'inv', 'cholesky_decomposition', 'cholesky', 'eigenvalues',\n 'eigvals', 'Heigenvalues', 'eigvalsh', 'generalized_inverse', 'pinv',\n 'determinant', 'det', 'singular_value_decomposition', 'svd',\n 'eigenvectors', 'eig', 'Heigenvectors', 'eigh','lstsq', 'norm',\n 'linear_least_squares'\n ]\n\nfrom numpy.core import *\nfrom numpy.lib import *\nimport lapack_lite\n\n# Error object\nclass LinAlgError(Exception):\n pass\n\n# Helper routines\n_lapack_type = {'f': 0, 'd': 1, 'F': 2, 'D': 3}\n_lapack_letter = ['s', 'd', 'c', 'z']\n_array_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\n_array_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\n_array_type = [['f', 'd'], ['F', 'D']]\n\ndef _makearray(a):\n new = asarray(a)\n wrap = getattr(a, \"__array_wrap__\", new.__array_wrap__)\n return new, wrap\n\ndef _commonType(*arrays):\n kind = 0\n# precision = 0\n# force higher precision in lite version\n precision = 1\n for a in arrays:\n t = a.dtype.char\n kind = max(kind, _array_kind[t])\n precision = max(precision, _array_precision[t])\n return _array_type[kind][precision]\n\ndef _castCopyAndTranspose(type, *arrays):\n if len(arrays) == 1:\n return transpose(arrays[0]).astype(type)\n else:\n return [transpose(a).astype(type) for a in arrays]\n\n# _fastCopyAndTranpose is an optimized version of _castCopyAndTranspose.\n# It assumes the input is 2D (as all the calls in here are).\n\n_fastCT = fastCopyAndTranspose\n\ndef _fastCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.dtype.char == type:\n cast_arrays = cast_arrays + (_fastCT(a),)\n else:\n cast_arrays = cast_arrays + (_fastCT(a.astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\ndef _assertRank2(*arrays):\n for a in arrays:\n if len(a.shape) != 2:\n raise LinAlgError, 'Array must be two-dimensional'\n\ndef _assertSquareness(*arrays):\n for a in arrays:\n if max(a.shape) != min(a.shape):\n raise LinAlgError, 'Array must be square'\n\n\n# Linear equations\n\ndef solve_linear_equations(a, b):\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n _assertSquareness(a)\n n_eq = a.shape[0]\n n_rhs = b.shape[1]\n if n_eq != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n# lapack_routine = _findLapackRoutine('gesv', t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesv\n else:\n lapack_routine = lapack_lite.dgesv\n a, b = _fastCopyAndTranspose(t, a, b)\n pivots = zeros(n_eq, 'i')\n results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Singular matrix'\n if one_eq:\n return ravel(b) # I see no need to copy here\n else:\n return transpose(b) # no need to copy\n\n\n# Matrix inversion\n\ndef inverse(a):\n a, wrap = _makearray(a)\n return wrap(solve_linear_equations(a, identity(a.shape[0])))\n\n\n# Cholesky decomposition\n\ndef cholesky_decomposition(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _castCopyAndTranspose(t, a)\n m = a.shape[0]\n n = a.shape[1]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zpotrf\n else:\n lapack_routine = lapack_lite.dpotrf\n results = lapack_routine('L', n, a, m, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Matrix is not positive definite - Cholesky decomposition cannot be computed'\n return transpose(triu(a,k=0)).copy()\n\n\n# Eigenvalues\n\ndef eigenvalues(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n dummy = zeros((1,), t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n rwork = zeros((n,),real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n else:\n w = wr+1j*wi\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\n\ndef Heigenvalues(a, UPLO='L'):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\ndef _convertarray(a):\n if issubclass(a.dtype.type, complexfloating):\n if a.dtype.char == 'D':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('D'))\n else:\n if a.dtype.char == 'd':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('d'))\n return a, a.dtype.char\n\n# Eigenvectors\n\ndef eig(a):\n \"\"\"eig(a) returns u,v where u is the eigenvalues and\nv is a matrix of eigenvectors with vector v[:,i] corresponds to\neigenvalue u[i]. Satisfies the equation dot(a, v[:,i]) = u[i]*v[:,i]\n\"\"\"\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n a,t = _convertarray(a) # convert to float_ or complex_ type\n real_t = 'd'\n n = a.shape[0]\n dummy = zeros((1,), t)\n if t == 'D': # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n v = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n rwork = zeros((2*n,),real_t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n vr = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n v = vr\n else:\n w = wr+1j*wi\n v = array(vr,Complex)\n ind = nonzero(\n equal(\n equal(wi,0.0) # true for real e-vals\n ,0) # true for complex e-vals\n ) # indices of complex e-vals\n for i in range(len(ind)/2):\n v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]]\n v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]]\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(v.transpose())\n\n\ndef eigh(a, UPLO='L'):\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(a.transpose())\n\n\n# Singular value decomposition\n\ndef svd(a, full_matrices=1, compute_uv=1):\n a, wrap = _makearray(a)\n _assertRank2(a)\n m, n = a.shape\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n s = zeros((min(n,m),), real_t)\n if compute_uv:\n if full_matrices:\n nu = m\n nvt = n\n option = 'A'\n else:\n nu = min(n,m)\n nvt = min(n,m)\n option = 'S'\n u = zeros((nu, m), t)\n vt = zeros((n, nvt), t)\n else:\n option = 'N'\n nu = 1\n nvt = 1\n u = empty((1,1),t) \n vt = empty((1,1),t) \n\n iwork = zeros((8*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesdd\n rwork = zeros((5*min(m,n)*min(m,n) + 5*min(m,n),), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, rwork, iwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, rwork, iwork, 0)\n else:\n lapack_routine = lapack_lite.dgesdd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, iwork, 0)\n lwork = int(work[0])\n if option == 'N' and lwork==1:\n # there seems to be a bug in dgesdd of lapack\n # (NNemec, 060310)\n # returning the wrong lwork size for option == 'N'\n results = lapack_routine('A', m, n, a, m, s, u, m, vt, n,\n work, -1, iwork, 0)\n lwork = int(work[0])\n assert lwork > 1\n\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, iwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge'\n if compute_uv:\n return wrap(transpose(u)), s, \\\n wrap(transpose(vt)) # why copy here?\n else:\n return s\n\n# Generalized inverse\n\ndef generalized_inverse(a, rcond = 1.e-10):\n a, wrap = _makearray(a)\n if a.dtype.char in typecodes['Complex']:\n a = conjugate(a)\n u, s, vt = svd(a, 0)\n m = u.shape[0]\n n = vt.shape[1]\n cutoff = rcond*maximum.reduce(s)\n for i in range(min(n,m)):\n if s[i] > cutoff:\n s[i] = 1./s[i]\n else:\n s[i] = 0.;\n return wrap(dot(transpose(vt),\n multiply(s[:, NewAxis],transpose(u))))\n\n# Determinant\n\ndef determinant(a):\n a = asarray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zgetrf\n else:\n lapack_routine = lapack_lite.dgetrf\n pivots = zeros((n,), 'i')\n results = lapack_routine(n, n, a, n, pivots, 0)\n sign = add.reduce(not_equal(pivots,\n arrayrange(1, n+1))) % 2\n return (1.-2.*sign)*multiply.reduce(diagonal(a),axis=-1)\n\n# Linear Least Squares\n\ndef linear_least_squares(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n import math\n a = asarray(a)\n b, wrap = _makearray(b)\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n m = a.shape[0]\n n = a.shape[1]\n n_rhs = b.shape[1]\n ldb = max(n,m)\n if m != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n real_t = _array_type[0][_array_precision[t]]\n bstar = zeros((ldb,n_rhs),t)\n bstar[:b.shape[0],:n_rhs] = b.copy()\n a,bstar = _castCopyAndTranspose(t, a, bstar)\n s = zeros((min(m,n),),real_t)\n nlvl = max( 0, int( math.log( float(min( m,n ))/2. ) ) + 1 )\n iwork = zeros((3*min(m,n)*nlvl+11*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgelsd\n lwork = 1\n rwork = zeros((lwork,), real_t)\n work = zeros((lwork,),t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,rwork,iwork,0 )\n lwork = int(abs(work[0]))\n rwork = zeros((lwork,),real_t)\n a_real = zeros((m,n),real_t)\n bstar_real = zeros((ldb,n_rhs,),real_t)\n results = lapack_lite.dgelsd( m, n, n_rhs, a_real, m, bstar_real,ldb , s, rcond,\n 0,rwork,-1,iwork,0 )\n lrwork = int(rwork[0])\n work = zeros((lwork,), t)\n rwork = zeros((lrwork,), real_t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,rwork,iwork,0 )\n else:\n lapack_routine = lapack_lite.dgelsd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,iwork,0 )\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,iwork,0 )\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge in Linear Least Squares'\n resids = array([],t)\n if one_eq:\n x = ravel(bstar)[:n].copy()\n if (results['rank']==n) and (m>n):\n resids = array([sum((ravel(bstar)[n:])**2)])\n else:\n x = transpose(bstar)[:n,:].copy()\n if (results['rank']==n) and (m>n):\n resids = sum((transpose(bstar)[n:,:])**2).copy()\n return wrap(x),resids,results['rank'],s[:min(n,m)].copy()\n\ndef singular_value_decomposition(A, full_matrices=0):\n return svd(A, full_matrices)\n\ndef eigenvectors(A):\n w, v = eig(A)\n return w, transpose(v)\n\ndef Heigenvectors(A):\n w, v = eigh(A)\n return w, transpose(v)\n\ndef norm(x, ord=None):\n \"\"\" norm(x, ord=None) -> n\n\n Matrix or vector norm.\n\n Inputs:\n\n x -- a rank-1 (vector) or rank-2 (matrix) array\n ord -- the order of the norm.\n\n Comments:\n For arrays of any rank, if ord is None:\n calculate the square norm (Euclidean norm for vectors, Frobenius norm for matrices)\n\n For vectors ord can be any real number including Inf or -Inf.\n ord = Inf, computes the maximum of the magnitudes\n ord = -Inf, computes minimum of the magnitudes\n ord is finite, computes sum(abs(x)**ord)**(1.0/ord)\n\n For matrices ord can only be one of the following values:\n ord = 2 computes the largest singular value\n ord = -2 computes the smallest singular value\n ord = 1 computes the largest column sum of absolute values\n ord = -1 computes the smallest column sum of absolute values\n ord = Inf computes the largest row sum of absolute values\n ord = -Inf computes the smallest row sum of absolute values\n ord = 'fro' computes the frobenius norm sqrt(sum(diag(X.H * X)))\n\n For values ord < 0, the result is, strictly speaking, not a\n mathematical 'norm', but it may still be useful for numerical purposes.\n \"\"\"\n x = asarray(x)\n nd = len(x.shape) \n if ord is None: # check the default case first and handle it immediately\n return sqrt(add.reduce((x.conj() * x).ravel().real))\n\n if nd == 1:\n if ord == Inf:\n return abs(x).max()\n elif ord == -Inf:\n return abs(x).min()\n elif ord == 1:\n return abs(x).sum() # special case for speedup\n elif ord == 2:\n return sqrt(((x.conj()*x).real).sum()) # special case for speedup\n else:\n return ((abs(x)**ord).sum())**(1.0/ord)\n elif nd == 2:\n if ord == 2:\n return svd(x,compute_uv=0).max()\n elif ord == -2:\n return svd(x,compute_uv=0).min()\n elif ord == 1:\n return abs(x).sum(axis=0).max()\n elif ord == Inf:\n return abs(x).sum(axis=1).max()\n elif ord == -1:\n return abs(x).sum(axis=0).min()\n elif ord == -Inf:\n return abs(x).sum(axis=1).min()\n elif ord in ['fro','f']:\n return sqrt(add.reduce((x.conj() * x).real.ravel()))\n else:\n raise ValueError, \"Invalid norm order for matrices.\"\n else:\n raise ValueError, \"Improper number of dimensions to norm.\"\n\n\n\ninv = inverse\nsolve = solve_linear_equations\ncholesky = cholesky_decomposition\neigvals = eigenvalues\neigvalsh = Heigenvalues\npinv = generalized_inverse\ndet = determinant\nlstsq = linear_least_squares\n\nif __name__ == '__main__':\n def test(a, b):\n\n print \"All numbers printed should be (almost) zero:\"\n\n x = solve_linear_equations(a, b)\n check = b - matrixmultiply(a, x)\n print check\n\n\n a_inv = inverse(a)\n check = matrixmultiply(a, a_inv)-identity(a.shape[0])\n print check\n\n\n ev = eigenvalues(a)\n\n evalues, evectors = eig(a)\n check = ev-evalues\n print check\n\n evectors = transpose(evectors)\n check = matrixmultiply(a, evectors)-evectors*evalues\n print check\n\n\n u, s, vt = svd(a,0)\n check = a - matrixmultiply(u*s, vt)\n print check\n\n\n a_ginv = generalized_inverse(a)\n check = matrixmultiply(a, a_ginv)-identity(a.shape[0])\n print check\n\n\n det = determinant(a)\n check = det-multiply.reduce(evalues)\n print check\n\n x, residuals, rank, sv = linear_least_squares(a, b)\n check = b - matrixmultiply(a, x)\n print check\n print rank-a.shape[0]\n print sv-s\n\n a = array([[1.,2.], [3.,4.]])\n b = array([2., 1.])\n test(a, b)\n\n a = a+0j\n b = b+0j\n test(a, b)\n", + "methods": [ + { + "name": "_makearray", + "long_name": "_makearray( a )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a" + ], + "start_line": 28, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_commonType", + "long_name": "_commonType( * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 2, + "token_count": 54, + "parameters": [ + "arrays" + ], + "start_line": 33, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_castCopyAndTranspose", + "long_name": "_castCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 5, + "complexity": 3, + "token_count": 47, + "parameters": [ + "type", + "arrays" + ], + "start_line": 44, + "end_line": 48, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_fastCopyAndTranspose", + "long_name": "_fastCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 11, + "complexity": 4, + "token_count": 72, + "parameters": [ + "type", + "arrays" + ], + "start_line": 55, + "end_line": 65, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_assertRank2", + "long_name": "_assertRank2( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 25, + "parameters": [ + "arrays" + ], + "start_line": 67, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_assertSquareness", + "long_name": "_assertSquareness( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 30, + "parameters": [ + "arrays" + ], + "start_line": 72, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "solve", + "long_name": "solve( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 79, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "inv", + "long_name": "inv( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 108, + "end_line": 110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cholesky", + "long_name": "cholesky( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 3, + "token_count": 105, + "parameters": [ + "a" + ], + "start_line": 114, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "eigvals", + "long_name": "eigvals( a )", + "filename": "linalg.py", + "nloc": 39, + "complexity": 4, + "token_count": 363, + "parameters": [ + "a" + ], + "start_line": 132, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "eigvalsh", + "long_name": "eigvalsh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 34, + "complexity": 3, + "token_count": 345, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 173, + "end_line": 206, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convertarray", + "long_name": "_convertarray( a )", + "filename": "linalg.py", + "nloc": 12, + "complexity": 4, + "token_count": 83, + "parameters": [ + "a" + ], + "start_line": 208, + "end_line": 219, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "eig", + "long_name": "eig( a )", + "filename": "linalg.py", + "nloc": 51, + "complexity": 5, + "token_count": 499, + "parameters": [ + "a" + ], + "start_line": 223, + "end_line": 277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "eigh", + "long_name": "eigh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 3, + "token_count": 362, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 280, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "svd", + "long_name": "svd( a , full_matrices = 1 , compute_uv = 1 )", + "filename": "linalg.py", + "nloc": 59, + "complexity": 8, + "token_count": 539, + "parameters": [ + "a", + "full_matrices", + "compute_uv" + ], + "start_line": 319, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "pinv", + "long_name": "pinv( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 386, + "end_line": 400, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "det", + "long_name": "det( a )", + "filename": "linalg.py", + "nloc": 16, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 404, + "end_line": 419, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "lstsq", + "long_name": "lstsq( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 423, + "end_line": 496, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "norm", + "long_name": "norm( x , ord = None )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 15, + "token_count": 325, + "parameters": [ + "x", + "ord" + ], + "start_line": 498, + "end_line": 563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "test", + "long_name": "test( a , b )", + "filename": "linalg.py", + "nloc": 29, + "complexity": 1, + "token_count": 205, + "parameters": [ + "a", + "b" + ], + "start_line": 566, + "end_line": 609, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "_makearray", + "long_name": "_makearray( a )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a" + ], + "start_line": 32, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_commonType", + "long_name": "_commonType( * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 2, + "token_count": 54, + "parameters": [ + "arrays" + ], + "start_line": 37, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_castCopyAndTranspose", + "long_name": "_castCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 5, + "complexity": 3, + "token_count": 47, + "parameters": [ + "type", + "arrays" + ], + "start_line": 48, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_fastCopyAndTranspose", + "long_name": "_fastCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 11, + "complexity": 4, + "token_count": 72, + "parameters": [ + "type", + "arrays" + ], + "start_line": 59, + "end_line": 69, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_assertRank2", + "long_name": "_assertRank2( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 25, + "parameters": [ + "arrays" + ], + "start_line": 71, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_assertSquareness", + "long_name": "_assertSquareness( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 30, + "parameters": [ + "arrays" + ], + "start_line": 76, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "solve_linear_equations", + "long_name": "solve_linear_equations( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 84, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "inverse", + "long_name": "inverse( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 113, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cholesky_decomposition", + "long_name": "cholesky_decomposition( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 3, + "token_count": 105, + "parameters": [ + "a" + ], + "start_line": 120, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "eigenvalues", + "long_name": "eigenvalues( a )", + "filename": "linalg.py", + "nloc": 39, + "complexity": 4, + "token_count": 363, + "parameters": [ + "a" + ], + "start_line": 139, + "end_line": 177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Heigenvalues", + "long_name": "Heigenvalues( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 34, + "complexity": 3, + "token_count": 345, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 180, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convertarray", + "long_name": "_convertarray( a )", + "filename": "linalg.py", + "nloc": 12, + "complexity": 4, + "token_count": 83, + "parameters": [ + "a" + ], + "start_line": 215, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "eig", + "long_name": "eig( a )", + "filename": "linalg.py", + "nloc": 51, + "complexity": 5, + "token_count": 499, + "parameters": [ + "a" + ], + "start_line": 230, + "end_line": 284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "eigh", + "long_name": "eigh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 3, + "token_count": 362, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 287, + "end_line": 321, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "svd", + "long_name": "svd( a , full_matrices = 1 , compute_uv = 1 )", + "filename": "linalg.py", + "nloc": 59, + "complexity": 8, + "token_count": 539, + "parameters": [ + "a", + "full_matrices", + "compute_uv" + ], + "start_line": 326, + "end_line": 389, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "generalized_inverse", + "long_name": "generalized_inverse( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 393, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "determinant", + "long_name": "determinant( a )", + "filename": "linalg.py", + "nloc": 16, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 411, + "end_line": 426, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "linear_least_squares", + "long_name": "linear_least_squares( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 430, + "end_line": 503, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "singular_value_decomposition", + "long_name": "singular_value_decomposition( A , full_matrices = 0 )", + "filename": "linalg.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "A", + "full_matrices" + ], + "start_line": 505, + "end_line": 506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvectors", + "long_name": "eigenvectors( A )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "A" + ], + "start_line": 508, + "end_line": 510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "Heigenvectors", + "long_name": "Heigenvectors( A )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "A" + ], + "start_line": 512, + "end_line": 514, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "norm", + "long_name": "norm( x , ord = None )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 15, + "token_count": 325, + "parameters": [ + "x", + "ord" + ], + "start_line": 516, + "end_line": 581, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "test", + "long_name": "test( a , b )", + "filename": "linalg.py", + "nloc": 29, + "complexity": 1, + "token_count": 205, + "parameters": [ + "a", + "b" + ], + "start_line": 595, + "end_line": 638, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "Heigenvalues", + "long_name": "Heigenvalues( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 34, + "complexity": 3, + "token_count": 345, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 180, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "eigenvalues", + "long_name": "eigenvalues( a )", + "filename": "linalg.py", + "nloc": 39, + "complexity": 4, + "token_count": 363, + "parameters": [ + "a" + ], + "start_line": 139, + "end_line": 177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "eigenvectors", + "long_name": "eigenvectors( A )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "A" + ], + "start_line": 508, + "end_line": 510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "inv", + "long_name": "inv( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 108, + "end_line": 110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "eigvals", + "long_name": "eigvals( a )", + "filename": "linalg.py", + "nloc": 39, + "complexity": 4, + "token_count": 363, + "parameters": [ + "a" + ], + "start_line": 132, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "cholesky", + "long_name": "cholesky( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 3, + "token_count": 105, + "parameters": [ + "a" + ], + "start_line": 114, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "inverse", + "long_name": "inverse( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 113, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "test", + "long_name": "test( a , b )", + "filename": "linalg.py", + "nloc": 29, + "complexity": 1, + "token_count": 205, + "parameters": [ + "a", + "b" + ], + "start_line": 566, + "end_line": 609, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + }, + { + "name": "solve_linear_equations", + "long_name": "solve_linear_equations( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 84, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "eigvalsh", + "long_name": "eigvalsh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 34, + "complexity": 3, + "token_count": 345, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 173, + "end_line": 206, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "det", + "long_name": "det( a )", + "filename": "linalg.py", + "nloc": 16, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 404, + "end_line": 419, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "singular_value_decomposition", + "long_name": "singular_value_decomposition( A , full_matrices = 0 )", + "filename": "linalg.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "A", + "full_matrices" + ], + "start_line": 505, + "end_line": 506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "determinant", + "long_name": "determinant( a )", + "filename": "linalg.py", + "nloc": 16, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 411, + "end_line": 426, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "linear_least_squares", + "long_name": "linear_least_squares( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 430, + "end_line": 503, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "generalized_inverse", + "long_name": "generalized_inverse( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 393, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "solve", + "long_name": "solve( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 79, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "Heigenvectors", + "long_name": "Heigenvectors( A )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "A" + ], + "start_line": 512, + "end_line": 514, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "lstsq", + "long_name": "lstsq( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 423, + "end_line": 496, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "cholesky_decomposition", + "long_name": "cholesky_decomposition( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 3, + "token_count": 105, + "parameters": [ + "a" + ], + "start_line": 120, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "pinv", + "long_name": "pinv( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 386, + "end_line": 400, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + } + ], + "nloc": 490, + "complexity": 85, + "token_count": 4511, + "diff_parsed": { + "added": [ + "__all__ = ['solve',", + " 'inv', 'cholesky',", + " 'eigvals',", + " 'eigvalsh', 'pinv',", + " 'det', 'svd',", + " 'eig', 'eigh','lstsq', 'norm',", + "def solve(a, b):", + "def inv(a):", + "def cholesky(a):", + "def eigvals(a):", + "def eigvalsh(a, UPLO='L'):", + "def pinv(a, rcond = 1.e-10):", + "def det(a):", + "def lstsq(a, b, rcond=1.e-10):", + " x = solve(a, b)", + " a_inv = inv(a)", + " ev = eigvals(a)", + " a_ginv = pinv(a)", + " det = det(a)", + " x, residuals, rank, sv = lstsq(a, b)" + ], + "deleted": [ + "__all__ = ['LinAlgError', 'solve_linear_equations', 'solve',", + " 'inverse', 'inv', 'cholesky_decomposition', 'cholesky', 'eigenvalues',", + " 'eigvals', 'Heigenvalues', 'eigvalsh', 'generalized_inverse', 'pinv',", + " 'determinant', 'det', 'singular_value_decomposition', 'svd',", + " 'eigenvectors', 'eig', 'Heigenvectors', 'eigh','lstsq', 'norm',", + " 'linear_least_squares'", + "# Error object", + "class LinAlgError(Exception):", + " pass", + "", + "", + "def solve_linear_equations(a, b):", + "def inverse(a):", + "", + "def cholesky_decomposition(a):", + "", + "def eigenvalues(a):", + "def Heigenvalues(a, UPLO='L'):", + "def generalized_inverse(a, rcond = 1.e-10):", + "def determinant(a):", + "def linear_least_squares(a, b, rcond=1.e-10):", + "def singular_value_decomposition(A, full_matrices=0):", + " return svd(A, full_matrices)", + "", + "def eigenvectors(A):", + " w, v = eig(A)", + " return w, transpose(v)", + "", + "def Heigenvectors(A):", + " w, v = eigh(A)", + " return w, transpose(v)", + "", + "", + "", + "inv = inverse", + "solve = solve_linear_equations", + "cholesky = cholesky_decomposition", + "eigvals = eigenvalues", + "eigvalsh = Heigenvalues", + "pinv = generalized_inverse", + "det = determinant", + "lstsq = linear_least_squares", + "", + " x = solve_linear_equations(a, b)", + " a_inv = inverse(a)", + " ev = eigenvalues(a)", + " a_ginv = generalized_inverse(a)", + " det = determinant(a)", + " x, residuals, rank, sv = linear_least_squares(a, b)" + ] + } + }, + { + "old_path": null, + "new_path": "numpy/linalg/old.py", + "filename": "old.py", + "extension": "py", + "change_type": "ADD", + "diff": "@@ -0,0 +1,86 @@\n+\n+\"\"\"Backward compatible with LinearAlgebra from Numeric\n+\"\"\"\n+# This module is a lite version of the linalg.py module in SciPy which contains\n+# high-level Python interface to the LAPACK library. The lite version\n+# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n+# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n+\n+\n+__all__ = ['LinAlgError', 'solve_linear_equations', \n+ 'inverse', 'cholesky_decomposition', 'eigenvalues',\n+ 'Heigenvalues', 'generalized_inverse', \n+ 'determinant', 'singular_value_decomposition', \n+ 'eigenvectors', 'Heigenvectors',\n+ 'linear_least_squares'\n+ ]\n+\n+from numpy.core import transpose\n+import numpy.linalg as linalg\n+\n+# Error object\n+class LinAlgError(Exception):\n+ pass\n+\n+# Linear equations\n+\n+def solve_linear_equations(a, b):\n+ return linalg.solve(a,b)\n+\n+# Matrix inversion\n+\n+def inverse(a):\n+ return linalg.inv(a)\n+\n+# Cholesky decomposition\n+\n+def cholesky_decomposition(a):\n+ return linalg.cholesky(a)\n+\n+# Eigenvalues\n+\n+def eigenvalues(a):\n+ return linalg.eigvals(a)\n+\n+def Heigenvalues(a, UPLO='L'):\n+ return linalg.eigvalsh(a,UPLO)\n+\n+# Eigenvectors\n+\n+def eigenvectors(A):\n+ w, v = linalg.eig(A)\n+ return w, transpose(v)\n+\n+def Heigenvectors(A):\n+ w, v = linalg.eigh(A)\n+ return w, transpose(v)\n+ \n+# Generalized inverse\n+\n+def generalized_inverse(a, rcond = 1.e-10):\n+ return linalg.pinv(a, rcond)\n+\n+# Determinant\n+\n+def determinant(a):\n+ return linalg.det(a)\n+\n+# Linear Least Squares\n+\n+def linear_least_squares(a, b, rcond=1.e-10):\n+ \"\"\"returns x,resids,rank,s\n+where x minimizes 2-norm(|b - Ax|)\n+ resids is the sum square residuals\n+ rank is the rank of A\n+ s is the rank of the singular values of A in descending order\n+\n+If b is a matrix then x is also a matrix with corresponding columns.\n+If the rank of A is less than the number of columns of A or greater than\n+the number of rows, then residuals will be returned as an empty array\n+otherwise resids = sum((b-dot(A,x)**2).\n+Singular values less than s[0]*rcond are treated as zero.\n+\"\"\"\n+ return linalg.lstsq(a,b,rcond)\n+\n+def singular_value_decomposition(A, full_matrices=0):\n+ return linalg.svd(A, full_matrices)\n", + "added_lines": 86, + "deleted_lines": 0, + "source_code": "\n\"\"\"Backward compatible with LinearAlgebra from Numeric\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n\n__all__ = ['LinAlgError', 'solve_linear_equations', \n 'inverse', 'cholesky_decomposition', 'eigenvalues',\n 'Heigenvalues', 'generalized_inverse', \n 'determinant', 'singular_value_decomposition', \n 'eigenvectors', 'Heigenvectors',\n 'linear_least_squares'\n ]\n\nfrom numpy.core import transpose\nimport numpy.linalg as linalg\n\n# Error object\nclass LinAlgError(Exception):\n pass\n\n# Linear equations\n\ndef solve_linear_equations(a, b):\n return linalg.solve(a,b)\n\n# Matrix inversion\n\ndef inverse(a):\n return linalg.inv(a)\n\n# Cholesky decomposition\n\ndef cholesky_decomposition(a):\n return linalg.cholesky(a)\n\n# Eigenvalues\n\ndef eigenvalues(a):\n return linalg.eigvals(a)\n\ndef Heigenvalues(a, UPLO='L'):\n return linalg.eigvalsh(a,UPLO)\n\n# Eigenvectors\n\ndef eigenvectors(A):\n w, v = linalg.eig(A)\n return w, transpose(v)\n\ndef Heigenvectors(A):\n w, v = linalg.eigh(A)\n return w, transpose(v)\n \n# Generalized inverse\n\ndef generalized_inverse(a, rcond = 1.e-10):\n return linalg.pinv(a, rcond)\n\n# Determinant\n\ndef determinant(a):\n return linalg.det(a)\n\n# Linear Least Squares\n\ndef linear_least_squares(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n return linalg.lstsq(a,b,rcond)\n\ndef singular_value_decomposition(A, full_matrices=0):\n return linalg.svd(A, full_matrices)\n", + "source_code_before": null, + "methods": [ + { + "name": "solve_linear_equations", + "long_name": "solve_linear_equations( a , b )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "a", + "b" + ], + "start_line": 27, + "end_line": 28, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "inverse", + "long_name": "inverse( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 32, + "end_line": 33, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "cholesky_decomposition", + "long_name": "cholesky_decomposition( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 37, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvalues", + "long_name": "eigenvalues( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 42, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "Heigenvalues", + "long_name": "Heigenvalues( a , UPLO = 'L' )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 45, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvectors", + "long_name": "eigenvectors( A )", + "filename": "old.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "A" + ], + "start_line": 50, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "Heigenvectors", + "long_name": "Heigenvectors( A )", + "filename": "old.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "A" + ], + "start_line": 54, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "generalized_inverse", + "long_name": "generalized_inverse( a , rcond = 1 . e - 10 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "rcond" + ], + "start_line": 60, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "determinant", + "long_name": "determinant( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 65, + "end_line": 66, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "linear_least_squares", + "long_name": "linear_least_squares( a , b , rcond = 1 . e - 10 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 70, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "singular_value_decomposition", + "long_name": "singular_value_decomposition( A , full_matrices = 0 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "A", + "full_matrices" + ], + "start_line": 85, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "methods_before": [], + "changed_methods": [ + { + "name": "Heigenvalues", + "long_name": "Heigenvalues( a , UPLO = 'L' )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 45, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "singular_value_decomposition", + "long_name": "singular_value_decomposition( A , full_matrices = 0 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "A", + "full_matrices" + ], + "start_line": 85, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvalues", + "long_name": "eigenvalues( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 42, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvectors", + "long_name": "eigenvectors( A )", + "filename": "old.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "A" + ], + "start_line": 50, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "determinant", + "long_name": "determinant( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 65, + "end_line": 66, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "linear_least_squares", + "long_name": "linear_least_squares( a , b , rcond = 1 . e - 10 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 70, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "Heigenvectors", + "long_name": "Heigenvectors( A )", + "filename": "old.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "A" + ], + "start_line": 54, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "inverse", + "long_name": "inverse( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 32, + "end_line": 33, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "cholesky_decomposition", + "long_name": "cholesky_decomposition( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 37, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "solve_linear_equations", + "long_name": "solve_linear_equations( a , b )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "a", + "b" + ], + "start_line": 27, + "end_line": 28, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "generalized_inverse", + "long_name": "generalized_inverse( a , rcond = 1 . e - 10 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "rcond" + ], + "start_line": 60, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "nloc": 37, + "complexity": 11, + "token_count": 251, + "diff_parsed": { + "added": [ + "", + "\"\"\"Backward compatible with LinearAlgebra from Numeric", + "\"\"\"", + "# This module is a lite version of the linalg.py module in SciPy which contains", + "# high-level Python interface to the LAPACK library. The lite version", + "# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,", + "# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.", + "", + "", + "__all__ = ['LinAlgError', 'solve_linear_equations',", + " 'inverse', 'cholesky_decomposition', 'eigenvalues',", + " 'Heigenvalues', 'generalized_inverse',", + " 'determinant', 'singular_value_decomposition',", + " 'eigenvectors', 'Heigenvectors',", + " 'linear_least_squares'", + " ]", + "", + "from numpy.core import transpose", + "import numpy.linalg as linalg", + "", + "# Error object", + "class LinAlgError(Exception):", + " pass", + "", + "# Linear equations", + "", + "def solve_linear_equations(a, b):", + " return linalg.solve(a,b)", + "", + "# Matrix inversion", + "", + "def inverse(a):", + " return linalg.inv(a)", + "", + "# Cholesky decomposition", + "", + "def cholesky_decomposition(a):", + " return linalg.cholesky(a)", + "", + "# Eigenvalues", + "", + "def eigenvalues(a):", + " return linalg.eigvals(a)", + "", + "def Heigenvalues(a, UPLO='L'):", + " return linalg.eigvalsh(a,UPLO)", + "", + "# Eigenvectors", + "", + "def eigenvectors(A):", + " w, v = linalg.eig(A)", + " return w, transpose(v)", + "", + "def Heigenvectors(A):", + " w, v = linalg.eigh(A)", + " return w, transpose(v)", + "", + "# Generalized inverse", + "", + "def generalized_inverse(a, rcond = 1.e-10):", + " return linalg.pinv(a, rcond)", + "", + "# Determinant", + "", + "def determinant(a):", + " return linalg.det(a)", + "", + "# Linear Least Squares", + "", + "def linear_least_squares(a, b, rcond=1.e-10):", + " \"\"\"returns x,resids,rank,s", + "where x minimizes 2-norm(|b - Ax|)", + " resids is the sum square residuals", + " rank is the rank of A", + " s is the rank of the singular values of A in descending order", + "", + "If b is a matrix then x is also a matrix with corresponding columns.", + "If the rank of A is less than the number of columns of A or greater than", + "the number of rows, then residuals will be returned as an empty array", + "otherwise resids = sum((b-dot(A,x)**2).", + "Singular values less than s[0]*rcond are treated as zero.", + "\"\"\"", + " return linalg.lstsq(a,b,rcond)", + "", + "def singular_value_decomposition(A, full_matrices=0):", + " return linalg.svd(A, full_matrices)" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "24cd77be0d56b1a98424d4f31aa58b506c4598e0", + "msg": "fix imports so that all tests pass", + "author": { + "name": "Tim Leslie", + "email": "tim.leslie@gmail.com" + }, + "committer": { + "name": "Tim Leslie", + "email": "tim.leslie@gmail.com" + }, + "author_date": "2006-03-15T06:10:41+00:00", + "author_timezone": 0, + "committer_date": "2006-03-15T06:10:41+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "db77da02aced7b10bd3fd8306cf66d88a0e8800e" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 1, + "insertions": 2, + "lines": 3, + "files": 2, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/linalg/linalg.py", + "new_path": "numpy/linalg/linalg.py", + "filename": "linalg.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -16,6 +16,7 @@\n \n from numpy.core import *\n from numpy.lib import *\n+from old import solve_linear_equations\n import lapack_lite\n \n # Helper routines\n", + "added_lines": 1, + "deleted_lines": 0, + "source_code": "\n\"\"\"Lite version of scipy.linalg.\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n__all__ = ['solve',\n 'inv', 'cholesky',\n 'eigvals',\n 'eigvalsh', 'pinv',\n 'det', 'svd',\n 'eig', 'eigh','lstsq', 'norm',\n ]\n\nfrom numpy.core import *\nfrom numpy.lib import *\nfrom old import solve_linear_equations\nimport lapack_lite\n\n# Helper routines\n_lapack_type = {'f': 0, 'd': 1, 'F': 2, 'D': 3}\n_lapack_letter = ['s', 'd', 'c', 'z']\n_array_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\n_array_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\n_array_type = [['f', 'd'], ['F', 'D']]\n\ndef _makearray(a):\n new = asarray(a)\n wrap = getattr(a, \"__array_wrap__\", new.__array_wrap__)\n return new, wrap\n\ndef _commonType(*arrays):\n kind = 0\n# precision = 0\n# force higher precision in lite version\n precision = 1\n for a in arrays:\n t = a.dtype.char\n kind = max(kind, _array_kind[t])\n precision = max(precision, _array_precision[t])\n return _array_type[kind][precision]\n\ndef _castCopyAndTranspose(type, *arrays):\n if len(arrays) == 1:\n return transpose(arrays[0]).astype(type)\n else:\n return [transpose(a).astype(type) for a in arrays]\n\n# _fastCopyAndTranpose is an optimized version of _castCopyAndTranspose.\n# It assumes the input is 2D (as all the calls in here are).\n\n_fastCT = fastCopyAndTranspose\n\ndef _fastCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.dtype.char == type:\n cast_arrays = cast_arrays + (_fastCT(a),)\n else:\n cast_arrays = cast_arrays + (_fastCT(a.astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\ndef _assertRank2(*arrays):\n for a in arrays:\n if len(a.shape) != 2:\n raise LinAlgError, 'Array must be two-dimensional'\n\ndef _assertSquareness(*arrays):\n for a in arrays:\n if max(a.shape) != min(a.shape):\n raise LinAlgError, 'Array must be square'\n\n# Linear equations\n\ndef solve(a, b):\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n _assertSquareness(a)\n n_eq = a.shape[0]\n n_rhs = b.shape[1]\n if n_eq != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n# lapack_routine = _findLapackRoutine('gesv', t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesv\n else:\n lapack_routine = lapack_lite.dgesv\n a, b = _fastCopyAndTranspose(t, a, b)\n pivots = zeros(n_eq, 'i')\n results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Singular matrix'\n if one_eq:\n return ravel(b) # I see no need to copy here\n else:\n return transpose(b) # no need to copy\n\n\n# Matrix inversion\n\ndef inv(a):\n a, wrap = _makearray(a)\n return wrap(solve_linear_equations(a, identity(a.shape[0])))\n\n# Cholesky decomposition\n\ndef cholesky(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _castCopyAndTranspose(t, a)\n m = a.shape[0]\n n = a.shape[1]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zpotrf\n else:\n lapack_routine = lapack_lite.dpotrf\n results = lapack_routine('L', n, a, m, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Matrix is not positive definite - Cholesky decomposition cannot be computed'\n return transpose(triu(a,k=0)).copy()\n\n\n# Eigenvalues\ndef eigvals(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n dummy = zeros((1,), t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n rwork = zeros((n,),real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n else:\n w = wr+1j*wi\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\n\ndef eigvalsh(a, UPLO='L'):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\ndef _convertarray(a):\n if issubclass(a.dtype.type, complexfloating):\n if a.dtype.char == 'D':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('D'))\n else:\n if a.dtype.char == 'd':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('d'))\n return a, a.dtype.char\n\n# Eigenvectors\n\ndef eig(a):\n \"\"\"eig(a) returns u,v where u is the eigenvalues and\nv is a matrix of eigenvectors with vector v[:,i] corresponds to\neigenvalue u[i]. Satisfies the equation dot(a, v[:,i]) = u[i]*v[:,i]\n\"\"\"\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n a,t = _convertarray(a) # convert to float_ or complex_ type\n real_t = 'd'\n n = a.shape[0]\n dummy = zeros((1,), t)\n if t == 'D': # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n v = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n rwork = zeros((2*n,),real_t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n vr = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n v = vr\n else:\n w = wr+1j*wi\n v = array(vr,Complex)\n ind = nonzero(\n equal(\n equal(wi,0.0) # true for real e-vals\n ,0) # true for complex e-vals\n ) # indices of complex e-vals\n for i in range(len(ind)/2):\n v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]]\n v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]]\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(v.transpose())\n\n\ndef eigh(a, UPLO='L'):\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(a.transpose())\n\n\n# Singular value decomposition\n\ndef svd(a, full_matrices=1, compute_uv=1):\n a, wrap = _makearray(a)\n _assertRank2(a)\n m, n = a.shape\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n s = zeros((min(n,m),), real_t)\n if compute_uv:\n if full_matrices:\n nu = m\n nvt = n\n option = 'A'\n else:\n nu = min(n,m)\n nvt = min(n,m)\n option = 'S'\n u = zeros((nu, m), t)\n vt = zeros((n, nvt), t)\n else:\n option = 'N'\n nu = 1\n nvt = 1\n u = empty((1,1),t) \n vt = empty((1,1),t) \n\n iwork = zeros((8*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesdd\n rwork = zeros((5*min(m,n)*min(m,n) + 5*min(m,n),), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, rwork, iwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, rwork, iwork, 0)\n else:\n lapack_routine = lapack_lite.dgesdd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, iwork, 0)\n lwork = int(work[0])\n if option == 'N' and lwork==1:\n # there seems to be a bug in dgesdd of lapack\n # (NNemec, 060310)\n # returning the wrong lwork size for option == 'N'\n results = lapack_routine('A', m, n, a, m, s, u, m, vt, n,\n work, -1, iwork, 0)\n lwork = int(work[0])\n assert lwork > 1\n\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, iwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge'\n if compute_uv:\n return wrap(transpose(u)), s, \\\n wrap(transpose(vt)) # why copy here?\n else:\n return s\n\n# Generalized inverse\n\ndef pinv(a, rcond = 1.e-10):\n a, wrap = _makearray(a)\n if a.dtype.char in typecodes['Complex']:\n a = conjugate(a)\n u, s, vt = svd(a, 0)\n m = u.shape[0]\n n = vt.shape[1]\n cutoff = rcond*maximum.reduce(s)\n for i in range(min(n,m)):\n if s[i] > cutoff:\n s[i] = 1./s[i]\n else:\n s[i] = 0.;\n return wrap(dot(transpose(vt),\n multiply(s[:, NewAxis],transpose(u))))\n\n# Determinant\n\ndef det(a):\n a = asarray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zgetrf\n else:\n lapack_routine = lapack_lite.dgetrf\n pivots = zeros((n,), 'i')\n results = lapack_routine(n, n, a, n, pivots, 0)\n sign = add.reduce(not_equal(pivots,\n arrayrange(1, n+1))) % 2\n return (1.-2.*sign)*multiply.reduce(diagonal(a),axis=-1)\n\n# Linear Least Squares\n\ndef lstsq(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n import math\n a = asarray(a)\n b, wrap = _makearray(b)\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n m = a.shape[0]\n n = a.shape[1]\n n_rhs = b.shape[1]\n ldb = max(n,m)\n if m != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n real_t = _array_type[0][_array_precision[t]]\n bstar = zeros((ldb,n_rhs),t)\n bstar[:b.shape[0],:n_rhs] = b.copy()\n a,bstar = _castCopyAndTranspose(t, a, bstar)\n s = zeros((min(m,n),),real_t)\n nlvl = max( 0, int( math.log( float(min( m,n ))/2. ) ) + 1 )\n iwork = zeros((3*min(m,n)*nlvl+11*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgelsd\n lwork = 1\n rwork = zeros((lwork,), real_t)\n work = zeros((lwork,),t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,rwork,iwork,0 )\n lwork = int(abs(work[0]))\n rwork = zeros((lwork,),real_t)\n a_real = zeros((m,n),real_t)\n bstar_real = zeros((ldb,n_rhs,),real_t)\n results = lapack_lite.dgelsd( m, n, n_rhs, a_real, m, bstar_real,ldb , s, rcond,\n 0,rwork,-1,iwork,0 )\n lrwork = int(rwork[0])\n work = zeros((lwork,), t)\n rwork = zeros((lrwork,), real_t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,rwork,iwork,0 )\n else:\n lapack_routine = lapack_lite.dgelsd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,iwork,0 )\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,iwork,0 )\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge in Linear Least Squares'\n resids = array([],t)\n if one_eq:\n x = ravel(bstar)[:n].copy()\n if (results['rank']==n) and (m>n):\n resids = array([sum((ravel(bstar)[n:])**2)])\n else:\n x = transpose(bstar)[:n,:].copy()\n if (results['rank']==n) and (m>n):\n resids = sum((transpose(bstar)[n:,:])**2).copy()\n return wrap(x),resids,results['rank'],s[:min(n,m)].copy()\n\ndef norm(x, ord=None):\n \"\"\" norm(x, ord=None) -> n\n\n Matrix or vector norm.\n\n Inputs:\n\n x -- a rank-1 (vector) or rank-2 (matrix) array\n ord -- the order of the norm.\n\n Comments:\n For arrays of any rank, if ord is None:\n calculate the square norm (Euclidean norm for vectors, Frobenius norm for matrices)\n\n For vectors ord can be any real number including Inf or -Inf.\n ord = Inf, computes the maximum of the magnitudes\n ord = -Inf, computes minimum of the magnitudes\n ord is finite, computes sum(abs(x)**ord)**(1.0/ord)\n\n For matrices ord can only be one of the following values:\n ord = 2 computes the largest singular value\n ord = -2 computes the smallest singular value\n ord = 1 computes the largest column sum of absolute values\n ord = -1 computes the smallest column sum of absolute values\n ord = Inf computes the largest row sum of absolute values\n ord = -Inf computes the smallest row sum of absolute values\n ord = 'fro' computes the frobenius norm sqrt(sum(diag(X.H * X)))\n\n For values ord < 0, the result is, strictly speaking, not a\n mathematical 'norm', but it may still be useful for numerical purposes.\n \"\"\"\n x = asarray(x)\n nd = len(x.shape) \n if ord is None: # check the default case first and handle it immediately\n return sqrt(add.reduce((x.conj() * x).ravel().real))\n\n if nd == 1:\n if ord == Inf:\n return abs(x).max()\n elif ord == -Inf:\n return abs(x).min()\n elif ord == 1:\n return abs(x).sum() # special case for speedup\n elif ord == 2:\n return sqrt(((x.conj()*x).real).sum()) # special case for speedup\n else:\n return ((abs(x)**ord).sum())**(1.0/ord)\n elif nd == 2:\n if ord == 2:\n return svd(x,compute_uv=0).max()\n elif ord == -2:\n return svd(x,compute_uv=0).min()\n elif ord == 1:\n return abs(x).sum(axis=0).max()\n elif ord == Inf:\n return abs(x).sum(axis=1).max()\n elif ord == -1:\n return abs(x).sum(axis=0).min()\n elif ord == -Inf:\n return abs(x).sum(axis=1).min()\n elif ord in ['fro','f']:\n return sqrt(add.reduce((x.conj() * x).real.ravel()))\n else:\n raise ValueError, \"Invalid norm order for matrices.\"\n else:\n raise ValueError, \"Improper number of dimensions to norm.\"\n\nif __name__ == '__main__':\n def test(a, b):\n\n print \"All numbers printed should be (almost) zero:\"\n\n x = solve(a, b)\n check = b - matrixmultiply(a, x)\n print check\n\n\n a_inv = inv(a)\n check = matrixmultiply(a, a_inv)-identity(a.shape[0])\n print check\n\n\n ev = eigvals(a)\n\n evalues, evectors = eig(a)\n check = ev-evalues\n print check\n\n evectors = transpose(evectors)\n check = matrixmultiply(a, evectors)-evectors*evalues\n print check\n\n\n u, s, vt = svd(a,0)\n check = a - matrixmultiply(u*s, vt)\n print check\n\n\n a_ginv = pinv(a)\n check = matrixmultiply(a, a_ginv)-identity(a.shape[0])\n print check\n\n\n det = det(a)\n check = det-multiply.reduce(evalues)\n print check\n\n x, residuals, rank, sv = lstsq(a, b)\n check = b - matrixmultiply(a, x)\n print check\n print rank-a.shape[0]\n print sv-s\n\n a = array([[1.,2.], [3.,4.]])\n b = array([2., 1.])\n test(a, b)\n\n a = a+0j\n b = b+0j\n test(a, b)\n", + "source_code_before": "\n\"\"\"Lite version of scipy.linalg.\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n__all__ = ['solve',\n 'inv', 'cholesky',\n 'eigvals',\n 'eigvalsh', 'pinv',\n 'det', 'svd',\n 'eig', 'eigh','lstsq', 'norm',\n ]\n\nfrom numpy.core import *\nfrom numpy.lib import *\nimport lapack_lite\n\n# Helper routines\n_lapack_type = {'f': 0, 'd': 1, 'F': 2, 'D': 3}\n_lapack_letter = ['s', 'd', 'c', 'z']\n_array_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\n_array_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\n_array_type = [['f', 'd'], ['F', 'D']]\n\ndef _makearray(a):\n new = asarray(a)\n wrap = getattr(a, \"__array_wrap__\", new.__array_wrap__)\n return new, wrap\n\ndef _commonType(*arrays):\n kind = 0\n# precision = 0\n# force higher precision in lite version\n precision = 1\n for a in arrays:\n t = a.dtype.char\n kind = max(kind, _array_kind[t])\n precision = max(precision, _array_precision[t])\n return _array_type[kind][precision]\n\ndef _castCopyAndTranspose(type, *arrays):\n if len(arrays) == 1:\n return transpose(arrays[0]).astype(type)\n else:\n return [transpose(a).astype(type) for a in arrays]\n\n# _fastCopyAndTranpose is an optimized version of _castCopyAndTranspose.\n# It assumes the input is 2D (as all the calls in here are).\n\n_fastCT = fastCopyAndTranspose\n\ndef _fastCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.dtype.char == type:\n cast_arrays = cast_arrays + (_fastCT(a),)\n else:\n cast_arrays = cast_arrays + (_fastCT(a.astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\ndef _assertRank2(*arrays):\n for a in arrays:\n if len(a.shape) != 2:\n raise LinAlgError, 'Array must be two-dimensional'\n\ndef _assertSquareness(*arrays):\n for a in arrays:\n if max(a.shape) != min(a.shape):\n raise LinAlgError, 'Array must be square'\n\n# Linear equations\n\ndef solve(a, b):\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n _assertSquareness(a)\n n_eq = a.shape[0]\n n_rhs = b.shape[1]\n if n_eq != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n# lapack_routine = _findLapackRoutine('gesv', t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesv\n else:\n lapack_routine = lapack_lite.dgesv\n a, b = _fastCopyAndTranspose(t, a, b)\n pivots = zeros(n_eq, 'i')\n results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Singular matrix'\n if one_eq:\n return ravel(b) # I see no need to copy here\n else:\n return transpose(b) # no need to copy\n\n\n# Matrix inversion\n\ndef inv(a):\n a, wrap = _makearray(a)\n return wrap(solve_linear_equations(a, identity(a.shape[0])))\n\n# Cholesky decomposition\n\ndef cholesky(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _castCopyAndTranspose(t, a)\n m = a.shape[0]\n n = a.shape[1]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zpotrf\n else:\n lapack_routine = lapack_lite.dpotrf\n results = lapack_routine('L', n, a, m, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Matrix is not positive definite - Cholesky decomposition cannot be computed'\n return transpose(triu(a,k=0)).copy()\n\n\n# Eigenvalues\ndef eigvals(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n dummy = zeros((1,), t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n rwork = zeros((n,),real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n else:\n w = wr+1j*wi\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\n\ndef eigvalsh(a, UPLO='L'):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\ndef _convertarray(a):\n if issubclass(a.dtype.type, complexfloating):\n if a.dtype.char == 'D':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('D'))\n else:\n if a.dtype.char == 'd':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('d'))\n return a, a.dtype.char\n\n# Eigenvectors\n\ndef eig(a):\n \"\"\"eig(a) returns u,v where u is the eigenvalues and\nv is a matrix of eigenvectors with vector v[:,i] corresponds to\neigenvalue u[i]. Satisfies the equation dot(a, v[:,i]) = u[i]*v[:,i]\n\"\"\"\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n a,t = _convertarray(a) # convert to float_ or complex_ type\n real_t = 'd'\n n = a.shape[0]\n dummy = zeros((1,), t)\n if t == 'D': # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n v = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n rwork = zeros((2*n,),real_t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n vr = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n v = vr\n else:\n w = wr+1j*wi\n v = array(vr,Complex)\n ind = nonzero(\n equal(\n equal(wi,0.0) # true for real e-vals\n ,0) # true for complex e-vals\n ) # indices of complex e-vals\n for i in range(len(ind)/2):\n v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]]\n v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]]\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(v.transpose())\n\n\ndef eigh(a, UPLO='L'):\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(a.transpose())\n\n\n# Singular value decomposition\n\ndef svd(a, full_matrices=1, compute_uv=1):\n a, wrap = _makearray(a)\n _assertRank2(a)\n m, n = a.shape\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n s = zeros((min(n,m),), real_t)\n if compute_uv:\n if full_matrices:\n nu = m\n nvt = n\n option = 'A'\n else:\n nu = min(n,m)\n nvt = min(n,m)\n option = 'S'\n u = zeros((nu, m), t)\n vt = zeros((n, nvt), t)\n else:\n option = 'N'\n nu = 1\n nvt = 1\n u = empty((1,1),t) \n vt = empty((1,1),t) \n\n iwork = zeros((8*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesdd\n rwork = zeros((5*min(m,n)*min(m,n) + 5*min(m,n),), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, rwork, iwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, rwork, iwork, 0)\n else:\n lapack_routine = lapack_lite.dgesdd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, iwork, 0)\n lwork = int(work[0])\n if option == 'N' and lwork==1:\n # there seems to be a bug in dgesdd of lapack\n # (NNemec, 060310)\n # returning the wrong lwork size for option == 'N'\n results = lapack_routine('A', m, n, a, m, s, u, m, vt, n,\n work, -1, iwork, 0)\n lwork = int(work[0])\n assert lwork > 1\n\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, iwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge'\n if compute_uv:\n return wrap(transpose(u)), s, \\\n wrap(transpose(vt)) # why copy here?\n else:\n return s\n\n# Generalized inverse\n\ndef pinv(a, rcond = 1.e-10):\n a, wrap = _makearray(a)\n if a.dtype.char in typecodes['Complex']:\n a = conjugate(a)\n u, s, vt = svd(a, 0)\n m = u.shape[0]\n n = vt.shape[1]\n cutoff = rcond*maximum.reduce(s)\n for i in range(min(n,m)):\n if s[i] > cutoff:\n s[i] = 1./s[i]\n else:\n s[i] = 0.;\n return wrap(dot(transpose(vt),\n multiply(s[:, NewAxis],transpose(u))))\n\n# Determinant\n\ndef det(a):\n a = asarray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zgetrf\n else:\n lapack_routine = lapack_lite.dgetrf\n pivots = zeros((n,), 'i')\n results = lapack_routine(n, n, a, n, pivots, 0)\n sign = add.reduce(not_equal(pivots,\n arrayrange(1, n+1))) % 2\n return (1.-2.*sign)*multiply.reduce(diagonal(a),axis=-1)\n\n# Linear Least Squares\n\ndef lstsq(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n import math\n a = asarray(a)\n b, wrap = _makearray(b)\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n m = a.shape[0]\n n = a.shape[1]\n n_rhs = b.shape[1]\n ldb = max(n,m)\n if m != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n real_t = _array_type[0][_array_precision[t]]\n bstar = zeros((ldb,n_rhs),t)\n bstar[:b.shape[0],:n_rhs] = b.copy()\n a,bstar = _castCopyAndTranspose(t, a, bstar)\n s = zeros((min(m,n),),real_t)\n nlvl = max( 0, int( math.log( float(min( m,n ))/2. ) ) + 1 )\n iwork = zeros((3*min(m,n)*nlvl+11*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgelsd\n lwork = 1\n rwork = zeros((lwork,), real_t)\n work = zeros((lwork,),t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,rwork,iwork,0 )\n lwork = int(abs(work[0]))\n rwork = zeros((lwork,),real_t)\n a_real = zeros((m,n),real_t)\n bstar_real = zeros((ldb,n_rhs,),real_t)\n results = lapack_lite.dgelsd( m, n, n_rhs, a_real, m, bstar_real,ldb , s, rcond,\n 0,rwork,-1,iwork,0 )\n lrwork = int(rwork[0])\n work = zeros((lwork,), t)\n rwork = zeros((lrwork,), real_t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,rwork,iwork,0 )\n else:\n lapack_routine = lapack_lite.dgelsd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,iwork,0 )\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,iwork,0 )\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge in Linear Least Squares'\n resids = array([],t)\n if one_eq:\n x = ravel(bstar)[:n].copy()\n if (results['rank']==n) and (m>n):\n resids = array([sum((ravel(bstar)[n:])**2)])\n else:\n x = transpose(bstar)[:n,:].copy()\n if (results['rank']==n) and (m>n):\n resids = sum((transpose(bstar)[n:,:])**2).copy()\n return wrap(x),resids,results['rank'],s[:min(n,m)].copy()\n\ndef norm(x, ord=None):\n \"\"\" norm(x, ord=None) -> n\n\n Matrix or vector norm.\n\n Inputs:\n\n x -- a rank-1 (vector) or rank-2 (matrix) array\n ord -- the order of the norm.\n\n Comments:\n For arrays of any rank, if ord is None:\n calculate the square norm (Euclidean norm for vectors, Frobenius norm for matrices)\n\n For vectors ord can be any real number including Inf or -Inf.\n ord = Inf, computes the maximum of the magnitudes\n ord = -Inf, computes minimum of the magnitudes\n ord is finite, computes sum(abs(x)**ord)**(1.0/ord)\n\n For matrices ord can only be one of the following values:\n ord = 2 computes the largest singular value\n ord = -2 computes the smallest singular value\n ord = 1 computes the largest column sum of absolute values\n ord = -1 computes the smallest column sum of absolute values\n ord = Inf computes the largest row sum of absolute values\n ord = -Inf computes the smallest row sum of absolute values\n ord = 'fro' computes the frobenius norm sqrt(sum(diag(X.H * X)))\n\n For values ord < 0, the result is, strictly speaking, not a\n mathematical 'norm', but it may still be useful for numerical purposes.\n \"\"\"\n x = asarray(x)\n nd = len(x.shape) \n if ord is None: # check the default case first and handle it immediately\n return sqrt(add.reduce((x.conj() * x).ravel().real))\n\n if nd == 1:\n if ord == Inf:\n return abs(x).max()\n elif ord == -Inf:\n return abs(x).min()\n elif ord == 1:\n return abs(x).sum() # special case for speedup\n elif ord == 2:\n return sqrt(((x.conj()*x).real).sum()) # special case for speedup\n else:\n return ((abs(x)**ord).sum())**(1.0/ord)\n elif nd == 2:\n if ord == 2:\n return svd(x,compute_uv=0).max()\n elif ord == -2:\n return svd(x,compute_uv=0).min()\n elif ord == 1:\n return abs(x).sum(axis=0).max()\n elif ord == Inf:\n return abs(x).sum(axis=1).max()\n elif ord == -1:\n return abs(x).sum(axis=0).min()\n elif ord == -Inf:\n return abs(x).sum(axis=1).min()\n elif ord in ['fro','f']:\n return sqrt(add.reduce((x.conj() * x).real.ravel()))\n else:\n raise ValueError, \"Invalid norm order for matrices.\"\n else:\n raise ValueError, \"Improper number of dimensions to norm.\"\n\nif __name__ == '__main__':\n def test(a, b):\n\n print \"All numbers printed should be (almost) zero:\"\n\n x = solve(a, b)\n check = b - matrixmultiply(a, x)\n print check\n\n\n a_inv = inv(a)\n check = matrixmultiply(a, a_inv)-identity(a.shape[0])\n print check\n\n\n ev = eigvals(a)\n\n evalues, evectors = eig(a)\n check = ev-evalues\n print check\n\n evectors = transpose(evectors)\n check = matrixmultiply(a, evectors)-evectors*evalues\n print check\n\n\n u, s, vt = svd(a,0)\n check = a - matrixmultiply(u*s, vt)\n print check\n\n\n a_ginv = pinv(a)\n check = matrixmultiply(a, a_ginv)-identity(a.shape[0])\n print check\n\n\n det = det(a)\n check = det-multiply.reduce(evalues)\n print check\n\n x, residuals, rank, sv = lstsq(a, b)\n check = b - matrixmultiply(a, x)\n print check\n print rank-a.shape[0]\n print sv-s\n\n a = array([[1.,2.], [3.,4.]])\n b = array([2., 1.])\n test(a, b)\n\n a = a+0j\n b = b+0j\n test(a, b)\n", + "methods": [ + { + "name": "_makearray", + "long_name": "_makearray( a )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a" + ], + "start_line": 29, + "end_line": 32, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_commonType", + "long_name": "_commonType( * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 2, + "token_count": 54, + "parameters": [ + "arrays" + ], + "start_line": 34, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_castCopyAndTranspose", + "long_name": "_castCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 5, + "complexity": 3, + "token_count": 47, + "parameters": [ + "type", + "arrays" + ], + "start_line": 45, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_fastCopyAndTranspose", + "long_name": "_fastCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 11, + "complexity": 4, + "token_count": 72, + "parameters": [ + "type", + "arrays" + ], + "start_line": 56, + "end_line": 66, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_assertRank2", + "long_name": "_assertRank2( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 25, + "parameters": [ + "arrays" + ], + "start_line": 68, + "end_line": 71, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_assertSquareness", + "long_name": "_assertSquareness( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 30, + "parameters": [ + "arrays" + ], + "start_line": 73, + "end_line": 76, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "solve", + "long_name": "solve( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 80, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "inv", + "long_name": "inv( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 109, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cholesky", + "long_name": "cholesky( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 3, + "token_count": 105, + "parameters": [ + "a" + ], + "start_line": 115, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "eigvals", + "long_name": "eigvals( a )", + "filename": "linalg.py", + "nloc": 39, + "complexity": 4, + "token_count": 363, + "parameters": [ + "a" + ], + "start_line": 133, + "end_line": 171, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "eigvalsh", + "long_name": "eigvalsh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 34, + "complexity": 3, + "token_count": 345, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 174, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convertarray", + "long_name": "_convertarray( a )", + "filename": "linalg.py", + "nloc": 12, + "complexity": 4, + "token_count": 83, + "parameters": [ + "a" + ], + "start_line": 209, + "end_line": 220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "eig", + "long_name": "eig( a )", + "filename": "linalg.py", + "nloc": 51, + "complexity": 5, + "token_count": 499, + "parameters": [ + "a" + ], + "start_line": 224, + "end_line": 278, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "eigh", + "long_name": "eigh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 3, + "token_count": 362, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 281, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "svd", + "long_name": "svd( a , full_matrices = 1 , compute_uv = 1 )", + "filename": "linalg.py", + "nloc": 59, + "complexity": 8, + "token_count": 539, + "parameters": [ + "a", + "full_matrices", + "compute_uv" + ], + "start_line": 320, + "end_line": 383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "pinv", + "long_name": "pinv( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 387, + "end_line": 401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "det", + "long_name": "det( a )", + "filename": "linalg.py", + "nloc": 16, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 405, + "end_line": 420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "lstsq", + "long_name": "lstsq( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 424, + "end_line": 497, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "norm", + "long_name": "norm( x , ord = None )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 15, + "token_count": 325, + "parameters": [ + "x", + "ord" + ], + "start_line": 499, + "end_line": 564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "test", + "long_name": "test( a , b )", + "filename": "linalg.py", + "nloc": 29, + "complexity": 1, + "token_count": 205, + "parameters": [ + "a", + "b" + ], + "start_line": 567, + "end_line": 610, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "_makearray", + "long_name": "_makearray( a )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a" + ], + "start_line": 28, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_commonType", + "long_name": "_commonType( * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 2, + "token_count": 54, + "parameters": [ + "arrays" + ], + "start_line": 33, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_castCopyAndTranspose", + "long_name": "_castCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 5, + "complexity": 3, + "token_count": 47, + "parameters": [ + "type", + "arrays" + ], + "start_line": 44, + "end_line": 48, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_fastCopyAndTranspose", + "long_name": "_fastCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 11, + "complexity": 4, + "token_count": 72, + "parameters": [ + "type", + "arrays" + ], + "start_line": 55, + "end_line": 65, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_assertRank2", + "long_name": "_assertRank2( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 25, + "parameters": [ + "arrays" + ], + "start_line": 67, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_assertSquareness", + "long_name": "_assertSquareness( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 30, + "parameters": [ + "arrays" + ], + "start_line": 72, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "solve", + "long_name": "solve( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 79, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "inv", + "long_name": "inv( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 108, + "end_line": 110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cholesky", + "long_name": "cholesky( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 3, + "token_count": 105, + "parameters": [ + "a" + ], + "start_line": 114, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "eigvals", + "long_name": "eigvals( a )", + "filename": "linalg.py", + "nloc": 39, + "complexity": 4, + "token_count": 363, + "parameters": [ + "a" + ], + "start_line": 132, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "eigvalsh", + "long_name": "eigvalsh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 34, + "complexity": 3, + "token_count": 345, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 173, + "end_line": 206, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convertarray", + "long_name": "_convertarray( a )", + "filename": "linalg.py", + "nloc": 12, + "complexity": 4, + "token_count": 83, + "parameters": [ + "a" + ], + "start_line": 208, + "end_line": 219, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "eig", + "long_name": "eig( a )", + "filename": "linalg.py", + "nloc": 51, + "complexity": 5, + "token_count": 499, + "parameters": [ + "a" + ], + "start_line": 223, + "end_line": 277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "eigh", + "long_name": "eigh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 3, + "token_count": 362, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 280, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "svd", + "long_name": "svd( a , full_matrices = 1 , compute_uv = 1 )", + "filename": "linalg.py", + "nloc": 59, + "complexity": 8, + "token_count": 539, + "parameters": [ + "a", + "full_matrices", + "compute_uv" + ], + "start_line": 319, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "pinv", + "long_name": "pinv( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 386, + "end_line": 400, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "det", + "long_name": "det( a )", + "filename": "linalg.py", + "nloc": 16, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 404, + "end_line": 419, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "lstsq", + "long_name": "lstsq( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 423, + "end_line": 496, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "norm", + "long_name": "norm( x , ord = None )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 15, + "token_count": 325, + "parameters": [ + "x", + "ord" + ], + "start_line": 498, + "end_line": 563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "test", + "long_name": "test( a , b )", + "filename": "linalg.py", + "nloc": 29, + "complexity": 1, + "token_count": 205, + "parameters": [ + "a", + "b" + ], + "start_line": 566, + "end_line": 609, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + } + ], + "changed_methods": [], + "nloc": 491, + "complexity": 85, + "token_count": 4515, + "diff_parsed": { + "added": [ + "from old import solve_linear_equations" + ], + "deleted": [] + } + }, + { + "old_path": "numpy/linalg/old.py", + "new_path": "numpy/linalg/old.py", + "filename": "old.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -16,7 +16,7 @@\n ]\n \n from numpy.core import transpose\n-import numpy.linalg as linalg\n+import linalg\n \n # Error object\n class LinAlgError(Exception):\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "\n\"\"\"Backward compatible with LinearAlgebra from Numeric\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n\n__all__ = ['LinAlgError', 'solve_linear_equations', \n 'inverse', 'cholesky_decomposition', 'eigenvalues',\n 'Heigenvalues', 'generalized_inverse', \n 'determinant', 'singular_value_decomposition', \n 'eigenvectors', 'Heigenvectors',\n 'linear_least_squares'\n ]\n\nfrom numpy.core import transpose\nimport linalg\n\n# Error object\nclass LinAlgError(Exception):\n pass\n\n# Linear equations\n\ndef solve_linear_equations(a, b):\n return linalg.solve(a,b)\n\n# Matrix inversion\n\ndef inverse(a):\n return linalg.inv(a)\n\n# Cholesky decomposition\n\ndef cholesky_decomposition(a):\n return linalg.cholesky(a)\n\n# Eigenvalues\n\ndef eigenvalues(a):\n return linalg.eigvals(a)\n\ndef Heigenvalues(a, UPLO='L'):\n return linalg.eigvalsh(a,UPLO)\n\n# Eigenvectors\n\ndef eigenvectors(A):\n w, v = linalg.eig(A)\n return w, transpose(v)\n\ndef Heigenvectors(A):\n w, v = linalg.eigh(A)\n return w, transpose(v)\n \n# Generalized inverse\n\ndef generalized_inverse(a, rcond = 1.e-10):\n return linalg.pinv(a, rcond)\n\n# Determinant\n\ndef determinant(a):\n return linalg.det(a)\n\n# Linear Least Squares\n\ndef linear_least_squares(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n return linalg.lstsq(a,b,rcond)\n\ndef singular_value_decomposition(A, full_matrices=0):\n return linalg.svd(A, full_matrices)\n", + "source_code_before": "\n\"\"\"Backward compatible with LinearAlgebra from Numeric\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n\n__all__ = ['LinAlgError', 'solve_linear_equations', \n 'inverse', 'cholesky_decomposition', 'eigenvalues',\n 'Heigenvalues', 'generalized_inverse', \n 'determinant', 'singular_value_decomposition', \n 'eigenvectors', 'Heigenvectors',\n 'linear_least_squares'\n ]\n\nfrom numpy.core import transpose\nimport numpy.linalg as linalg\n\n# Error object\nclass LinAlgError(Exception):\n pass\n\n# Linear equations\n\ndef solve_linear_equations(a, b):\n return linalg.solve(a,b)\n\n# Matrix inversion\n\ndef inverse(a):\n return linalg.inv(a)\n\n# Cholesky decomposition\n\ndef cholesky_decomposition(a):\n return linalg.cholesky(a)\n\n# Eigenvalues\n\ndef eigenvalues(a):\n return linalg.eigvals(a)\n\ndef Heigenvalues(a, UPLO='L'):\n return linalg.eigvalsh(a,UPLO)\n\n# Eigenvectors\n\ndef eigenvectors(A):\n w, v = linalg.eig(A)\n return w, transpose(v)\n\ndef Heigenvectors(A):\n w, v = linalg.eigh(A)\n return w, transpose(v)\n \n# Generalized inverse\n\ndef generalized_inverse(a, rcond = 1.e-10):\n return linalg.pinv(a, rcond)\n\n# Determinant\n\ndef determinant(a):\n return linalg.det(a)\n\n# Linear Least Squares\n\ndef linear_least_squares(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n return linalg.lstsq(a,b,rcond)\n\ndef singular_value_decomposition(A, full_matrices=0):\n return linalg.svd(A, full_matrices)\n", + "methods": [ + { + "name": "solve_linear_equations", + "long_name": "solve_linear_equations( a , b )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "a", + "b" + ], + "start_line": 27, + "end_line": 28, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "inverse", + "long_name": "inverse( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 32, + "end_line": 33, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "cholesky_decomposition", + "long_name": "cholesky_decomposition( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 37, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvalues", + "long_name": "eigenvalues( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 42, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "Heigenvalues", + "long_name": "Heigenvalues( a , UPLO = 'L' )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 45, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvectors", + "long_name": "eigenvectors( A )", + "filename": "old.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "A" + ], + "start_line": 50, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "Heigenvectors", + "long_name": "Heigenvectors( A )", + "filename": "old.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "A" + ], + "start_line": 54, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "generalized_inverse", + "long_name": "generalized_inverse( a , rcond = 1 . e - 10 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "rcond" + ], + "start_line": 60, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "determinant", + "long_name": "determinant( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 65, + "end_line": 66, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "linear_least_squares", + "long_name": "linear_least_squares( a , b , rcond = 1 . e - 10 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 70, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "singular_value_decomposition", + "long_name": "singular_value_decomposition( A , full_matrices = 0 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "A", + "full_matrices" + ], + "start_line": 85, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "solve_linear_equations", + "long_name": "solve_linear_equations( a , b )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "a", + "b" + ], + "start_line": 27, + "end_line": 28, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "inverse", + "long_name": "inverse( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 32, + "end_line": 33, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "cholesky_decomposition", + "long_name": "cholesky_decomposition( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 37, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvalues", + "long_name": "eigenvalues( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 42, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "Heigenvalues", + "long_name": "Heigenvalues( a , UPLO = 'L' )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 45, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvectors", + "long_name": "eigenvectors( A )", + "filename": "old.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "A" + ], + "start_line": 50, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "Heigenvectors", + "long_name": "Heigenvectors( A )", + "filename": "old.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "A" + ], + "start_line": 54, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "generalized_inverse", + "long_name": "generalized_inverse( a , rcond = 1 . e - 10 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "rcond" + ], + "start_line": 60, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "determinant", + "long_name": "determinant( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 65, + "end_line": 66, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "linear_least_squares", + "long_name": "linear_least_squares( a , b , rcond = 1 . e - 10 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 70, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "singular_value_decomposition", + "long_name": "singular_value_decomposition( A , full_matrices = 0 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "A", + "full_matrices" + ], + "start_line": 85, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 37, + "complexity": 11, + "token_count": 247, + "diff_parsed": { + "added": [ + "import linalg" + ], + "deleted": [ + "import numpy.linalg as linalg" + ] + } + } + ] + }, + { + "hash": "abe1567d970117ed9a3634c10c843da2e3399f60", + "msg": "Fix-up name-spaces.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-15T09:29:30+00:00", + "author_timezone": 0, + "committer_date": "2006-03-15T09:29:30+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "24cd77be0d56b1a98424d4f31aa58b506c4598e0" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 10, + "insertions": 10, + "lines": 20, + "files": 3, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/core/oldnumeric.py", + "new_path": "numpy/core/oldnumeric.py", + "filename": "oldnumeric.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -514,7 +514,7 @@ def alen(a):\n try:\n return len(a)\n except TypeError:\n- return len(atleast_1d(a))\n+ return len(array(a,ndmin=1))\n \n def prod(a, axis=0, dtype=None):\n \"\"\"Return the product of the elements along the given axis\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "# Compatibility module containing deprecated names\n\n__all__ = ['asarray', 'array', 'concatenate',\n 'NewAxis',\n 'UFuncType', 'UfuncType', 'ArrayType', 'arraytype',\n 'LittleEndian', 'Bool',\n 'Character', 'UnsignedInt8', 'UnsignedInt16', 'UnsignedInt',\n 'UInt8','UInt16','UInt32', 'UnsignedInt32', 'UnsignedInteger',\n # UnsignedInt64 and Unsigned128 added below if possible\n # same for Int64 and Int128, Float128, and Complex128\n 'Int8', 'Int16', 'Int32',\n 'Int0', 'Int', 'Float0', 'Float', 'Complex0', 'Complex',\n 'PyObject', 'Float32', 'Float64', 'Float16', 'Float8',\n 'Complex32', 'Complex64', 'Complex8', 'Complex16',\n 'typecodes', 'sarray', 'arrayrange', 'cross_correlate',\n 'matrixmultiply', 'outerproduct', 'innerproduct',\n # from cPickle\n 'dump', 'dumps',\n # functions that are now methods\n 'take', 'reshape', 'choose', 'repeat', 'put', 'putmask',\n 'swapaxes', 'transpose', 'sort', 'argsort', 'argmax', 'argmin',\n 'searchsorted', 'alen',\n 'resize', 'diagonal', 'trace', 'ravel', 'nonzero', 'shape',\n 'compress', 'clip', 'sum', 'product', 'prod', 'sometrue', 'alltrue',\n 'any', 'all', 'cumsum', 'cumproduct', 'cumprod', 'ptp', 'ndim',\n 'rank', 'size', 'around', 'round_', 'mean', 'std', 'var', 'squeeze',\n 'amax', 'amin',\n ]\n\nimport multiarray as mu\nimport umath as um\nimport numerictypes as nt\nfrom numeric import asarray, array, asanyarray, correlate, outer, concatenate\nfrom umath import sign, absolute, multiply\nimport numeric as _nx\nimport sys\n_dt_ = nt.sctype2char\n\nimport types\n\ntry:\n _gentype = types.GeneratorType\nexcept AttributeError:\n _gentype = types.NoneType\n#Use this to add a new axis to an array\n#compatibility only\nNewAxis = None\n\n#deprecated\nUFuncType = type(um.sin)\nUfuncType = type(um.sin)\nArrayType = mu.ndarray\narraytype = mu.ndarray\n\nLittleEndian = (sys.byteorder == 'little')\n\n# save away Python sum\n_sum_ = sum\n\n# backward compatible names from old Precision.py\n\nCharacter = 'S1'\nUnsignedInt8 = _dt_(nt.uint8)\nUInt8 = UnsignedInt8\nUnsignedInt16 = _dt_(nt.uint16)\nUInt16 = UnsignedInt16\nUnsignedInt32 = _dt_(nt.uint32)\nUInt32 = UnsignedInt32\nUnsignedInt = _dt_(nt.uint)\n\ntry:\n UnsignedInt64 = _dt_(nt.uint64)\nexcept AttributeError:\n pass\nelse:\n UInt64 = UnsignedInt64\n __all__ += ['UnsignedInt64', 'UInt64']\ntry:\n UnsignedInt128 = _dt_(nt.uint128)\nexcept AttributeError:\n pass\nelse:\n UInt128 = UnsignedInt128\n __all__ += ['UnsignedInt128','UInt128']\n\nInt8 = _dt_(nt.int8)\nInt16 = _dt_(nt.int16)\nInt32 = _dt_(nt.int32)\n\ntry:\n Int64 = _dt_(nt.int64)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int64']\n\ntry:\n Int128 = _dt_(nt.int128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int128']\n\nBool = _dt_(bool)\nInt0 = _dt_(int)\nInt = _dt_(int)\nFloat0 = _dt_(float)\nFloat = _dt_(float)\nComplex0 = _dt_(complex)\nComplex = _dt_(complex)\nPyObject = _dt_(nt.object_)\nFloat32 = _dt_(nt.float32)\nFloat64 = _dt_(nt.float64)\n\nFloat16='f'\nFloat8='f'\nUnsignedInteger='L'\nComplex8='F'\nComplex16='F'\n\ntry:\n Float128 = _dt_(nt.float128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Float128']\n\nComplex32 = _dt_(nt.complex64)\nComplex64 = _dt_(nt.complex128)\n\ntry:\n Complex128 = _dt_(nt.complex256)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Complex128']\n\ntypecodes = {'Character':'S1',\n 'Integer':'bhilqp',\n 'UnsignedInteger':'BHILQP',\n 'Float':'fdg',\n 'Complex':'FDG',\n 'AllInteger':'bBhHiIlLqQpP',\n 'AllFloat':'fdgFDG',\n 'All':'?bhilqpBHILQPfdgFDGSUVO'}\n\ndef sarray(a, dtype=None, copy=False):\n return array(a, dtype, copy)\n\n# backward compatibility\narrayrange = mu.arange\ncross_correlate = correlate\n\n# deprecated names\nmatrixmultiply = mu.dot\nouterproduct = outer\ninnerproduct = mu.inner\n\nfrom cPickle import dump, dumps\n\n# functions that are now methods\n\ndef _wrapit(obj, method, *args, **kwds):\n try:\n wrap = obj.__array_wrap__\n except AttributeError:\n wrap = None\n result = getattr(asarray(obj),method)(*args, **kwds)\n if wrap:\n result = wrap(result)\n return result\n\ndef take(a, indices, axis=0):\n try:\n result = a.take(indices, axis)\n except AttributeError:\n result = _wrapit(a, 'take', indices, axis)\n return result\n\ndef reshape(a, newshape):\n \"\"\"Change the shape of a to newshape. Return a new view object.\n \"\"\"\n try:\n result = a.reshape(newshape)\n except AttributeError:\n result = _wrapit(a, 'reshape', newshape)\n return result\n\ndef choose(a, choices):\n try:\n result = a.choose(choices)\n except AttributeError:\n result = _wrapit(a, 'choose', choices)\n return result\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n 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 try:\n result = a.repeat(repeats, axis)\n except AttributeError:\n result = _wrapit(a, 'repeat', repeats, axis)\n return result\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.dtype)\n for i in ind: a.flat[i] = v[i]\n a must be a contiguous numpy array.\n \"\"\"\n return a.put(v,ind)\n\ndef putmask (a, mask, v):\n \"\"\"putmask(a, mask, v) results in a = v for all places mask is true.\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n \"\"\"\n return a.putmask(v, mask)\n\ndef swapaxes(a, axis1, axis2):\n \"\"\"swapaxes(a, axis1, axis2) returns array a with axis1 and axis2\n interchanged.\n \"\"\"\n try:\n result = a.swapaxes(axis1, axis2)\n except AttributeError:\n result = _wrapit(a, 'swapaxes', axis1, axis2)\n return result\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 try:\n result = a.transpose(axes)\n except AttributeError:\n result = _wrapit(a, 'transpose', axes)\n return result\n\ndef sort(a, axis=-1):\n \"\"\"sort(a,axis=-1) returns array with elements sorted along given axis.\n \"\"\"\n a = asanyarray(a, copy=True)\n a.sort(axis)\n return a\n\ndef argsort(a, axis=-1):\n \"\"\"argsort(a,axis=-1) return the indices into a of the sorted array\n along the given axis, so that take(a,result,axis) is the sorted array.\n \"\"\"\n try:\n result = a.argsort(axis)\n except AttributeError:\n result = _wrapit(a, 'argsort', axis)\n return result\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 try:\n result = a.argmax(axis)\n except AttributeError:\n result = _wrapit(a, 'argmax', axis)\n return result\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 try:\n result = a.argmin(axis)\n except AttributeError:\n result = _wrapit(a, 'argmin', axis)\n return result\n \ndef searchsorted(a, v):\n \"\"\"searchsorted(a, v)\n \"\"\"\n try:\n result = a.searchsorted(v)\n except AttributeError:\n result = _wrapit(a, 'searchsorted', v)\n return result\n\ndef resize(a, new_shape):\n \"\"\"resize(a,new_shape) returns a new array with the specified shape.\n The original array's total size can be any size. It\n fills the new array with repeated copies of a.\n\n Note that a.resize(new_shape) will fill array with 0's\n beyond current definition of a.\n \"\"\"\n\n if isinstance(new_shape, (int, nt.integer)):\n new_shape = (new_shape,)\n a = ravel(a)\n Na = len(a)\n if not Na: return mu.zeros(new_shape, a.dtype.char)\n total_size = um.multiply.reduce(new_shape)\n n_copies = int(total_size / Na)\n extra = total_size % Na\n\n if total_size == 0:\n return a[:0]\n\n if extra != 0:\n n_copies = n_copies+1\n extra = Na-extra\n\n a = concatenate( (a,)*n_copies)\n if extra > 0:\n a = a[:-extra]\n\n return reshape(a, new_shape)\n\ndef squeeze(a):\n \"Returns a with any ones from the shape of a removed\"\n try:\n result = a.squeeze()\n except AttributeError:\n result = _wrapit(a, 'squeeze')\n return result\n\ndef diagonal(a, offset=0, axis1=0, axis2=1):\n \"\"\"diagonal(a, offset=0, axis1=0, axis2=1) returns the given diagonals\n defined by the last two dimensions of the array.\n \"\"\"\n return asarray(a).diagonal(offset, axis1, axis2)\n\ndef trace(a, offset=0, axis1=0, axis2=1, dtype=None):\n \"\"\"trace(a,offset=0, axis1=0, axis2=1) returns the sum along diagonals\n (defined by the last two dimenions) of the array.\n \"\"\"\n return asarray(a).trace(offset, axis1, axis2, dtype)\n\ndef ravel(m):\n \"\"\"ravel(m) returns a 1d array corresponding to all the elements of it's\n argument.\n \"\"\"\n return asarray(m).ravel()\n\ndef nonzero(a):\n \"\"\"nonzero(a) returns the indices of the elements of a which are not zero,\n a must be 1d\n \"\"\"\n try:\n result = a.nonzero()\n except AttributeError:\n result = _wrapit(a, 'nonzero')\n return result\n\ndef shape(a):\n \"\"\"shape(a) returns the shape of a (as a function call which\n also works on nested sequences).\n \"\"\"\n try:\n result = a.shape\n except AttributeError:\n result = asarray(a).shape\n return result\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 try:\n result = m.compress(condition, axis)\n except AttributeError:\n result = _wrapit(m, 'compress', condition, axis)\n return result\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 try:\n result = m.clip(m_min, m_max)\n except AttributeError:\n result = _wrapit(m, 'clip', m_min, m_max)\n return result\n\ndef sum(x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis. The optional dtype argument\n is the data type for intermediate calculations.\n\n The default is to upcast (promote) smaller integer types to the\n platform-dependent Int. For example, on 32-bit platforms:\n\n x.dtype default sum() dtype\n ---------------------------------------------------\n bool, Int8, Int16, Int32 Int32\n\n Examples:\n >>> sum([0.5, 1.5])\n 2.0\n >>> sum([0.5, 1.5], dtype=Int32)\n 1\n >>> sum([[0, 1], [0, 5]])\n array([0, 6])\n >>> sum([[0, 1], [0, 5]], axis=1)\n array([1, 5])\n \"\"\"\n if isinstance(x, _gentype):\n return _sum_(x)\n try:\n result = x.sum(axis, dtype)\n except AttributeError:\n result = _wrapit(x, 'sum', axis, dtype)\n return result\n\ndef product (x, axis=0, dtype=None):\n \"\"\"Product of the array elements over the given axis.\"\"\"\n try:\n result = x.prod(axis, dtype)\n except AttributeError:\n result = _wrapit(x, 'prod', axis, dtype)\n return result\n\ndef sometrue (x, axis=0):\n \"\"\"Perform a logical_or over the given axis.\"\"\"\n try:\n result = x.any(axis)\n except AttributeError:\n result = _wrapit(x, 'any', axis)\n return result\n\ndef alltrue (x, axis=0):\n \"\"\"Perform a logical_and over the given axis.\"\"\"\n try:\n result = x.all(axis)\n except AttributeError:\n result = _wrapit(x, 'all', axis)\n return result\n\ndef any(x,axis=None):\n \"\"\"Return true if any elements of x are true: \n \"\"\"\n try:\n result = x.any(axis)\n except AttributeError:\n result = _wrapit(x, 'any', axis)\n return result\n\ndef all(x,axis=None):\n \"\"\"Return true if all elements of x are true: \n \"\"\"\n try:\n result = x.all(axis)\n except AttributeError:\n result = _wrapit(x, 'all', axis)\n return result\n\ndef cumsum (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n try:\n result = x.cumsum(axis, dtype)\n except AttributeError:\n result = _wrapit(x, 'cumsum', axis, dtype)\n return result\n\ndef cumproduct (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n try:\n result = x.cumprod(axis, dtype)\n except AttributeError:\n result = _wrapit(x, 'cumprod', axis, dtype)\n return result\n\ndef ptp(a, axis=0):\n \"\"\"Return maximum - minimum along the the given dimension\n \"\"\"\n try:\n result = a.ptp(axis)\n except AttributeError:\n result = _wrapit(a, 'ptp', axis)\n return result\n\ndef amax(a, axis=0):\n \"\"\"Return the maximum of 'a' along dimension axis.\n \"\"\"\n try:\n result = a.max(axis)\n except AttributeError:\n result = _wrapit(a, 'max', axis)\n return result\n\ndef amin(a, axis=0):\n \"\"\"Return the minimum of a along dimension axis.\n \"\"\"\n try:\n result = a.min(axis)\n except AttributeError:\n result = _wrapit(a, 'min', axis)\n return result\n\ndef alen(a):\n \"\"\"Return the length of a Python object interpreted as an array\n of at least 1 dimension.\n \"\"\"\n try:\n return len(a)\n except TypeError:\n return len(array(a,ndmin=1))\n\ndef prod(a, axis=0, dtype=None):\n \"\"\"Return the product of the elements along the given axis\n \"\"\"\n try:\n result = a.prod(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'prod', axis, dtype)\n return result\n\ndef cumprod(a, axis=0, dtype=None):\n \"\"\"Return the cumulative product of the elments along the given axis\n \"\"\"\n try:\n result = a.cumprod(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'cumprod', axis, dtype)\n return result\n\ndef ndim(a):\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef rank(a):\n \"\"\"Get the rank of sequence a (the number of dimensions, not a matrix rank)\n The rank of a scalar is zero.\n \"\"\"\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef size (a, axis=None):\n \"Get the number of elements in sequence a, or along a certain axis.\"\n if axis is None:\n try:\n return a.size\n except AttributeError:\n return asarray(a).size\n else:\n try:\n return a.shape[axis]\n except AttributeError:\n return asarray(a).shape[axis]\n\ndef round_(a, decimals=0):\n \"\"\"Round 'a' to the given number of decimal places. Rounding\n behaviour is equivalent to Python.\n\n Return 'a' if the array is not floating point. Round both the real\n and imaginary parts separately if the array is complex.\n \"\"\"\n try:\n result = a.round(decimals)\n except AttributeError:\n result = _wrapit(a, 'round', decimals)\n return result\n\naround = round_\n\ndef mean(a, axis=0, dtype=None):\n try:\n result = a.mean(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'mean', axis, dtype)\n return result \n\ndef std(a, axis=0, dtype=None):\n try:\n result = a.std(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'std', axis, dtype)\n return result\n\ndef var(a, axis=0, dtype=None):\n try:\n result = a.std(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'var', axis, dtype)\n return result\n", + "source_code_before": "# Compatibility module containing deprecated names\n\n__all__ = ['asarray', 'array', 'concatenate',\n 'NewAxis',\n 'UFuncType', 'UfuncType', 'ArrayType', 'arraytype',\n 'LittleEndian', 'Bool',\n 'Character', 'UnsignedInt8', 'UnsignedInt16', 'UnsignedInt',\n 'UInt8','UInt16','UInt32', 'UnsignedInt32', 'UnsignedInteger',\n # UnsignedInt64 and Unsigned128 added below if possible\n # same for Int64 and Int128, Float128, and Complex128\n 'Int8', 'Int16', 'Int32',\n 'Int0', 'Int', 'Float0', 'Float', 'Complex0', 'Complex',\n 'PyObject', 'Float32', 'Float64', 'Float16', 'Float8',\n 'Complex32', 'Complex64', 'Complex8', 'Complex16',\n 'typecodes', 'sarray', 'arrayrange', 'cross_correlate',\n 'matrixmultiply', 'outerproduct', 'innerproduct',\n # from cPickle\n 'dump', 'dumps',\n # functions that are now methods\n 'take', 'reshape', 'choose', 'repeat', 'put', 'putmask',\n 'swapaxes', 'transpose', 'sort', 'argsort', 'argmax', 'argmin',\n 'searchsorted', 'alen',\n 'resize', 'diagonal', 'trace', 'ravel', 'nonzero', 'shape',\n 'compress', 'clip', 'sum', 'product', 'prod', 'sometrue', 'alltrue',\n 'any', 'all', 'cumsum', 'cumproduct', 'cumprod', 'ptp', 'ndim',\n 'rank', 'size', 'around', 'round_', 'mean', 'std', 'var', 'squeeze',\n 'amax', 'amin',\n ]\n\nimport multiarray as mu\nimport umath as um\nimport numerictypes as nt\nfrom numeric import asarray, array, asanyarray, correlate, outer, concatenate\nfrom umath import sign, absolute, multiply\nimport numeric as _nx\nimport sys\n_dt_ = nt.sctype2char\n\nimport types\n\ntry:\n _gentype = types.GeneratorType\nexcept AttributeError:\n _gentype = types.NoneType\n#Use this to add a new axis to an array\n#compatibility only\nNewAxis = None\n\n#deprecated\nUFuncType = type(um.sin)\nUfuncType = type(um.sin)\nArrayType = mu.ndarray\narraytype = mu.ndarray\n\nLittleEndian = (sys.byteorder == 'little')\n\n# save away Python sum\n_sum_ = sum\n\n# backward compatible names from old Precision.py\n\nCharacter = 'S1'\nUnsignedInt8 = _dt_(nt.uint8)\nUInt8 = UnsignedInt8\nUnsignedInt16 = _dt_(nt.uint16)\nUInt16 = UnsignedInt16\nUnsignedInt32 = _dt_(nt.uint32)\nUInt32 = UnsignedInt32\nUnsignedInt = _dt_(nt.uint)\n\ntry:\n UnsignedInt64 = _dt_(nt.uint64)\nexcept AttributeError:\n pass\nelse:\n UInt64 = UnsignedInt64\n __all__ += ['UnsignedInt64', 'UInt64']\ntry:\n UnsignedInt128 = _dt_(nt.uint128)\nexcept AttributeError:\n pass\nelse:\n UInt128 = UnsignedInt128\n __all__ += ['UnsignedInt128','UInt128']\n\nInt8 = _dt_(nt.int8)\nInt16 = _dt_(nt.int16)\nInt32 = _dt_(nt.int32)\n\ntry:\n Int64 = _dt_(nt.int64)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int64']\n\ntry:\n Int128 = _dt_(nt.int128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int128']\n\nBool = _dt_(bool)\nInt0 = _dt_(int)\nInt = _dt_(int)\nFloat0 = _dt_(float)\nFloat = _dt_(float)\nComplex0 = _dt_(complex)\nComplex = _dt_(complex)\nPyObject = _dt_(nt.object_)\nFloat32 = _dt_(nt.float32)\nFloat64 = _dt_(nt.float64)\n\nFloat16='f'\nFloat8='f'\nUnsignedInteger='L'\nComplex8='F'\nComplex16='F'\n\ntry:\n Float128 = _dt_(nt.float128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Float128']\n\nComplex32 = _dt_(nt.complex64)\nComplex64 = _dt_(nt.complex128)\n\ntry:\n Complex128 = _dt_(nt.complex256)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Complex128']\n\ntypecodes = {'Character':'S1',\n 'Integer':'bhilqp',\n 'UnsignedInteger':'BHILQP',\n 'Float':'fdg',\n 'Complex':'FDG',\n 'AllInteger':'bBhHiIlLqQpP',\n 'AllFloat':'fdgFDG',\n 'All':'?bhilqpBHILQPfdgFDGSUVO'}\n\ndef sarray(a, dtype=None, copy=False):\n return array(a, dtype, copy)\n\n# backward compatibility\narrayrange = mu.arange\ncross_correlate = correlate\n\n# deprecated names\nmatrixmultiply = mu.dot\nouterproduct = outer\ninnerproduct = mu.inner\n\nfrom cPickle import dump, dumps\n\n# functions that are now methods\n\ndef _wrapit(obj, method, *args, **kwds):\n try:\n wrap = obj.__array_wrap__\n except AttributeError:\n wrap = None\n result = getattr(asarray(obj),method)(*args, **kwds)\n if wrap:\n result = wrap(result)\n return result\n\ndef take(a, indices, axis=0):\n try:\n result = a.take(indices, axis)\n except AttributeError:\n result = _wrapit(a, 'take', indices, axis)\n return result\n\ndef reshape(a, newshape):\n \"\"\"Change the shape of a to newshape. Return a new view object.\n \"\"\"\n try:\n result = a.reshape(newshape)\n except AttributeError:\n result = _wrapit(a, 'reshape', newshape)\n return result\n\ndef choose(a, choices):\n try:\n result = a.choose(choices)\n except AttributeError:\n result = _wrapit(a, 'choose', choices)\n return result\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n 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 try:\n result = a.repeat(repeats, axis)\n except AttributeError:\n result = _wrapit(a, 'repeat', repeats, axis)\n return result\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.dtype)\n for i in ind: a.flat[i] = v[i]\n a must be a contiguous numpy array.\n \"\"\"\n return a.put(v,ind)\n\ndef putmask (a, mask, v):\n \"\"\"putmask(a, mask, v) results in a = v for all places mask is true.\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n \"\"\"\n return a.putmask(v, mask)\n\ndef swapaxes(a, axis1, axis2):\n \"\"\"swapaxes(a, axis1, axis2) returns array a with axis1 and axis2\n interchanged.\n \"\"\"\n try:\n result = a.swapaxes(axis1, axis2)\n except AttributeError:\n result = _wrapit(a, 'swapaxes', axis1, axis2)\n return result\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 try:\n result = a.transpose(axes)\n except AttributeError:\n result = _wrapit(a, 'transpose', axes)\n return result\n\ndef sort(a, axis=-1):\n \"\"\"sort(a,axis=-1) returns array with elements sorted along given axis.\n \"\"\"\n a = asanyarray(a, copy=True)\n a.sort(axis)\n return a\n\ndef argsort(a, axis=-1):\n \"\"\"argsort(a,axis=-1) return the indices into a of the sorted array\n along the given axis, so that take(a,result,axis) is the sorted array.\n \"\"\"\n try:\n result = a.argsort(axis)\n except AttributeError:\n result = _wrapit(a, 'argsort', axis)\n return result\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 try:\n result = a.argmax(axis)\n except AttributeError:\n result = _wrapit(a, 'argmax', axis)\n return result\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 try:\n result = a.argmin(axis)\n except AttributeError:\n result = _wrapit(a, 'argmin', axis)\n return result\n \ndef searchsorted(a, v):\n \"\"\"searchsorted(a, v)\n \"\"\"\n try:\n result = a.searchsorted(v)\n except AttributeError:\n result = _wrapit(a, 'searchsorted', v)\n return result\n\ndef resize(a, new_shape):\n \"\"\"resize(a,new_shape) returns a new array with the specified shape.\n The original array's total size can be any size. It\n fills the new array with repeated copies of a.\n\n Note that a.resize(new_shape) will fill array with 0's\n beyond current definition of a.\n \"\"\"\n\n if isinstance(new_shape, (int, nt.integer)):\n new_shape = (new_shape,)\n a = ravel(a)\n Na = len(a)\n if not Na: return mu.zeros(new_shape, a.dtype.char)\n total_size = um.multiply.reduce(new_shape)\n n_copies = int(total_size / Na)\n extra = total_size % Na\n\n if total_size == 0:\n return a[:0]\n\n if extra != 0:\n n_copies = n_copies+1\n extra = Na-extra\n\n a = concatenate( (a,)*n_copies)\n if extra > 0:\n a = a[:-extra]\n\n return reshape(a, new_shape)\n\ndef squeeze(a):\n \"Returns a with any ones from the shape of a removed\"\n try:\n result = a.squeeze()\n except AttributeError:\n result = _wrapit(a, 'squeeze')\n return result\n\ndef diagonal(a, offset=0, axis1=0, axis2=1):\n \"\"\"diagonal(a, offset=0, axis1=0, axis2=1) returns the given diagonals\n defined by the last two dimensions of the array.\n \"\"\"\n return asarray(a).diagonal(offset, axis1, axis2)\n\ndef trace(a, offset=0, axis1=0, axis2=1, dtype=None):\n \"\"\"trace(a,offset=0, axis1=0, axis2=1) returns the sum along diagonals\n (defined by the last two dimenions) of the array.\n \"\"\"\n return asarray(a).trace(offset, axis1, axis2, dtype)\n\ndef ravel(m):\n \"\"\"ravel(m) returns a 1d array corresponding to all the elements of it's\n argument.\n \"\"\"\n return asarray(m).ravel()\n\ndef nonzero(a):\n \"\"\"nonzero(a) returns the indices of the elements of a which are not zero,\n a must be 1d\n \"\"\"\n try:\n result = a.nonzero()\n except AttributeError:\n result = _wrapit(a, 'nonzero')\n return result\n\ndef shape(a):\n \"\"\"shape(a) returns the shape of a (as a function call which\n also works on nested sequences).\n \"\"\"\n try:\n result = a.shape\n except AttributeError:\n result = asarray(a).shape\n return result\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 try:\n result = m.compress(condition, axis)\n except AttributeError:\n result = _wrapit(m, 'compress', condition, axis)\n return result\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 try:\n result = m.clip(m_min, m_max)\n except AttributeError:\n result = _wrapit(m, 'clip', m_min, m_max)\n return result\n\ndef sum(x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis. The optional dtype argument\n is the data type for intermediate calculations.\n\n The default is to upcast (promote) smaller integer types to the\n platform-dependent Int. For example, on 32-bit platforms:\n\n x.dtype default sum() dtype\n ---------------------------------------------------\n bool, Int8, Int16, Int32 Int32\n\n Examples:\n >>> sum([0.5, 1.5])\n 2.0\n >>> sum([0.5, 1.5], dtype=Int32)\n 1\n >>> sum([[0, 1], [0, 5]])\n array([0, 6])\n >>> sum([[0, 1], [0, 5]], axis=1)\n array([1, 5])\n \"\"\"\n if isinstance(x, _gentype):\n return _sum_(x)\n try:\n result = x.sum(axis, dtype)\n except AttributeError:\n result = _wrapit(x, 'sum', axis, dtype)\n return result\n\ndef product (x, axis=0, dtype=None):\n \"\"\"Product of the array elements over the given axis.\"\"\"\n try:\n result = x.prod(axis, dtype)\n except AttributeError:\n result = _wrapit(x, 'prod', axis, dtype)\n return result\n\ndef sometrue (x, axis=0):\n \"\"\"Perform a logical_or over the given axis.\"\"\"\n try:\n result = x.any(axis)\n except AttributeError:\n result = _wrapit(x, 'any', axis)\n return result\n\ndef alltrue (x, axis=0):\n \"\"\"Perform a logical_and over the given axis.\"\"\"\n try:\n result = x.all(axis)\n except AttributeError:\n result = _wrapit(x, 'all', axis)\n return result\n\ndef any(x,axis=None):\n \"\"\"Return true if any elements of x are true: \n \"\"\"\n try:\n result = x.any(axis)\n except AttributeError:\n result = _wrapit(x, 'any', axis)\n return result\n\ndef all(x,axis=None):\n \"\"\"Return true if all elements of x are true: \n \"\"\"\n try:\n result = x.all(axis)\n except AttributeError:\n result = _wrapit(x, 'all', axis)\n return result\n\ndef cumsum (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n try:\n result = x.cumsum(axis, dtype)\n except AttributeError:\n result = _wrapit(x, 'cumsum', axis, dtype)\n return result\n\ndef cumproduct (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n try:\n result = x.cumprod(axis, dtype)\n except AttributeError:\n result = _wrapit(x, 'cumprod', axis, dtype)\n return result\n\ndef ptp(a, axis=0):\n \"\"\"Return maximum - minimum along the the given dimension\n \"\"\"\n try:\n result = a.ptp(axis)\n except AttributeError:\n result = _wrapit(a, 'ptp', axis)\n return result\n\ndef amax(a, axis=0):\n \"\"\"Return the maximum of 'a' along dimension axis.\n \"\"\"\n try:\n result = a.max(axis)\n except AttributeError:\n result = _wrapit(a, 'max', axis)\n return result\n\ndef amin(a, axis=0):\n \"\"\"Return the minimum of a along dimension axis.\n \"\"\"\n try:\n result = a.min(axis)\n except AttributeError:\n result = _wrapit(a, 'min', axis)\n return result\n\ndef alen(a):\n \"\"\"Return the length of a Python object interpreted as an array\n of at least 1 dimension.\n \"\"\"\n try:\n return len(a)\n except TypeError:\n return len(atleast_1d(a))\n\ndef prod(a, axis=0, dtype=None):\n \"\"\"Return the product of the elements along the given axis\n \"\"\"\n try:\n result = a.prod(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'prod', axis, dtype)\n return result\n\ndef cumprod(a, axis=0, dtype=None):\n \"\"\"Return the cumulative product of the elments along the given axis\n \"\"\"\n try:\n result = a.cumprod(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'cumprod', axis, dtype)\n return result\n\ndef ndim(a):\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef rank(a):\n \"\"\"Get the rank of sequence a (the number of dimensions, not a matrix rank)\n The rank of a scalar is zero.\n \"\"\"\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef size (a, axis=None):\n \"Get the number of elements in sequence a, or along a certain axis.\"\n if axis is None:\n try:\n return a.size\n except AttributeError:\n return asarray(a).size\n else:\n try:\n return a.shape[axis]\n except AttributeError:\n return asarray(a).shape[axis]\n\ndef round_(a, decimals=0):\n \"\"\"Round 'a' to the given number of decimal places. Rounding\n behaviour is equivalent to Python.\n\n Return 'a' if the array is not floating point. Round both the real\n and imaginary parts separately if the array is complex.\n \"\"\"\n try:\n result = a.round(decimals)\n except AttributeError:\n result = _wrapit(a, 'round', decimals)\n return result\n\naround = round_\n\ndef mean(a, axis=0, dtype=None):\n try:\n result = a.mean(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'mean', axis, dtype)\n return result \n\ndef std(a, axis=0, dtype=None):\n try:\n result = a.std(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'std', axis, dtype)\n return result\n\ndef var(a, axis=0, dtype=None):\n try:\n result = a.std(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'var', axis, dtype)\n return result\n", + "methods": [ + { + "name": "sarray", + "long_name": "sarray( a , dtype = None , copy = False )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "dtype", + "copy" + ], + "start_line": 147, + "end_line": 148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_wrapit", + "long_name": "_wrapit( obj , method , * args , ** kwds )", + "filename": "oldnumeric.py", + "nloc": 9, + "complexity": 3, + "token_count": 55, + "parameters": [ + "obj", + "method", + "args", + "kwds" + ], + "start_line": 163, + "end_line": 171, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 40, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 173, + "end_line": 178, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , newshape )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 33, + "parameters": [ + "a", + "newshape" + ], + "start_line": 180, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "choose", + "long_name": "choose( a , choices )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 32, + "parameters": [ + "a", + "choices" + ], + "start_line": 189, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 196, + "end_line": 208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , ind , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "ind", + "v" + ], + "start_line": 210, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "mask", + "v" + ], + "start_line": 224, + "end_line": 229, + "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": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "a", + "axis1", + "axis2" + ], + "start_line": 231, + "end_line": 239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "axes" + ], + "start_line": 241, + "end_line": 250, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "sort", + "long_name": "sort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis" + ], + "start_line": 252, + "end_line": 257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "a", + "axis" + ], + "start_line": 259, + "end_line": 267, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "a", + "axis" + ], + "start_line": 269, + "end_line": 277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "a", + "axis" + ], + "start_line": 279, + "end_line": 287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "searchsorted", + "long_name": "searchsorted( a , v )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 33, + "parameters": [ + "a", + "v" + ], + "start_line": 289, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "oldnumeric.py", + "nloc": 18, + "complexity": 6, + "token_count": 137, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 298, + "end_line": 327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "squeeze", + "long_name": "squeeze( a )", + "filename": "oldnumeric.py", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "a" + ], + "start_line": 329, + "end_line": 335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "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": 337, + "end_line": 341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "trace", + "long_name": "trace( a , offset = 0 , axis1 = 0 , axis2 = 1 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 38, + "parameters": [ + "a", + "offset", + "axis1", + "axis2", + "dtype" + ], + "start_line": 343, + "end_line": 347, + "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": 349, + "end_line": 353, + "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": 6, + "complexity": 2, + "token_count": 28, + "parameters": [ + "a" + ], + "start_line": 355, + "end_line": 363, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( a )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 26, + "parameters": [ + "a" + ], + "start_line": 365, + "end_line": 373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , m , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "condition", + "m", + "axis" + ], + "start_line": 375, + "end_line": 383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "clip", + "long_name": "clip( m , m_min , m_max )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "m", + "m_min", + "m_max" + ], + "start_line": 385, + "end_line": 394, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "sum", + "long_name": "sum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 8, + "complexity": 3, + "token_count": 56, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 396, + "end_line": 423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "product", + "long_name": "product( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 425, + "end_line": 431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "sometrue", + "long_name": "sometrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "x", + "axis" + ], + "start_line": 433, + "end_line": 439, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "alltrue", + "long_name": "alltrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "x", + "axis" + ], + "start_line": 441, + "end_line": 447, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "any", + "long_name": "any( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "x", + "axis" + ], + "start_line": 449, + "end_line": 456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "all", + "long_name": "all( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "x", + "axis" + ], + "start_line": 458, + "end_line": 465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "cumsum", + "long_name": "cumsum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 467, + "end_line": 473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "cumproduct", + "long_name": "cumproduct( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 475, + "end_line": 481, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "ptp", + "long_name": "ptp( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "axis" + ], + "start_line": 483, + "end_line": 490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "amax", + "long_name": "amax( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "axis" + ], + "start_line": 492, + "end_line": 499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "amin", + "long_name": "amin( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "axis" + ], + "start_line": 501, + "end_line": 508, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "alen", + "long_name": "alen( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 28, + "parameters": [ + "a" + ], + "start_line": 510, + "end_line": 517, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "prod", + "long_name": "prod( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 519, + "end_line": 526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "cumprod", + "long_name": "cumprod( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 528, + "end_line": 535, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ndim", + "long_name": "ndim( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 21, + "parameters": [ + "a" + ], + "start_line": 537, + "end_line": 541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rank", + "long_name": "rank( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "a" + ], + "start_line": 543, + "end_line": 550, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( a , axis = None )", + "filename": "oldnumeric.py", + "nloc": 12, + "complexity": 4, + "token_count": 55, + "parameters": [ + "a", + "axis" + ], + "start_line": 552, + "end_line": 563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "round_", + "long_name": "round_( a , decimals = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "decimals" + ], + "start_line": 565, + "end_line": 576, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "mean", + "long_name": "mean( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 580, + "end_line": 585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "std", + "long_name": "std( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 587, + "end_line": 592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "var", + "long_name": "var( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 594, + "end_line": 599, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "sarray", + "long_name": "sarray( a , dtype = None , copy = False )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "dtype", + "copy" + ], + "start_line": 147, + "end_line": 148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_wrapit", + "long_name": "_wrapit( obj , method , * args , ** kwds )", + "filename": "oldnumeric.py", + "nloc": 9, + "complexity": 3, + "token_count": 55, + "parameters": [ + "obj", + "method", + "args", + "kwds" + ], + "start_line": 163, + "end_line": 171, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 40, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 173, + "end_line": 178, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , newshape )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 33, + "parameters": [ + "a", + "newshape" + ], + "start_line": 180, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "choose", + "long_name": "choose( a , choices )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 32, + "parameters": [ + "a", + "choices" + ], + "start_line": 189, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 196, + "end_line": 208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , ind , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "ind", + "v" + ], + "start_line": 210, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "mask", + "v" + ], + "start_line": 224, + "end_line": 229, + "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": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "a", + "axis1", + "axis2" + ], + "start_line": 231, + "end_line": 239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "axes" + ], + "start_line": 241, + "end_line": 250, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "sort", + "long_name": "sort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis" + ], + "start_line": 252, + "end_line": 257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "a", + "axis" + ], + "start_line": 259, + "end_line": 267, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "a", + "axis" + ], + "start_line": 269, + "end_line": 277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "a", + "axis" + ], + "start_line": 279, + "end_line": 287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "searchsorted", + "long_name": "searchsorted( a , v )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 33, + "parameters": [ + "a", + "v" + ], + "start_line": 289, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "oldnumeric.py", + "nloc": 18, + "complexity": 6, + "token_count": 137, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 298, + "end_line": 327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "squeeze", + "long_name": "squeeze( a )", + "filename": "oldnumeric.py", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "a" + ], + "start_line": 329, + "end_line": 335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "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": 337, + "end_line": 341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "trace", + "long_name": "trace( a , offset = 0 , axis1 = 0 , axis2 = 1 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 38, + "parameters": [ + "a", + "offset", + "axis1", + "axis2", + "dtype" + ], + "start_line": 343, + "end_line": 347, + "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": 349, + "end_line": 353, + "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": 6, + "complexity": 2, + "token_count": 28, + "parameters": [ + "a" + ], + "start_line": 355, + "end_line": 363, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( a )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 26, + "parameters": [ + "a" + ], + "start_line": 365, + "end_line": 373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , m , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "condition", + "m", + "axis" + ], + "start_line": 375, + "end_line": 383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "clip", + "long_name": "clip( m , m_min , m_max )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "m", + "m_min", + "m_max" + ], + "start_line": 385, + "end_line": 394, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "sum", + "long_name": "sum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 8, + "complexity": 3, + "token_count": 56, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 396, + "end_line": 423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "product", + "long_name": "product( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 425, + "end_line": 431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "sometrue", + "long_name": "sometrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "x", + "axis" + ], + "start_line": 433, + "end_line": 439, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "alltrue", + "long_name": "alltrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "x", + "axis" + ], + "start_line": 441, + "end_line": 447, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "any", + "long_name": "any( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "x", + "axis" + ], + "start_line": 449, + "end_line": 456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "all", + "long_name": "all( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "x", + "axis" + ], + "start_line": 458, + "end_line": 465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "cumsum", + "long_name": "cumsum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 467, + "end_line": 473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "cumproduct", + "long_name": "cumproduct( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 475, + "end_line": 481, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "ptp", + "long_name": "ptp( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "axis" + ], + "start_line": 483, + "end_line": 490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "amax", + "long_name": "amax( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "axis" + ], + "start_line": 492, + "end_line": 499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "amin", + "long_name": "amin( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "axis" + ], + "start_line": 501, + "end_line": 508, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "alen", + "long_name": "alen( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "a" + ], + "start_line": 510, + "end_line": 517, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "prod", + "long_name": "prod( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 519, + "end_line": 526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "cumprod", + "long_name": "cumprod( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 528, + "end_line": 535, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ndim", + "long_name": "ndim( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 21, + "parameters": [ + "a" + ], + "start_line": 537, + "end_line": 541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rank", + "long_name": "rank( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "a" + ], + "start_line": 543, + "end_line": 550, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( a , axis = None )", + "filename": "oldnumeric.py", + "nloc": 12, + "complexity": 4, + "token_count": 55, + "parameters": [ + "a", + "axis" + ], + "start_line": 552, + "end_line": 563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "round_", + "long_name": "round_( a , decimals = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "decimals" + ], + "start_line": 565, + "end_line": 576, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "mean", + "long_name": "mean( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 580, + "end_line": 585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "std", + "long_name": "std( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 587, + "end_line": 592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "var", + "long_name": "var( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 594, + "end_line": 599, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "alen", + "long_name": "alen( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 28, + "parameters": [ + "a" + ], + "start_line": 510, + "end_line": 517, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "nloc": 388, + "complexity": 91, + "token_count": 2391, + "diff_parsed": { + "added": [ + " return len(array(a,ndmin=1))" + ], + "deleted": [ + " return len(atleast_1d(a))" + ] + } + }, + { + "old_path": "numpy/linalg/linalg.py", + "new_path": "numpy/linalg/linalg.py", + "filename": "linalg.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -12,6 +12,7 @@\n 'eigvalsh', 'pinv',\n 'det', 'svd',\n 'eig', 'eigh','lstsq', 'norm',\n+ 'LinAlgError'\n ]\n \n from numpy.core import *\n@@ -19,9 +20,11 @@\n from old import solve_linear_equations\n import lapack_lite\n \n+# Error object\n+class LinAlgError(Exception):\n+ pass\n+\n # Helper routines\n-_lapack_type = {'f': 0, 'd': 1, 'F': 2, 'D': 3}\n-_lapack_letter = ['s', 'd', 'c', 'z']\n _array_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\n _array_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\n _array_type = [['f', 'd'], ['F', 'D']]\n@@ -108,7 +111,7 @@ def solve(a, b):\n \n def inv(a):\n a, wrap = _makearray(a)\n- return wrap(solve_linear_equations(a, identity(a.shape[0])))\n+ return wrap(solve(a, identity(a.shape[0])))\n \n # Cholesky decomposition\n \n@@ -415,8 +418,7 @@ def det(a):\n lapack_routine = lapack_lite.dgetrf\n pivots = zeros((n,), 'i')\n results = lapack_routine(n, n, a, n, pivots, 0)\n- sign = add.reduce(not_equal(pivots,\n- arrayrange(1, n+1))) % 2\n+ sign = add.reduce(not_equal(pivots, arrayrange(1, n+1))) % 2\n return (1.-2.*sign)*multiply.reduce(diagonal(a),axis=-1)\n \n # Linear Least Squares\n", + "added_lines": 7, + "deleted_lines": 5, + "source_code": "\n\"\"\"Lite version of scipy.linalg.\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n__all__ = ['solve',\n 'inv', 'cholesky',\n 'eigvals',\n 'eigvalsh', 'pinv',\n 'det', 'svd',\n 'eig', 'eigh','lstsq', 'norm',\n 'LinAlgError'\n ]\n\nfrom numpy.core import *\nfrom numpy.lib import *\nfrom old import solve_linear_equations\nimport lapack_lite\n\n# Error object\nclass LinAlgError(Exception):\n pass\n\n# Helper routines\n_array_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\n_array_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\n_array_type = [['f', 'd'], ['F', 'D']]\n\ndef _makearray(a):\n new = asarray(a)\n wrap = getattr(a, \"__array_wrap__\", new.__array_wrap__)\n return new, wrap\n\ndef _commonType(*arrays):\n kind = 0\n# precision = 0\n# force higher precision in lite version\n precision = 1\n for a in arrays:\n t = a.dtype.char\n kind = max(kind, _array_kind[t])\n precision = max(precision, _array_precision[t])\n return _array_type[kind][precision]\n\ndef _castCopyAndTranspose(type, *arrays):\n if len(arrays) == 1:\n return transpose(arrays[0]).astype(type)\n else:\n return [transpose(a).astype(type) for a in arrays]\n\n# _fastCopyAndTranpose is an optimized version of _castCopyAndTranspose.\n# It assumes the input is 2D (as all the calls in here are).\n\n_fastCT = fastCopyAndTranspose\n\ndef _fastCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.dtype.char == type:\n cast_arrays = cast_arrays + (_fastCT(a),)\n else:\n cast_arrays = cast_arrays + (_fastCT(a.astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\ndef _assertRank2(*arrays):\n for a in arrays:\n if len(a.shape) != 2:\n raise LinAlgError, 'Array must be two-dimensional'\n\ndef _assertSquareness(*arrays):\n for a in arrays:\n if max(a.shape) != min(a.shape):\n raise LinAlgError, 'Array must be square'\n\n# Linear equations\n\ndef solve(a, b):\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n _assertSquareness(a)\n n_eq = a.shape[0]\n n_rhs = b.shape[1]\n if n_eq != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n# lapack_routine = _findLapackRoutine('gesv', t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesv\n else:\n lapack_routine = lapack_lite.dgesv\n a, b = _fastCopyAndTranspose(t, a, b)\n pivots = zeros(n_eq, 'i')\n results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Singular matrix'\n if one_eq:\n return ravel(b) # I see no need to copy here\n else:\n return transpose(b) # no need to copy\n\n\n# Matrix inversion\n\ndef inv(a):\n a, wrap = _makearray(a)\n return wrap(solve(a, identity(a.shape[0])))\n\n# Cholesky decomposition\n\ndef cholesky(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _castCopyAndTranspose(t, a)\n m = a.shape[0]\n n = a.shape[1]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zpotrf\n else:\n lapack_routine = lapack_lite.dpotrf\n results = lapack_routine('L', n, a, m, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Matrix is not positive definite - Cholesky decomposition cannot be computed'\n return transpose(triu(a,k=0)).copy()\n\n\n# Eigenvalues\ndef eigvals(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n dummy = zeros((1,), t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n rwork = zeros((n,),real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n else:\n w = wr+1j*wi\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\n\ndef eigvalsh(a, UPLO='L'):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\ndef _convertarray(a):\n if issubclass(a.dtype.type, complexfloating):\n if a.dtype.char == 'D':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('D'))\n else:\n if a.dtype.char == 'd':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('d'))\n return a, a.dtype.char\n\n# Eigenvectors\n\ndef eig(a):\n \"\"\"eig(a) returns u,v where u is the eigenvalues and\nv is a matrix of eigenvectors with vector v[:,i] corresponds to\neigenvalue u[i]. Satisfies the equation dot(a, v[:,i]) = u[i]*v[:,i]\n\"\"\"\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n a,t = _convertarray(a) # convert to float_ or complex_ type\n real_t = 'd'\n n = a.shape[0]\n dummy = zeros((1,), t)\n if t == 'D': # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n v = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n rwork = zeros((2*n,),real_t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n vr = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n v = vr\n else:\n w = wr+1j*wi\n v = array(vr,Complex)\n ind = nonzero(\n equal(\n equal(wi,0.0) # true for real e-vals\n ,0) # true for complex e-vals\n ) # indices of complex e-vals\n for i in range(len(ind)/2):\n v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]]\n v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]]\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(v.transpose())\n\n\ndef eigh(a, UPLO='L'):\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(a.transpose())\n\n\n# Singular value decomposition\n\ndef svd(a, full_matrices=1, compute_uv=1):\n a, wrap = _makearray(a)\n _assertRank2(a)\n m, n = a.shape\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n s = zeros((min(n,m),), real_t)\n if compute_uv:\n if full_matrices:\n nu = m\n nvt = n\n option = 'A'\n else:\n nu = min(n,m)\n nvt = min(n,m)\n option = 'S'\n u = zeros((nu, m), t)\n vt = zeros((n, nvt), t)\n else:\n option = 'N'\n nu = 1\n nvt = 1\n u = empty((1,1),t) \n vt = empty((1,1),t) \n\n iwork = zeros((8*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesdd\n rwork = zeros((5*min(m,n)*min(m,n) + 5*min(m,n),), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, rwork, iwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, rwork, iwork, 0)\n else:\n lapack_routine = lapack_lite.dgesdd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, iwork, 0)\n lwork = int(work[0])\n if option == 'N' and lwork==1:\n # there seems to be a bug in dgesdd of lapack\n # (NNemec, 060310)\n # returning the wrong lwork size for option == 'N'\n results = lapack_routine('A', m, n, a, m, s, u, m, vt, n,\n work, -1, iwork, 0)\n lwork = int(work[0])\n assert lwork > 1\n\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, iwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge'\n if compute_uv:\n return wrap(transpose(u)), s, \\\n wrap(transpose(vt)) # why copy here?\n else:\n return s\n\n# Generalized inverse\n\ndef pinv(a, rcond = 1.e-10):\n a, wrap = _makearray(a)\n if a.dtype.char in typecodes['Complex']:\n a = conjugate(a)\n u, s, vt = svd(a, 0)\n m = u.shape[0]\n n = vt.shape[1]\n cutoff = rcond*maximum.reduce(s)\n for i in range(min(n,m)):\n if s[i] > cutoff:\n s[i] = 1./s[i]\n else:\n s[i] = 0.;\n return wrap(dot(transpose(vt),\n multiply(s[:, NewAxis],transpose(u))))\n\n# Determinant\n\ndef det(a):\n a = asarray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zgetrf\n else:\n lapack_routine = lapack_lite.dgetrf\n pivots = zeros((n,), 'i')\n results = lapack_routine(n, n, a, n, pivots, 0)\n sign = add.reduce(not_equal(pivots, arrayrange(1, n+1))) % 2\n return (1.-2.*sign)*multiply.reduce(diagonal(a),axis=-1)\n\n# Linear Least Squares\n\ndef lstsq(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n import math\n a = asarray(a)\n b, wrap = _makearray(b)\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n m = a.shape[0]\n n = a.shape[1]\n n_rhs = b.shape[1]\n ldb = max(n,m)\n if m != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n real_t = _array_type[0][_array_precision[t]]\n bstar = zeros((ldb,n_rhs),t)\n bstar[:b.shape[0],:n_rhs] = b.copy()\n a,bstar = _castCopyAndTranspose(t, a, bstar)\n s = zeros((min(m,n),),real_t)\n nlvl = max( 0, int( math.log( float(min( m,n ))/2. ) ) + 1 )\n iwork = zeros((3*min(m,n)*nlvl+11*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgelsd\n lwork = 1\n rwork = zeros((lwork,), real_t)\n work = zeros((lwork,),t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,rwork,iwork,0 )\n lwork = int(abs(work[0]))\n rwork = zeros((lwork,),real_t)\n a_real = zeros((m,n),real_t)\n bstar_real = zeros((ldb,n_rhs,),real_t)\n results = lapack_lite.dgelsd( m, n, n_rhs, a_real, m, bstar_real,ldb , s, rcond,\n 0,rwork,-1,iwork,0 )\n lrwork = int(rwork[0])\n work = zeros((lwork,), t)\n rwork = zeros((lrwork,), real_t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,rwork,iwork,0 )\n else:\n lapack_routine = lapack_lite.dgelsd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,iwork,0 )\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,iwork,0 )\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge in Linear Least Squares'\n resids = array([],t)\n if one_eq:\n x = ravel(bstar)[:n].copy()\n if (results['rank']==n) and (m>n):\n resids = array([sum((ravel(bstar)[n:])**2)])\n else:\n x = transpose(bstar)[:n,:].copy()\n if (results['rank']==n) and (m>n):\n resids = sum((transpose(bstar)[n:,:])**2).copy()\n return wrap(x),resids,results['rank'],s[:min(n,m)].copy()\n\ndef norm(x, ord=None):\n \"\"\" norm(x, ord=None) -> n\n\n Matrix or vector norm.\n\n Inputs:\n\n x -- a rank-1 (vector) or rank-2 (matrix) array\n ord -- the order of the norm.\n\n Comments:\n For arrays of any rank, if ord is None:\n calculate the square norm (Euclidean norm for vectors, Frobenius norm for matrices)\n\n For vectors ord can be any real number including Inf or -Inf.\n ord = Inf, computes the maximum of the magnitudes\n ord = -Inf, computes minimum of the magnitudes\n ord is finite, computes sum(abs(x)**ord)**(1.0/ord)\n\n For matrices ord can only be one of the following values:\n ord = 2 computes the largest singular value\n ord = -2 computes the smallest singular value\n ord = 1 computes the largest column sum of absolute values\n ord = -1 computes the smallest column sum of absolute values\n ord = Inf computes the largest row sum of absolute values\n ord = -Inf computes the smallest row sum of absolute values\n ord = 'fro' computes the frobenius norm sqrt(sum(diag(X.H * X)))\n\n For values ord < 0, the result is, strictly speaking, not a\n mathematical 'norm', but it may still be useful for numerical purposes.\n \"\"\"\n x = asarray(x)\n nd = len(x.shape) \n if ord is None: # check the default case first and handle it immediately\n return sqrt(add.reduce((x.conj() * x).ravel().real))\n\n if nd == 1:\n if ord == Inf:\n return abs(x).max()\n elif ord == -Inf:\n return abs(x).min()\n elif ord == 1:\n return abs(x).sum() # special case for speedup\n elif ord == 2:\n return sqrt(((x.conj()*x).real).sum()) # special case for speedup\n else:\n return ((abs(x)**ord).sum())**(1.0/ord)\n elif nd == 2:\n if ord == 2:\n return svd(x,compute_uv=0).max()\n elif ord == -2:\n return svd(x,compute_uv=0).min()\n elif ord == 1:\n return abs(x).sum(axis=0).max()\n elif ord == Inf:\n return abs(x).sum(axis=1).max()\n elif ord == -1:\n return abs(x).sum(axis=0).min()\n elif ord == -Inf:\n return abs(x).sum(axis=1).min()\n elif ord in ['fro','f']:\n return sqrt(add.reduce((x.conj() * x).real.ravel()))\n else:\n raise ValueError, \"Invalid norm order for matrices.\"\n else:\n raise ValueError, \"Improper number of dimensions to norm.\"\n\nif __name__ == '__main__':\n def test(a, b):\n\n print \"All numbers printed should be (almost) zero:\"\n\n x = solve(a, b)\n check = b - matrixmultiply(a, x)\n print check\n\n\n a_inv = inv(a)\n check = matrixmultiply(a, a_inv)-identity(a.shape[0])\n print check\n\n\n ev = eigvals(a)\n\n evalues, evectors = eig(a)\n check = ev-evalues\n print check\n\n evectors = transpose(evectors)\n check = matrixmultiply(a, evectors)-evectors*evalues\n print check\n\n\n u, s, vt = svd(a,0)\n check = a - matrixmultiply(u*s, vt)\n print check\n\n\n a_ginv = pinv(a)\n check = matrixmultiply(a, a_ginv)-identity(a.shape[0])\n print check\n\n\n det = det(a)\n check = det-multiply.reduce(evalues)\n print check\n\n x, residuals, rank, sv = lstsq(a, b)\n check = b - matrixmultiply(a, x)\n print check\n print rank-a.shape[0]\n print sv-s\n\n a = array([[1.,2.], [3.,4.]])\n b = array([2., 1.])\n test(a, b)\n\n a = a+0j\n b = b+0j\n test(a, b)\n", + "source_code_before": "\n\"\"\"Lite version of scipy.linalg.\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n__all__ = ['solve',\n 'inv', 'cholesky',\n 'eigvals',\n 'eigvalsh', 'pinv',\n 'det', 'svd',\n 'eig', 'eigh','lstsq', 'norm',\n ]\n\nfrom numpy.core import *\nfrom numpy.lib import *\nfrom old import solve_linear_equations\nimport lapack_lite\n\n# Helper routines\n_lapack_type = {'f': 0, 'd': 1, 'F': 2, 'D': 3}\n_lapack_letter = ['s', 'd', 'c', 'z']\n_array_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\n_array_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\n_array_type = [['f', 'd'], ['F', 'D']]\n\ndef _makearray(a):\n new = asarray(a)\n wrap = getattr(a, \"__array_wrap__\", new.__array_wrap__)\n return new, wrap\n\ndef _commonType(*arrays):\n kind = 0\n# precision = 0\n# force higher precision in lite version\n precision = 1\n for a in arrays:\n t = a.dtype.char\n kind = max(kind, _array_kind[t])\n precision = max(precision, _array_precision[t])\n return _array_type[kind][precision]\n\ndef _castCopyAndTranspose(type, *arrays):\n if len(arrays) == 1:\n return transpose(arrays[0]).astype(type)\n else:\n return [transpose(a).astype(type) for a in arrays]\n\n# _fastCopyAndTranpose is an optimized version of _castCopyAndTranspose.\n# It assumes the input is 2D (as all the calls in here are).\n\n_fastCT = fastCopyAndTranspose\n\ndef _fastCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.dtype.char == type:\n cast_arrays = cast_arrays + (_fastCT(a),)\n else:\n cast_arrays = cast_arrays + (_fastCT(a.astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\ndef _assertRank2(*arrays):\n for a in arrays:\n if len(a.shape) != 2:\n raise LinAlgError, 'Array must be two-dimensional'\n\ndef _assertSquareness(*arrays):\n for a in arrays:\n if max(a.shape) != min(a.shape):\n raise LinAlgError, 'Array must be square'\n\n# Linear equations\n\ndef solve(a, b):\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n _assertSquareness(a)\n n_eq = a.shape[0]\n n_rhs = b.shape[1]\n if n_eq != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n# lapack_routine = _findLapackRoutine('gesv', t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesv\n else:\n lapack_routine = lapack_lite.dgesv\n a, b = _fastCopyAndTranspose(t, a, b)\n pivots = zeros(n_eq, 'i')\n results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Singular matrix'\n if one_eq:\n return ravel(b) # I see no need to copy here\n else:\n return transpose(b) # no need to copy\n\n\n# Matrix inversion\n\ndef inv(a):\n a, wrap = _makearray(a)\n return wrap(solve_linear_equations(a, identity(a.shape[0])))\n\n# Cholesky decomposition\n\ndef cholesky(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _castCopyAndTranspose(t, a)\n m = a.shape[0]\n n = a.shape[1]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zpotrf\n else:\n lapack_routine = lapack_lite.dpotrf\n results = lapack_routine('L', n, a, m, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Matrix is not positive definite - Cholesky decomposition cannot be computed'\n return transpose(triu(a,k=0)).copy()\n\n\n# Eigenvalues\ndef eigvals(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n dummy = zeros((1,), t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n rwork = zeros((n,),real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n else:\n w = wr+1j*wi\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\n\ndef eigvalsh(a, UPLO='L'):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\ndef _convertarray(a):\n if issubclass(a.dtype.type, complexfloating):\n if a.dtype.char == 'D':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('D'))\n else:\n if a.dtype.char == 'd':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('d'))\n return a, a.dtype.char\n\n# Eigenvectors\n\ndef eig(a):\n \"\"\"eig(a) returns u,v where u is the eigenvalues and\nv is a matrix of eigenvectors with vector v[:,i] corresponds to\neigenvalue u[i]. Satisfies the equation dot(a, v[:,i]) = u[i]*v[:,i]\n\"\"\"\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n a,t = _convertarray(a) # convert to float_ or complex_ type\n real_t = 'd'\n n = a.shape[0]\n dummy = zeros((1,), t)\n if t == 'D': # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n v = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n rwork = zeros((2*n,),real_t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n vr = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n v = vr\n else:\n w = wr+1j*wi\n v = array(vr,Complex)\n ind = nonzero(\n equal(\n equal(wi,0.0) # true for real e-vals\n ,0) # true for complex e-vals\n ) # indices of complex e-vals\n for i in range(len(ind)/2):\n v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]]\n v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]]\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(v.transpose())\n\n\ndef eigh(a, UPLO='L'):\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(a.transpose())\n\n\n# Singular value decomposition\n\ndef svd(a, full_matrices=1, compute_uv=1):\n a, wrap = _makearray(a)\n _assertRank2(a)\n m, n = a.shape\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n s = zeros((min(n,m),), real_t)\n if compute_uv:\n if full_matrices:\n nu = m\n nvt = n\n option = 'A'\n else:\n nu = min(n,m)\n nvt = min(n,m)\n option = 'S'\n u = zeros((nu, m), t)\n vt = zeros((n, nvt), t)\n else:\n option = 'N'\n nu = 1\n nvt = 1\n u = empty((1,1),t) \n vt = empty((1,1),t) \n\n iwork = zeros((8*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesdd\n rwork = zeros((5*min(m,n)*min(m,n) + 5*min(m,n),), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, rwork, iwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, rwork, iwork, 0)\n else:\n lapack_routine = lapack_lite.dgesdd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, iwork, 0)\n lwork = int(work[0])\n if option == 'N' and lwork==1:\n # there seems to be a bug in dgesdd of lapack\n # (NNemec, 060310)\n # returning the wrong lwork size for option == 'N'\n results = lapack_routine('A', m, n, a, m, s, u, m, vt, n,\n work, -1, iwork, 0)\n lwork = int(work[0])\n assert lwork > 1\n\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, iwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge'\n if compute_uv:\n return wrap(transpose(u)), s, \\\n wrap(transpose(vt)) # why copy here?\n else:\n return s\n\n# Generalized inverse\n\ndef pinv(a, rcond = 1.e-10):\n a, wrap = _makearray(a)\n if a.dtype.char in typecodes['Complex']:\n a = conjugate(a)\n u, s, vt = svd(a, 0)\n m = u.shape[0]\n n = vt.shape[1]\n cutoff = rcond*maximum.reduce(s)\n for i in range(min(n,m)):\n if s[i] > cutoff:\n s[i] = 1./s[i]\n else:\n s[i] = 0.;\n return wrap(dot(transpose(vt),\n multiply(s[:, NewAxis],transpose(u))))\n\n# Determinant\n\ndef det(a):\n a = asarray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zgetrf\n else:\n lapack_routine = lapack_lite.dgetrf\n pivots = zeros((n,), 'i')\n results = lapack_routine(n, n, a, n, pivots, 0)\n sign = add.reduce(not_equal(pivots,\n arrayrange(1, n+1))) % 2\n return (1.-2.*sign)*multiply.reduce(diagonal(a),axis=-1)\n\n# Linear Least Squares\n\ndef lstsq(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n import math\n a = asarray(a)\n b, wrap = _makearray(b)\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n m = a.shape[0]\n n = a.shape[1]\n n_rhs = b.shape[1]\n ldb = max(n,m)\n if m != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n real_t = _array_type[0][_array_precision[t]]\n bstar = zeros((ldb,n_rhs),t)\n bstar[:b.shape[0],:n_rhs] = b.copy()\n a,bstar = _castCopyAndTranspose(t, a, bstar)\n s = zeros((min(m,n),),real_t)\n nlvl = max( 0, int( math.log( float(min( m,n ))/2. ) ) + 1 )\n iwork = zeros((3*min(m,n)*nlvl+11*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgelsd\n lwork = 1\n rwork = zeros((lwork,), real_t)\n work = zeros((lwork,),t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,rwork,iwork,0 )\n lwork = int(abs(work[0]))\n rwork = zeros((lwork,),real_t)\n a_real = zeros((m,n),real_t)\n bstar_real = zeros((ldb,n_rhs,),real_t)\n results = lapack_lite.dgelsd( m, n, n_rhs, a_real, m, bstar_real,ldb , s, rcond,\n 0,rwork,-1,iwork,0 )\n lrwork = int(rwork[0])\n work = zeros((lwork,), t)\n rwork = zeros((lrwork,), real_t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,rwork,iwork,0 )\n else:\n lapack_routine = lapack_lite.dgelsd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,iwork,0 )\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,iwork,0 )\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge in Linear Least Squares'\n resids = array([],t)\n if one_eq:\n x = ravel(bstar)[:n].copy()\n if (results['rank']==n) and (m>n):\n resids = array([sum((ravel(bstar)[n:])**2)])\n else:\n x = transpose(bstar)[:n,:].copy()\n if (results['rank']==n) and (m>n):\n resids = sum((transpose(bstar)[n:,:])**2).copy()\n return wrap(x),resids,results['rank'],s[:min(n,m)].copy()\n\ndef norm(x, ord=None):\n \"\"\" norm(x, ord=None) -> n\n\n Matrix or vector norm.\n\n Inputs:\n\n x -- a rank-1 (vector) or rank-2 (matrix) array\n ord -- the order of the norm.\n\n Comments:\n For arrays of any rank, if ord is None:\n calculate the square norm (Euclidean norm for vectors, Frobenius norm for matrices)\n\n For vectors ord can be any real number including Inf or -Inf.\n ord = Inf, computes the maximum of the magnitudes\n ord = -Inf, computes minimum of the magnitudes\n ord is finite, computes sum(abs(x)**ord)**(1.0/ord)\n\n For matrices ord can only be one of the following values:\n ord = 2 computes the largest singular value\n ord = -2 computes the smallest singular value\n ord = 1 computes the largest column sum of absolute values\n ord = -1 computes the smallest column sum of absolute values\n ord = Inf computes the largest row sum of absolute values\n ord = -Inf computes the smallest row sum of absolute values\n ord = 'fro' computes the frobenius norm sqrt(sum(diag(X.H * X)))\n\n For values ord < 0, the result is, strictly speaking, not a\n mathematical 'norm', but it may still be useful for numerical purposes.\n \"\"\"\n x = asarray(x)\n nd = len(x.shape) \n if ord is None: # check the default case first and handle it immediately\n return sqrt(add.reduce((x.conj() * x).ravel().real))\n\n if nd == 1:\n if ord == Inf:\n return abs(x).max()\n elif ord == -Inf:\n return abs(x).min()\n elif ord == 1:\n return abs(x).sum() # special case for speedup\n elif ord == 2:\n return sqrt(((x.conj()*x).real).sum()) # special case for speedup\n else:\n return ((abs(x)**ord).sum())**(1.0/ord)\n elif nd == 2:\n if ord == 2:\n return svd(x,compute_uv=0).max()\n elif ord == -2:\n return svd(x,compute_uv=0).min()\n elif ord == 1:\n return abs(x).sum(axis=0).max()\n elif ord == Inf:\n return abs(x).sum(axis=1).max()\n elif ord == -1:\n return abs(x).sum(axis=0).min()\n elif ord == -Inf:\n return abs(x).sum(axis=1).min()\n elif ord in ['fro','f']:\n return sqrt(add.reduce((x.conj() * x).real.ravel()))\n else:\n raise ValueError, \"Invalid norm order for matrices.\"\n else:\n raise ValueError, \"Improper number of dimensions to norm.\"\n\nif __name__ == '__main__':\n def test(a, b):\n\n print \"All numbers printed should be (almost) zero:\"\n\n x = solve(a, b)\n check = b - matrixmultiply(a, x)\n print check\n\n\n a_inv = inv(a)\n check = matrixmultiply(a, a_inv)-identity(a.shape[0])\n print check\n\n\n ev = eigvals(a)\n\n evalues, evectors = eig(a)\n check = ev-evalues\n print check\n\n evectors = transpose(evectors)\n check = matrixmultiply(a, evectors)-evectors*evalues\n print check\n\n\n u, s, vt = svd(a,0)\n check = a - matrixmultiply(u*s, vt)\n print check\n\n\n a_ginv = pinv(a)\n check = matrixmultiply(a, a_ginv)-identity(a.shape[0])\n print check\n\n\n det = det(a)\n check = det-multiply.reduce(evalues)\n print check\n\n x, residuals, rank, sv = lstsq(a, b)\n check = b - matrixmultiply(a, x)\n print check\n print rank-a.shape[0]\n print sv-s\n\n a = array([[1.,2.], [3.,4.]])\n b = array([2., 1.])\n test(a, b)\n\n a = a+0j\n b = b+0j\n test(a, b)\n", + "methods": [ + { + "name": "_makearray", + "long_name": "_makearray( a )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a" + ], + "start_line": 32, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_commonType", + "long_name": "_commonType( * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 2, + "token_count": 54, + "parameters": [ + "arrays" + ], + "start_line": 37, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_castCopyAndTranspose", + "long_name": "_castCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 5, + "complexity": 3, + "token_count": 47, + "parameters": [ + "type", + "arrays" + ], + "start_line": 48, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_fastCopyAndTranspose", + "long_name": "_fastCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 11, + "complexity": 4, + "token_count": 72, + "parameters": [ + "type", + "arrays" + ], + "start_line": 59, + "end_line": 69, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_assertRank2", + "long_name": "_assertRank2( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 25, + "parameters": [ + "arrays" + ], + "start_line": 71, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_assertSquareness", + "long_name": "_assertSquareness( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 30, + "parameters": [ + "arrays" + ], + "start_line": 76, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "solve", + "long_name": "solve( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 83, + "end_line": 107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "inv", + "long_name": "inv( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 112, + "end_line": 114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cholesky", + "long_name": "cholesky( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 3, + "token_count": 105, + "parameters": [ + "a" + ], + "start_line": 118, + "end_line": 132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "eigvals", + "long_name": "eigvals( a )", + "filename": "linalg.py", + "nloc": 39, + "complexity": 4, + "token_count": 363, + "parameters": [ + "a" + ], + "start_line": 136, + "end_line": 174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "eigvalsh", + "long_name": "eigvalsh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 34, + "complexity": 3, + "token_count": 345, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 177, + "end_line": 210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convertarray", + "long_name": "_convertarray( a )", + "filename": "linalg.py", + "nloc": 12, + "complexity": 4, + "token_count": 83, + "parameters": [ + "a" + ], + "start_line": 212, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "eig", + "long_name": "eig( a )", + "filename": "linalg.py", + "nloc": 51, + "complexity": 5, + "token_count": 499, + "parameters": [ + "a" + ], + "start_line": 227, + "end_line": 281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "eigh", + "long_name": "eigh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 3, + "token_count": 362, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 284, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "svd", + "long_name": "svd( a , full_matrices = 1 , compute_uv = 1 )", + "filename": "linalg.py", + "nloc": 59, + "complexity": 8, + "token_count": 539, + "parameters": [ + "a", + "full_matrices", + "compute_uv" + ], + "start_line": 323, + "end_line": 386, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "pinv", + "long_name": "pinv( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 390, + "end_line": 404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "det", + "long_name": "det( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 408, + "end_line": 422, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "lstsq", + "long_name": "lstsq( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 426, + "end_line": 499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "norm", + "long_name": "norm( x , ord = None )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 15, + "token_count": 325, + "parameters": [ + "x", + "ord" + ], + "start_line": 501, + "end_line": 566, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "test", + "long_name": "test( a , b )", + "filename": "linalg.py", + "nloc": 29, + "complexity": 1, + "token_count": 205, + "parameters": [ + "a", + "b" + ], + "start_line": 569, + "end_line": 612, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "_makearray", + "long_name": "_makearray( a )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a" + ], + "start_line": 29, + "end_line": 32, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_commonType", + "long_name": "_commonType( * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 2, + "token_count": 54, + "parameters": [ + "arrays" + ], + "start_line": 34, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_castCopyAndTranspose", + "long_name": "_castCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 5, + "complexity": 3, + "token_count": 47, + "parameters": [ + "type", + "arrays" + ], + "start_line": 45, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_fastCopyAndTranspose", + "long_name": "_fastCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 11, + "complexity": 4, + "token_count": 72, + "parameters": [ + "type", + "arrays" + ], + "start_line": 56, + "end_line": 66, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_assertRank2", + "long_name": "_assertRank2( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 25, + "parameters": [ + "arrays" + ], + "start_line": 68, + "end_line": 71, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_assertSquareness", + "long_name": "_assertSquareness( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 30, + "parameters": [ + "arrays" + ], + "start_line": 73, + "end_line": 76, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "solve", + "long_name": "solve( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 80, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "inv", + "long_name": "inv( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 109, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cholesky", + "long_name": "cholesky( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 3, + "token_count": 105, + "parameters": [ + "a" + ], + "start_line": 115, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "eigvals", + "long_name": "eigvals( a )", + "filename": "linalg.py", + "nloc": 39, + "complexity": 4, + "token_count": 363, + "parameters": [ + "a" + ], + "start_line": 133, + "end_line": 171, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "eigvalsh", + "long_name": "eigvalsh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 34, + "complexity": 3, + "token_count": 345, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 174, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convertarray", + "long_name": "_convertarray( a )", + "filename": "linalg.py", + "nloc": 12, + "complexity": 4, + "token_count": 83, + "parameters": [ + "a" + ], + "start_line": 209, + "end_line": 220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "eig", + "long_name": "eig( a )", + "filename": "linalg.py", + "nloc": 51, + "complexity": 5, + "token_count": 499, + "parameters": [ + "a" + ], + "start_line": 224, + "end_line": 278, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "eigh", + "long_name": "eigh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 3, + "token_count": 362, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 281, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "svd", + "long_name": "svd( a , full_matrices = 1 , compute_uv = 1 )", + "filename": "linalg.py", + "nloc": 59, + "complexity": 8, + "token_count": 539, + "parameters": [ + "a", + "full_matrices", + "compute_uv" + ], + "start_line": 320, + "end_line": 383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "pinv", + "long_name": "pinv( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 387, + "end_line": 401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "det", + "long_name": "det( a )", + "filename": "linalg.py", + "nloc": 16, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 405, + "end_line": 420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "lstsq", + "long_name": "lstsq( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 424, + "end_line": 497, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "norm", + "long_name": "norm( x , ord = None )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 15, + "token_count": 325, + "parameters": [ + "x", + "ord" + ], + "start_line": 499, + "end_line": 564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "test", + "long_name": "test( a , b )", + "filename": "linalg.py", + "nloc": 29, + "complexity": 1, + "token_count": 205, + "parameters": [ + "a", + "b" + ], + "start_line": 567, + "end_line": 610, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "inv", + "long_name": "inv( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 112, + "end_line": 114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "det", + "long_name": "det( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 408, + "end_line": 422, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + } + ], + "nloc": 491, + "complexity": 85, + "token_count": 4493, + "diff_parsed": { + "added": [ + " 'LinAlgError'", + "# Error object", + "class LinAlgError(Exception):", + " pass", + "", + " return wrap(solve(a, identity(a.shape[0])))", + " sign = add.reduce(not_equal(pivots, arrayrange(1, n+1))) % 2" + ], + "deleted": [ + "_lapack_type = {'f': 0, 'd': 1, 'F': 2, 'D': 3}", + "_lapack_letter = ['s', 'd', 'c', 'z']", + " return wrap(solve_linear_equations(a, identity(a.shape[0])))", + " sign = add.reduce(not_equal(pivots,", + " arrayrange(1, n+1))) % 2" + ] + } + }, + { + "old_path": "numpy/linalg/old.py", + "new_path": "numpy/linalg/old.py", + "filename": "old.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -18,12 +18,10 @@\n from numpy.core import transpose\n import linalg\n \n-# Error object\n-class LinAlgError(Exception):\n- pass\n-\n # Linear equations\n \n+LinAlgError = linalg.LinAlgError\n+\n def solve_linear_equations(a, b):\n return linalg.solve(a,b)\n \n", + "added_lines": 2, + "deleted_lines": 4, + "source_code": "\n\"\"\"Backward compatible with LinearAlgebra from Numeric\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n\n__all__ = ['LinAlgError', 'solve_linear_equations', \n 'inverse', 'cholesky_decomposition', 'eigenvalues',\n 'Heigenvalues', 'generalized_inverse', \n 'determinant', 'singular_value_decomposition', \n 'eigenvectors', 'Heigenvectors',\n 'linear_least_squares'\n ]\n\nfrom numpy.core import transpose\nimport linalg\n\n# Linear equations\n\nLinAlgError = linalg.LinAlgError\n\ndef solve_linear_equations(a, b):\n return linalg.solve(a,b)\n\n# Matrix inversion\n\ndef inverse(a):\n return linalg.inv(a)\n\n# Cholesky decomposition\n\ndef cholesky_decomposition(a):\n return linalg.cholesky(a)\n\n# Eigenvalues\n\ndef eigenvalues(a):\n return linalg.eigvals(a)\n\ndef Heigenvalues(a, UPLO='L'):\n return linalg.eigvalsh(a,UPLO)\n\n# Eigenvectors\n\ndef eigenvectors(A):\n w, v = linalg.eig(A)\n return w, transpose(v)\n\ndef Heigenvectors(A):\n w, v = linalg.eigh(A)\n return w, transpose(v)\n \n# Generalized inverse\n\ndef generalized_inverse(a, rcond = 1.e-10):\n return linalg.pinv(a, rcond)\n\n# Determinant\n\ndef determinant(a):\n return linalg.det(a)\n\n# Linear Least Squares\n\ndef linear_least_squares(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n return linalg.lstsq(a,b,rcond)\n\ndef singular_value_decomposition(A, full_matrices=0):\n return linalg.svd(A, full_matrices)\n", + "source_code_before": "\n\"\"\"Backward compatible with LinearAlgebra from Numeric\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n\n__all__ = ['LinAlgError', 'solve_linear_equations', \n 'inverse', 'cholesky_decomposition', 'eigenvalues',\n 'Heigenvalues', 'generalized_inverse', \n 'determinant', 'singular_value_decomposition', \n 'eigenvectors', 'Heigenvectors',\n 'linear_least_squares'\n ]\n\nfrom numpy.core import transpose\nimport linalg\n\n# Error object\nclass LinAlgError(Exception):\n pass\n\n# Linear equations\n\ndef solve_linear_equations(a, b):\n return linalg.solve(a,b)\n\n# Matrix inversion\n\ndef inverse(a):\n return linalg.inv(a)\n\n# Cholesky decomposition\n\ndef cholesky_decomposition(a):\n return linalg.cholesky(a)\n\n# Eigenvalues\n\ndef eigenvalues(a):\n return linalg.eigvals(a)\n\ndef Heigenvalues(a, UPLO='L'):\n return linalg.eigvalsh(a,UPLO)\n\n# Eigenvectors\n\ndef eigenvectors(A):\n w, v = linalg.eig(A)\n return w, transpose(v)\n\ndef Heigenvectors(A):\n w, v = linalg.eigh(A)\n return w, transpose(v)\n \n# Generalized inverse\n\ndef generalized_inverse(a, rcond = 1.e-10):\n return linalg.pinv(a, rcond)\n\n# Determinant\n\ndef determinant(a):\n return linalg.det(a)\n\n# Linear Least Squares\n\ndef linear_least_squares(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n return linalg.lstsq(a,b,rcond)\n\ndef singular_value_decomposition(A, full_matrices=0):\n return linalg.svd(A, full_matrices)\n", + "methods": [ + { + "name": "solve_linear_equations", + "long_name": "solve_linear_equations( a , b )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "a", + "b" + ], + "start_line": 25, + "end_line": 26, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "inverse", + "long_name": "inverse( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 30, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "cholesky_decomposition", + "long_name": "cholesky_decomposition( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 35, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvalues", + "long_name": "eigenvalues( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 40, + "end_line": 41, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "Heigenvalues", + "long_name": "Heigenvalues( a , UPLO = 'L' )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 43, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvectors", + "long_name": "eigenvectors( A )", + "filename": "old.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "A" + ], + "start_line": 48, + "end_line": 50, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "Heigenvectors", + "long_name": "Heigenvectors( A )", + "filename": "old.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "A" + ], + "start_line": 52, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "generalized_inverse", + "long_name": "generalized_inverse( a , rcond = 1 . e - 10 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "rcond" + ], + "start_line": 58, + "end_line": 59, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "determinant", + "long_name": "determinant( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 63, + "end_line": 64, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "linear_least_squares", + "long_name": "linear_least_squares( a , b , rcond = 1 . e - 10 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 68, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "singular_value_decomposition", + "long_name": "singular_value_decomposition( A , full_matrices = 0 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "A", + "full_matrices" + ], + "start_line": 83, + "end_line": 84, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "solve_linear_equations", + "long_name": "solve_linear_equations( a , b )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "a", + "b" + ], + "start_line": 27, + "end_line": 28, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "inverse", + "long_name": "inverse( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 32, + "end_line": 33, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "cholesky_decomposition", + "long_name": "cholesky_decomposition( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 37, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvalues", + "long_name": "eigenvalues( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 42, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "Heigenvalues", + "long_name": "Heigenvalues( a , UPLO = 'L' )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 45, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "eigenvectors", + "long_name": "eigenvectors( A )", + "filename": "old.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "A" + ], + "start_line": 50, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "Heigenvectors", + "long_name": "Heigenvectors( A )", + "filename": "old.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "A" + ], + "start_line": 54, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "generalized_inverse", + "long_name": "generalized_inverse( a , rcond = 1 . e - 10 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "rcond" + ], + "start_line": 60, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "determinant", + "long_name": "determinant( a )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "a" + ], + "start_line": 65, + "end_line": 66, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "linear_least_squares", + "long_name": "linear_least_squares( a , b , rcond = 1 . e - 10 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 70, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "singular_value_decomposition", + "long_name": "singular_value_decomposition( A , full_matrices = 0 )", + "filename": "old.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "A", + "full_matrices" + ], + "start_line": 85, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 36, + "complexity": 11, + "token_count": 245, + "diff_parsed": { + "added": [ + "LinAlgError = linalg.LinAlgError", + "" + ], + "deleted": [ + "# Error object", + "class LinAlgError(Exception):", + " pass", + "" + ] + } + } + ] + }, + { + "hash": "967e9fd69a2113f124591e144b8ede722faa887e", + "msg": "Fix-up name-spaces.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-15T09:30:20+00:00", + "author_timezone": 0, + "committer_date": "2006-03-15T09:30:20+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "abe1567d970117ed9a3634c10c843da2e3399f60" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 1, + "insertions": 0, + "lines": 1, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/linalg/linalg.py", + "new_path": "numpy/linalg/linalg.py", + "filename": "linalg.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -17,7 +17,6 @@\n \n from numpy.core import *\n from numpy.lib import *\n-from old import solve_linear_equations\n import lapack_lite\n \n # Error object\n", + "added_lines": 0, + "deleted_lines": 1, + "source_code": "\n\"\"\"Lite version of scipy.linalg.\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n__all__ = ['solve',\n 'inv', 'cholesky',\n 'eigvals',\n 'eigvalsh', 'pinv',\n 'det', 'svd',\n 'eig', 'eigh','lstsq', 'norm',\n 'LinAlgError'\n ]\n\nfrom numpy.core import *\nfrom numpy.lib import *\nimport lapack_lite\n\n# Error object\nclass LinAlgError(Exception):\n pass\n\n# Helper routines\n_array_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\n_array_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\n_array_type = [['f', 'd'], ['F', 'D']]\n\ndef _makearray(a):\n new = asarray(a)\n wrap = getattr(a, \"__array_wrap__\", new.__array_wrap__)\n return new, wrap\n\ndef _commonType(*arrays):\n kind = 0\n# precision = 0\n# force higher precision in lite version\n precision = 1\n for a in arrays:\n t = a.dtype.char\n kind = max(kind, _array_kind[t])\n precision = max(precision, _array_precision[t])\n return _array_type[kind][precision]\n\ndef _castCopyAndTranspose(type, *arrays):\n if len(arrays) == 1:\n return transpose(arrays[0]).astype(type)\n else:\n return [transpose(a).astype(type) for a in arrays]\n\n# _fastCopyAndTranpose is an optimized version of _castCopyAndTranspose.\n# It assumes the input is 2D (as all the calls in here are).\n\n_fastCT = fastCopyAndTranspose\n\ndef _fastCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.dtype.char == type:\n cast_arrays = cast_arrays + (_fastCT(a),)\n else:\n cast_arrays = cast_arrays + (_fastCT(a.astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\ndef _assertRank2(*arrays):\n for a in arrays:\n if len(a.shape) != 2:\n raise LinAlgError, 'Array must be two-dimensional'\n\ndef _assertSquareness(*arrays):\n for a in arrays:\n if max(a.shape) != min(a.shape):\n raise LinAlgError, 'Array must be square'\n\n# Linear equations\n\ndef solve(a, b):\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n _assertSquareness(a)\n n_eq = a.shape[0]\n n_rhs = b.shape[1]\n if n_eq != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n# lapack_routine = _findLapackRoutine('gesv', t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesv\n else:\n lapack_routine = lapack_lite.dgesv\n a, b = _fastCopyAndTranspose(t, a, b)\n pivots = zeros(n_eq, 'i')\n results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Singular matrix'\n if one_eq:\n return ravel(b) # I see no need to copy here\n else:\n return transpose(b) # no need to copy\n\n\n# Matrix inversion\n\ndef inv(a):\n a, wrap = _makearray(a)\n return wrap(solve(a, identity(a.shape[0])))\n\n# Cholesky decomposition\n\ndef cholesky(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _castCopyAndTranspose(t, a)\n m = a.shape[0]\n n = a.shape[1]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zpotrf\n else:\n lapack_routine = lapack_lite.dpotrf\n results = lapack_routine('L', n, a, m, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Matrix is not positive definite - Cholesky decomposition cannot be computed'\n return transpose(triu(a,k=0)).copy()\n\n\n# Eigenvalues\ndef eigvals(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n dummy = zeros((1,), t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n rwork = zeros((n,),real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n else:\n w = wr+1j*wi\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\n\ndef eigvalsh(a, UPLO='L'):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\ndef _convertarray(a):\n if issubclass(a.dtype.type, complexfloating):\n if a.dtype.char == 'D':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('D'))\n else:\n if a.dtype.char == 'd':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('d'))\n return a, a.dtype.char\n\n# Eigenvectors\n\ndef eig(a):\n \"\"\"eig(a) returns u,v where u is the eigenvalues and\nv is a matrix of eigenvectors with vector v[:,i] corresponds to\neigenvalue u[i]. Satisfies the equation dot(a, v[:,i]) = u[i]*v[:,i]\n\"\"\"\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n a,t = _convertarray(a) # convert to float_ or complex_ type\n real_t = 'd'\n n = a.shape[0]\n dummy = zeros((1,), t)\n if t == 'D': # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n v = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n rwork = zeros((2*n,),real_t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n vr = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n v = vr\n else:\n w = wr+1j*wi\n v = array(vr,Complex)\n ind = nonzero(\n equal(\n equal(wi,0.0) # true for real e-vals\n ,0) # true for complex e-vals\n ) # indices of complex e-vals\n for i in range(len(ind)/2):\n v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]]\n v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]]\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(v.transpose())\n\n\ndef eigh(a, UPLO='L'):\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(a.transpose())\n\n\n# Singular value decomposition\n\ndef svd(a, full_matrices=1, compute_uv=1):\n a, wrap = _makearray(a)\n _assertRank2(a)\n m, n = a.shape\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n s = zeros((min(n,m),), real_t)\n if compute_uv:\n if full_matrices:\n nu = m\n nvt = n\n option = 'A'\n else:\n nu = min(n,m)\n nvt = min(n,m)\n option = 'S'\n u = zeros((nu, m), t)\n vt = zeros((n, nvt), t)\n else:\n option = 'N'\n nu = 1\n nvt = 1\n u = empty((1,1),t) \n vt = empty((1,1),t) \n\n iwork = zeros((8*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesdd\n rwork = zeros((5*min(m,n)*min(m,n) + 5*min(m,n),), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, rwork, iwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, rwork, iwork, 0)\n else:\n lapack_routine = lapack_lite.dgesdd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, iwork, 0)\n lwork = int(work[0])\n if option == 'N' and lwork==1:\n # there seems to be a bug in dgesdd of lapack\n # (NNemec, 060310)\n # returning the wrong lwork size for option == 'N'\n results = lapack_routine('A', m, n, a, m, s, u, m, vt, n,\n work, -1, iwork, 0)\n lwork = int(work[0])\n assert lwork > 1\n\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, iwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge'\n if compute_uv:\n return wrap(transpose(u)), s, \\\n wrap(transpose(vt)) # why copy here?\n else:\n return s\n\n# Generalized inverse\n\ndef pinv(a, rcond = 1.e-10):\n a, wrap = _makearray(a)\n if a.dtype.char in typecodes['Complex']:\n a = conjugate(a)\n u, s, vt = svd(a, 0)\n m = u.shape[0]\n n = vt.shape[1]\n cutoff = rcond*maximum.reduce(s)\n for i in range(min(n,m)):\n if s[i] > cutoff:\n s[i] = 1./s[i]\n else:\n s[i] = 0.;\n return wrap(dot(transpose(vt),\n multiply(s[:, NewAxis],transpose(u))))\n\n# Determinant\n\ndef det(a):\n a = asarray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zgetrf\n else:\n lapack_routine = lapack_lite.dgetrf\n pivots = zeros((n,), 'i')\n results = lapack_routine(n, n, a, n, pivots, 0)\n sign = add.reduce(not_equal(pivots, arrayrange(1, n+1))) % 2\n return (1.-2.*sign)*multiply.reduce(diagonal(a),axis=-1)\n\n# Linear Least Squares\n\ndef lstsq(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n import math\n a = asarray(a)\n b, wrap = _makearray(b)\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n m = a.shape[0]\n n = a.shape[1]\n n_rhs = b.shape[1]\n ldb = max(n,m)\n if m != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n real_t = _array_type[0][_array_precision[t]]\n bstar = zeros((ldb,n_rhs),t)\n bstar[:b.shape[0],:n_rhs] = b.copy()\n a,bstar = _castCopyAndTranspose(t, a, bstar)\n s = zeros((min(m,n),),real_t)\n nlvl = max( 0, int( math.log( float(min( m,n ))/2. ) ) + 1 )\n iwork = zeros((3*min(m,n)*nlvl+11*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgelsd\n lwork = 1\n rwork = zeros((lwork,), real_t)\n work = zeros((lwork,),t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,rwork,iwork,0 )\n lwork = int(abs(work[0]))\n rwork = zeros((lwork,),real_t)\n a_real = zeros((m,n),real_t)\n bstar_real = zeros((ldb,n_rhs,),real_t)\n results = lapack_lite.dgelsd( m, n, n_rhs, a_real, m, bstar_real,ldb , s, rcond,\n 0,rwork,-1,iwork,0 )\n lrwork = int(rwork[0])\n work = zeros((lwork,), t)\n rwork = zeros((lrwork,), real_t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,rwork,iwork,0 )\n else:\n lapack_routine = lapack_lite.dgelsd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,iwork,0 )\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,iwork,0 )\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge in Linear Least Squares'\n resids = array([],t)\n if one_eq:\n x = ravel(bstar)[:n].copy()\n if (results['rank']==n) and (m>n):\n resids = array([sum((ravel(bstar)[n:])**2)])\n else:\n x = transpose(bstar)[:n,:].copy()\n if (results['rank']==n) and (m>n):\n resids = sum((transpose(bstar)[n:,:])**2).copy()\n return wrap(x),resids,results['rank'],s[:min(n,m)].copy()\n\ndef norm(x, ord=None):\n \"\"\" norm(x, ord=None) -> n\n\n Matrix or vector norm.\n\n Inputs:\n\n x -- a rank-1 (vector) or rank-2 (matrix) array\n ord -- the order of the norm.\n\n Comments:\n For arrays of any rank, if ord is None:\n calculate the square norm (Euclidean norm for vectors, Frobenius norm for matrices)\n\n For vectors ord can be any real number including Inf or -Inf.\n ord = Inf, computes the maximum of the magnitudes\n ord = -Inf, computes minimum of the magnitudes\n ord is finite, computes sum(abs(x)**ord)**(1.0/ord)\n\n For matrices ord can only be one of the following values:\n ord = 2 computes the largest singular value\n ord = -2 computes the smallest singular value\n ord = 1 computes the largest column sum of absolute values\n ord = -1 computes the smallest column sum of absolute values\n ord = Inf computes the largest row sum of absolute values\n ord = -Inf computes the smallest row sum of absolute values\n ord = 'fro' computes the frobenius norm sqrt(sum(diag(X.H * X)))\n\n For values ord < 0, the result is, strictly speaking, not a\n mathematical 'norm', but it may still be useful for numerical purposes.\n \"\"\"\n x = asarray(x)\n nd = len(x.shape) \n if ord is None: # check the default case first and handle it immediately\n return sqrt(add.reduce((x.conj() * x).ravel().real))\n\n if nd == 1:\n if ord == Inf:\n return abs(x).max()\n elif ord == -Inf:\n return abs(x).min()\n elif ord == 1:\n return abs(x).sum() # special case for speedup\n elif ord == 2:\n return sqrt(((x.conj()*x).real).sum()) # special case for speedup\n else:\n return ((abs(x)**ord).sum())**(1.0/ord)\n elif nd == 2:\n if ord == 2:\n return svd(x,compute_uv=0).max()\n elif ord == -2:\n return svd(x,compute_uv=0).min()\n elif ord == 1:\n return abs(x).sum(axis=0).max()\n elif ord == Inf:\n return abs(x).sum(axis=1).max()\n elif ord == -1:\n return abs(x).sum(axis=0).min()\n elif ord == -Inf:\n return abs(x).sum(axis=1).min()\n elif ord in ['fro','f']:\n return sqrt(add.reduce((x.conj() * x).real.ravel()))\n else:\n raise ValueError, \"Invalid norm order for matrices.\"\n else:\n raise ValueError, \"Improper number of dimensions to norm.\"\n\nif __name__ == '__main__':\n def test(a, b):\n\n print \"All numbers printed should be (almost) zero:\"\n\n x = solve(a, b)\n check = b - matrixmultiply(a, x)\n print check\n\n\n a_inv = inv(a)\n check = matrixmultiply(a, a_inv)-identity(a.shape[0])\n print check\n\n\n ev = eigvals(a)\n\n evalues, evectors = eig(a)\n check = ev-evalues\n print check\n\n evectors = transpose(evectors)\n check = matrixmultiply(a, evectors)-evectors*evalues\n print check\n\n\n u, s, vt = svd(a,0)\n check = a - matrixmultiply(u*s, vt)\n print check\n\n\n a_ginv = pinv(a)\n check = matrixmultiply(a, a_ginv)-identity(a.shape[0])\n print check\n\n\n det = det(a)\n check = det-multiply.reduce(evalues)\n print check\n\n x, residuals, rank, sv = lstsq(a, b)\n check = b - matrixmultiply(a, x)\n print check\n print rank-a.shape[0]\n print sv-s\n\n a = array([[1.,2.], [3.,4.]])\n b = array([2., 1.])\n test(a, b)\n\n a = a+0j\n b = b+0j\n test(a, b)\n", + "source_code_before": "\n\"\"\"Lite version of scipy.linalg.\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n__all__ = ['solve',\n 'inv', 'cholesky',\n 'eigvals',\n 'eigvalsh', 'pinv',\n 'det', 'svd',\n 'eig', 'eigh','lstsq', 'norm',\n 'LinAlgError'\n ]\n\nfrom numpy.core import *\nfrom numpy.lib import *\nfrom old import solve_linear_equations\nimport lapack_lite\n\n# Error object\nclass LinAlgError(Exception):\n pass\n\n# Helper routines\n_array_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\n_array_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\n_array_type = [['f', 'd'], ['F', 'D']]\n\ndef _makearray(a):\n new = asarray(a)\n wrap = getattr(a, \"__array_wrap__\", new.__array_wrap__)\n return new, wrap\n\ndef _commonType(*arrays):\n kind = 0\n# precision = 0\n# force higher precision in lite version\n precision = 1\n for a in arrays:\n t = a.dtype.char\n kind = max(kind, _array_kind[t])\n precision = max(precision, _array_precision[t])\n return _array_type[kind][precision]\n\ndef _castCopyAndTranspose(type, *arrays):\n if len(arrays) == 1:\n return transpose(arrays[0]).astype(type)\n else:\n return [transpose(a).astype(type) for a in arrays]\n\n# _fastCopyAndTranpose is an optimized version of _castCopyAndTranspose.\n# It assumes the input is 2D (as all the calls in here are).\n\n_fastCT = fastCopyAndTranspose\n\ndef _fastCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.dtype.char == type:\n cast_arrays = cast_arrays + (_fastCT(a),)\n else:\n cast_arrays = cast_arrays + (_fastCT(a.astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\ndef _assertRank2(*arrays):\n for a in arrays:\n if len(a.shape) != 2:\n raise LinAlgError, 'Array must be two-dimensional'\n\ndef _assertSquareness(*arrays):\n for a in arrays:\n if max(a.shape) != min(a.shape):\n raise LinAlgError, 'Array must be square'\n\n# Linear equations\n\ndef solve(a, b):\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n _assertSquareness(a)\n n_eq = a.shape[0]\n n_rhs = b.shape[1]\n if n_eq != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n# lapack_routine = _findLapackRoutine('gesv', t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesv\n else:\n lapack_routine = lapack_lite.dgesv\n a, b = _fastCopyAndTranspose(t, a, b)\n pivots = zeros(n_eq, 'i')\n results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Singular matrix'\n if one_eq:\n return ravel(b) # I see no need to copy here\n else:\n return transpose(b) # no need to copy\n\n\n# Matrix inversion\n\ndef inv(a):\n a, wrap = _makearray(a)\n return wrap(solve(a, identity(a.shape[0])))\n\n# Cholesky decomposition\n\ndef cholesky(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _castCopyAndTranspose(t, a)\n m = a.shape[0]\n n = a.shape[1]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zpotrf\n else:\n lapack_routine = lapack_lite.dpotrf\n results = lapack_routine('L', n, a, m, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Matrix is not positive definite - Cholesky decomposition cannot be computed'\n return transpose(triu(a,k=0)).copy()\n\n\n# Eigenvalues\ndef eigvals(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n dummy = zeros((1,), t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n rwork = zeros((n,),real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n else:\n w = wr+1j*wi\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\n\ndef eigvalsh(a, UPLO='L'):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\ndef _convertarray(a):\n if issubclass(a.dtype.type, complexfloating):\n if a.dtype.char == 'D':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('D'))\n else:\n if a.dtype.char == 'd':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('d'))\n return a, a.dtype.char\n\n# Eigenvectors\n\ndef eig(a):\n \"\"\"eig(a) returns u,v where u is the eigenvalues and\nv is a matrix of eigenvectors with vector v[:,i] corresponds to\neigenvalue u[i]. Satisfies the equation dot(a, v[:,i]) = u[i]*v[:,i]\n\"\"\"\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n a,t = _convertarray(a) # convert to float_ or complex_ type\n real_t = 'd'\n n = a.shape[0]\n dummy = zeros((1,), t)\n if t == 'D': # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n v = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n rwork = zeros((2*n,),real_t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n vr = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n v = vr\n else:\n w = wr+1j*wi\n v = array(vr,Complex)\n ind = nonzero(\n equal(\n equal(wi,0.0) # true for real e-vals\n ,0) # true for complex e-vals\n ) # indices of complex e-vals\n for i in range(len(ind)/2):\n v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]]\n v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]]\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(v.transpose())\n\n\ndef eigh(a, UPLO='L'):\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(a.transpose())\n\n\n# Singular value decomposition\n\ndef svd(a, full_matrices=1, compute_uv=1):\n a, wrap = _makearray(a)\n _assertRank2(a)\n m, n = a.shape\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n s = zeros((min(n,m),), real_t)\n if compute_uv:\n if full_matrices:\n nu = m\n nvt = n\n option = 'A'\n else:\n nu = min(n,m)\n nvt = min(n,m)\n option = 'S'\n u = zeros((nu, m), t)\n vt = zeros((n, nvt), t)\n else:\n option = 'N'\n nu = 1\n nvt = 1\n u = empty((1,1),t) \n vt = empty((1,1),t) \n\n iwork = zeros((8*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesdd\n rwork = zeros((5*min(m,n)*min(m,n) + 5*min(m,n),), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, rwork, iwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, rwork, iwork, 0)\n else:\n lapack_routine = lapack_lite.dgesdd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, iwork, 0)\n lwork = int(work[0])\n if option == 'N' and lwork==1:\n # there seems to be a bug in dgesdd of lapack\n # (NNemec, 060310)\n # returning the wrong lwork size for option == 'N'\n results = lapack_routine('A', m, n, a, m, s, u, m, vt, n,\n work, -1, iwork, 0)\n lwork = int(work[0])\n assert lwork > 1\n\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, iwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge'\n if compute_uv:\n return wrap(transpose(u)), s, \\\n wrap(transpose(vt)) # why copy here?\n else:\n return s\n\n# Generalized inverse\n\ndef pinv(a, rcond = 1.e-10):\n a, wrap = _makearray(a)\n if a.dtype.char in typecodes['Complex']:\n a = conjugate(a)\n u, s, vt = svd(a, 0)\n m = u.shape[0]\n n = vt.shape[1]\n cutoff = rcond*maximum.reduce(s)\n for i in range(min(n,m)):\n if s[i] > cutoff:\n s[i] = 1./s[i]\n else:\n s[i] = 0.;\n return wrap(dot(transpose(vt),\n multiply(s[:, NewAxis],transpose(u))))\n\n# Determinant\n\ndef det(a):\n a = asarray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zgetrf\n else:\n lapack_routine = lapack_lite.dgetrf\n pivots = zeros((n,), 'i')\n results = lapack_routine(n, n, a, n, pivots, 0)\n sign = add.reduce(not_equal(pivots, arrayrange(1, n+1))) % 2\n return (1.-2.*sign)*multiply.reduce(diagonal(a),axis=-1)\n\n# Linear Least Squares\n\ndef lstsq(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n import math\n a = asarray(a)\n b, wrap = _makearray(b)\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n m = a.shape[0]\n n = a.shape[1]\n n_rhs = b.shape[1]\n ldb = max(n,m)\n if m != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n real_t = _array_type[0][_array_precision[t]]\n bstar = zeros((ldb,n_rhs),t)\n bstar[:b.shape[0],:n_rhs] = b.copy()\n a,bstar = _castCopyAndTranspose(t, a, bstar)\n s = zeros((min(m,n),),real_t)\n nlvl = max( 0, int( math.log( float(min( m,n ))/2. ) ) + 1 )\n iwork = zeros((3*min(m,n)*nlvl+11*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgelsd\n lwork = 1\n rwork = zeros((lwork,), real_t)\n work = zeros((lwork,),t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,rwork,iwork,0 )\n lwork = int(abs(work[0]))\n rwork = zeros((lwork,),real_t)\n a_real = zeros((m,n),real_t)\n bstar_real = zeros((ldb,n_rhs,),real_t)\n results = lapack_lite.dgelsd( m, n, n_rhs, a_real, m, bstar_real,ldb , s, rcond,\n 0,rwork,-1,iwork,0 )\n lrwork = int(rwork[0])\n work = zeros((lwork,), t)\n rwork = zeros((lrwork,), real_t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,rwork,iwork,0 )\n else:\n lapack_routine = lapack_lite.dgelsd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,iwork,0 )\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,iwork,0 )\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge in Linear Least Squares'\n resids = array([],t)\n if one_eq:\n x = ravel(bstar)[:n].copy()\n if (results['rank']==n) and (m>n):\n resids = array([sum((ravel(bstar)[n:])**2)])\n else:\n x = transpose(bstar)[:n,:].copy()\n if (results['rank']==n) and (m>n):\n resids = sum((transpose(bstar)[n:,:])**2).copy()\n return wrap(x),resids,results['rank'],s[:min(n,m)].copy()\n\ndef norm(x, ord=None):\n \"\"\" norm(x, ord=None) -> n\n\n Matrix or vector norm.\n\n Inputs:\n\n x -- a rank-1 (vector) or rank-2 (matrix) array\n ord -- the order of the norm.\n\n Comments:\n For arrays of any rank, if ord is None:\n calculate the square norm (Euclidean norm for vectors, Frobenius norm for matrices)\n\n For vectors ord can be any real number including Inf or -Inf.\n ord = Inf, computes the maximum of the magnitudes\n ord = -Inf, computes minimum of the magnitudes\n ord is finite, computes sum(abs(x)**ord)**(1.0/ord)\n\n For matrices ord can only be one of the following values:\n ord = 2 computes the largest singular value\n ord = -2 computes the smallest singular value\n ord = 1 computes the largest column sum of absolute values\n ord = -1 computes the smallest column sum of absolute values\n ord = Inf computes the largest row sum of absolute values\n ord = -Inf computes the smallest row sum of absolute values\n ord = 'fro' computes the frobenius norm sqrt(sum(diag(X.H * X)))\n\n For values ord < 0, the result is, strictly speaking, not a\n mathematical 'norm', but it may still be useful for numerical purposes.\n \"\"\"\n x = asarray(x)\n nd = len(x.shape) \n if ord is None: # check the default case first and handle it immediately\n return sqrt(add.reduce((x.conj() * x).ravel().real))\n\n if nd == 1:\n if ord == Inf:\n return abs(x).max()\n elif ord == -Inf:\n return abs(x).min()\n elif ord == 1:\n return abs(x).sum() # special case for speedup\n elif ord == 2:\n return sqrt(((x.conj()*x).real).sum()) # special case for speedup\n else:\n return ((abs(x)**ord).sum())**(1.0/ord)\n elif nd == 2:\n if ord == 2:\n return svd(x,compute_uv=0).max()\n elif ord == -2:\n return svd(x,compute_uv=0).min()\n elif ord == 1:\n return abs(x).sum(axis=0).max()\n elif ord == Inf:\n return abs(x).sum(axis=1).max()\n elif ord == -1:\n return abs(x).sum(axis=0).min()\n elif ord == -Inf:\n return abs(x).sum(axis=1).min()\n elif ord in ['fro','f']:\n return sqrt(add.reduce((x.conj() * x).real.ravel()))\n else:\n raise ValueError, \"Invalid norm order for matrices.\"\n else:\n raise ValueError, \"Improper number of dimensions to norm.\"\n\nif __name__ == '__main__':\n def test(a, b):\n\n print \"All numbers printed should be (almost) zero:\"\n\n x = solve(a, b)\n check = b - matrixmultiply(a, x)\n print check\n\n\n a_inv = inv(a)\n check = matrixmultiply(a, a_inv)-identity(a.shape[0])\n print check\n\n\n ev = eigvals(a)\n\n evalues, evectors = eig(a)\n check = ev-evalues\n print check\n\n evectors = transpose(evectors)\n check = matrixmultiply(a, evectors)-evectors*evalues\n print check\n\n\n u, s, vt = svd(a,0)\n check = a - matrixmultiply(u*s, vt)\n print check\n\n\n a_ginv = pinv(a)\n check = matrixmultiply(a, a_ginv)-identity(a.shape[0])\n print check\n\n\n det = det(a)\n check = det-multiply.reduce(evalues)\n print check\n\n x, residuals, rank, sv = lstsq(a, b)\n check = b - matrixmultiply(a, x)\n print check\n print rank-a.shape[0]\n print sv-s\n\n a = array([[1.,2.], [3.,4.]])\n b = array([2., 1.])\n test(a, b)\n\n a = a+0j\n b = b+0j\n test(a, b)\n", + "methods": [ + { + "name": "_makearray", + "long_name": "_makearray( a )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a" + ], + "start_line": 31, + "end_line": 34, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_commonType", + "long_name": "_commonType( * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 2, + "token_count": 54, + "parameters": [ + "arrays" + ], + "start_line": 36, + "end_line": 45, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_castCopyAndTranspose", + "long_name": "_castCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 5, + "complexity": 3, + "token_count": 47, + "parameters": [ + "type", + "arrays" + ], + "start_line": 47, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_fastCopyAndTranspose", + "long_name": "_fastCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 11, + "complexity": 4, + "token_count": 72, + "parameters": [ + "type", + "arrays" + ], + "start_line": 58, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_assertRank2", + "long_name": "_assertRank2( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 25, + "parameters": [ + "arrays" + ], + "start_line": 70, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_assertSquareness", + "long_name": "_assertSquareness( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 30, + "parameters": [ + "arrays" + ], + "start_line": 75, + "end_line": 78, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "solve", + "long_name": "solve( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 82, + "end_line": 106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "inv", + "long_name": "inv( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 111, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cholesky", + "long_name": "cholesky( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 3, + "token_count": 105, + "parameters": [ + "a" + ], + "start_line": 117, + "end_line": 131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "eigvals", + "long_name": "eigvals( a )", + "filename": "linalg.py", + "nloc": 39, + "complexity": 4, + "token_count": 363, + "parameters": [ + "a" + ], + "start_line": 135, + "end_line": 173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "eigvalsh", + "long_name": "eigvalsh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 34, + "complexity": 3, + "token_count": 345, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 176, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convertarray", + "long_name": "_convertarray( a )", + "filename": "linalg.py", + "nloc": 12, + "complexity": 4, + "token_count": 83, + "parameters": [ + "a" + ], + "start_line": 211, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "eig", + "long_name": "eig( a )", + "filename": "linalg.py", + "nloc": 51, + "complexity": 5, + "token_count": 499, + "parameters": [ + "a" + ], + "start_line": 226, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "eigh", + "long_name": "eigh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 3, + "token_count": 362, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 283, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "svd", + "long_name": "svd( a , full_matrices = 1 , compute_uv = 1 )", + "filename": "linalg.py", + "nloc": 59, + "complexity": 8, + "token_count": 539, + "parameters": [ + "a", + "full_matrices", + "compute_uv" + ], + "start_line": 322, + "end_line": 385, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "pinv", + "long_name": "pinv( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 389, + "end_line": 403, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "det", + "long_name": "det( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 407, + "end_line": 421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "lstsq", + "long_name": "lstsq( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 425, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "norm", + "long_name": "norm( x , ord = None )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 15, + "token_count": 325, + "parameters": [ + "x", + "ord" + ], + "start_line": 500, + "end_line": 565, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "test", + "long_name": "test( a , b )", + "filename": "linalg.py", + "nloc": 29, + "complexity": 1, + "token_count": 205, + "parameters": [ + "a", + "b" + ], + "start_line": 568, + "end_line": 611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "_makearray", + "long_name": "_makearray( a )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a" + ], + "start_line": 32, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_commonType", + "long_name": "_commonType( * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 2, + "token_count": 54, + "parameters": [ + "arrays" + ], + "start_line": 37, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_castCopyAndTranspose", + "long_name": "_castCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 5, + "complexity": 3, + "token_count": 47, + "parameters": [ + "type", + "arrays" + ], + "start_line": 48, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_fastCopyAndTranspose", + "long_name": "_fastCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 11, + "complexity": 4, + "token_count": 72, + "parameters": [ + "type", + "arrays" + ], + "start_line": 59, + "end_line": 69, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_assertRank2", + "long_name": "_assertRank2( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 25, + "parameters": [ + "arrays" + ], + "start_line": 71, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_assertSquareness", + "long_name": "_assertSquareness( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 30, + "parameters": [ + "arrays" + ], + "start_line": 76, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "solve", + "long_name": "solve( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 83, + "end_line": 107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "inv", + "long_name": "inv( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 112, + "end_line": 114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cholesky", + "long_name": "cholesky( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 3, + "token_count": 105, + "parameters": [ + "a" + ], + "start_line": 118, + "end_line": 132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "eigvals", + "long_name": "eigvals( a )", + "filename": "linalg.py", + "nloc": 39, + "complexity": 4, + "token_count": 363, + "parameters": [ + "a" + ], + "start_line": 136, + "end_line": 174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "eigvalsh", + "long_name": "eigvalsh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 34, + "complexity": 3, + "token_count": 345, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 177, + "end_line": 210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convertarray", + "long_name": "_convertarray( a )", + "filename": "linalg.py", + "nloc": 12, + "complexity": 4, + "token_count": 83, + "parameters": [ + "a" + ], + "start_line": 212, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "eig", + "long_name": "eig( a )", + "filename": "linalg.py", + "nloc": 51, + "complexity": 5, + "token_count": 499, + "parameters": [ + "a" + ], + "start_line": 227, + "end_line": 281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "eigh", + "long_name": "eigh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 3, + "token_count": 362, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 284, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "svd", + "long_name": "svd( a , full_matrices = 1 , compute_uv = 1 )", + "filename": "linalg.py", + "nloc": 59, + "complexity": 8, + "token_count": 539, + "parameters": [ + "a", + "full_matrices", + "compute_uv" + ], + "start_line": 323, + "end_line": 386, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "pinv", + "long_name": "pinv( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 390, + "end_line": 404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "det", + "long_name": "det( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 408, + "end_line": 422, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "lstsq", + "long_name": "lstsq( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 426, + "end_line": 499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "norm", + "long_name": "norm( x , ord = None )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 15, + "token_count": 325, + "parameters": [ + "x", + "ord" + ], + "start_line": 501, + "end_line": 566, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "test", + "long_name": "test( a , b )", + "filename": "linalg.py", + "nloc": 29, + "complexity": 1, + "token_count": 205, + "parameters": [ + "a", + "b" + ], + "start_line": 569, + "end_line": 612, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + } + ], + "changed_methods": [], + "nloc": 490, + "complexity": 85, + "token_count": 4489, + "diff_parsed": { + "added": [], + "deleted": [ + "from old import solve_linear_equations" + ] + } + } + ] + }, + { + "hash": "75f139dacec2845ed18424bb65efbed3280fd0b2", + "msg": "Fix flags getitem.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-15T11:31:30+00:00", + "author_timezone": 0, + "committer_date": "2006-03-15T11:31:30+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "967e9fd69a2113f124591e144b8ede722faa887e" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 40, + "insertions": 70, + "lines": 110, + "files": 1, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/core/src/arrayobject.c", + "new_path": "numpy/core/src/arrayobject.c", + "filename": "arrayobject.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -9302,38 +9302,70 @@ arrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n- if ((strncmp(key,\"CONTIGUOUS\",n)==0) ||\n- (strncmp(key,\"C\",n)))\n- return arrayflags_contiguous_get(self);\n- else if ((strncmp(key, \"FORTRAN\", n)==0) ||\n- (strncmp(key, \"F\", n)==0)) \n- return arrayflags_fortran_get(self);\n- else if ((strncmp(key, \"WRITEABLE\", n)==0) ||\n- (strncmp(key, \"W\", n)==0))\n- return arrayflags_writeable_get(self);\n- else if ((strncmp(key, \"BEHAVED\", n)==0) ||\n- (strncmp(key, \"B\", n)==0))\n- return arrayflags_behaved_get(self);\n- else if ((strncmp(key, \"OWNDATA\", n)==0) ||\n- (strncmp(key, \"O\", n)==0))\n- return arrayflags_owndata_get(self);\n- else if ((strncmp(key, \"ALIGNED\", n)==0) ||\n- (strncmp(key, \"A\", n)==0))\n- return arrayflags_aligned_get(self);\n- else if ((strncmp(key, \"UPDATEIFCOPY\", n)==0) ||\n- (strncmp(key, \"U\", n)==0))\n- return arrayflags_updateifcopy_get(self);\n- else if ((strncmp(key, \"FNC\", n)==0))\n- return arrayflags_fnc_get(self);\n- else if ((strncmp(key, \"FORC\", n)==0))\n- return arrayflags_forc_get(self);\n- else if ((strncmp(key, \"CARRAY\", n)==0) ||\n- (strncmp(key, \"CA\", n)==0))\n- return arrayflags_carray_get(self);\n- else if ((strncmp(key, \"FARRAY\", n)==0) ||\n- (strncmp(key, \"FA\", n)==0))\n- return arrayflags_farray_get(self);\n- else goto fail;\n+\tswitch(n) {\n+\tcase 1:\n+\t\tswitch(key[0]) {\n+\t\tcase 'C':\n+\t\t\treturn arrayflags_contiguous_get(self);\n+\t\tcase 'F':\n+\t\t\treturn arrayflags_fortran_get(self);\n+\t\tcase 'W':\n+\t\t\treturn arrayflags_writeable_get(self);\n+\t\tcase 'B':\n+\t\t\treturn arrayflags_behaved_get(self);\n+\t\tcase 'O':\n+\t\t\treturn arrayflags_owndata_get(self);\n+\t\tcase 'A':\n+\t\t\treturn arrayflags_aligned_get(self);\n+\t\tcase 'U':\n+\t\t\treturn arrayflags_updateifcopy_get(self);\n+\t\tdefault:\n+\t\t\tgoto fail;\n+\t\t}\n+\t\tbreak;\n+\tcase 2:\n+\t\tif (strncmp(key, \"CA\", n)==0)\n+\t\t\treturn arrayflags_carray_get(self);\n+\t\tif (strncmp(key, \"FA\", n)==0)\n+\t\t\treturn arrayflags_farray_get(self);\n+\t\tbreak;\n+\tcase 3:\n+\t\tif (strncmp(key, \"FNC\", n)==0)\n+\t\t\treturn arrayflags_fnc_get(self);\n+\t\tbreak;\n+\tcase 4:\n+\t\tif (strncmp(key, \"FORC\", n)==0)\n+\t\t\treturn arrayflags_forc_get(self);\n+\t\tbreak;\n+\tcase 6:\n+\t\tif (strncmp(key, \"CARRAY\", n)==0)\n+\t\t\treturn arrayflags_carray_get(self);\n+\t\tif (strncmp(key, \"FARRAY\", n)==0)\n+\t\t\treturn arrayflags_farray_get(self);\n+\t\tbreak;\n+\tcase 7:\n+\t\tif (strncmp(key,\"FORTRAN\",n)==0)\n+\t\t\treturn arrayflags_fortran_get(self);\n+\t\tif (strncmp(key,\"BEHAVED\",n)==0)\n+\t\t\treturn arrayflags_behaved_get(self);\n+\t\tif (strncmp(key,\"OWNDATA\",n)==0)\n+\t\t\treturn arrayflags_owndata_get(self);\n+\t\tif (strncmp(key,\"ALIGNED\",n)==0)\n+\t\t\treturn arrayflags_aligned_get(self);\n+\t\tbreak;\n+\tcase 9:\t\n+\t\tif (strncmp(key,\"WRITEABLE\",n)==0)\n+\t\t\treturn arrayflags_writeable_get(self);\n+\t\tbreak;\n+\tcase 10:\n+\t\tif (strncmp(key,\"CONTIGUOUS\",n)==0)\n+\t\t\treturn arrayflags_contiguous_get(self);\n+\t\tbreak;\n+\tcase 12:\n+\t\tif (strncmp(key, \"UPDATEIFCOPY\", n)==0)\n+\t\t\treturn arrayflags_updateifcopy_get(self);\n+\t\tbreak;\n+\t}\n \n fail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n@@ -9348,17 +9380,15 @@ arrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n- if ((strncmp(key, \"WRITEABLE\", n)==0) ||\n- (strncmp(key, \"W\", n)==0))\n+ if (((n==9) && (strncmp(key, \"WRITEABLE\", n)==0)) ||\n+\t ((n==1) && (strncmp(key, \"W\", n)==0)))\n return arrayflags_writeable_set(self, item);\n- else if ((strncmp(key, \"ALIGNED\", n)==0) ||\n- (strncmp(key, \"A\", n)==0))\n+ else if (((n==7) && (strncmp(key, \"ALIGNED\", n)==0)) || \n+ ((n==1) && (strncmp(key, \"A\", n)==0)))\n return arrayflags_aligned_set(self, item);\n- else if ((strncmp(key, \"UPDATEIFCOPY\", n)==0) ||\n- (strncmp(key, \"U\", n)==0))\n+ else if (((n==12) && (strncmp(key, \"UPDATEIFCOPY\", n)==0)) ||\n+ ((n==1) && (strncmp(key, \"U\", n)==0)))\n return arrayflags_updateifcopy_set(self, item); \n- else goto fail;\n- return 0;\n \n fail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n", + "added_lines": 70, + "deleted_lines": 40, + "source_code": "/*\n Provide multidimensional arrays as a basic object type in python.\n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004\n\nHeavily modified in 2005 with inspiration from Numarray\n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University\n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by\nSpace Science Telescope Institute\n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_)\n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear();\n priority = default_;\n }\n Py_XDECREF(ret);\n return priority;\n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a\n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n }\n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int\ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides,\n\t intp *src_dimensions, int src_nd, int elsize,\n\t int copies) {\n intp i, j;\n\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1,\n dest_dimensions+1, dest_nd-1,\n src, src_strides,\n src_dimensions, src_nd,\n elsize, copies) == -1)\n return -1;\n }\n return 0;\n }\n\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError,\n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) &&\n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] !=\n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src)\n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\n dest_strides_ptr = dest_strides;\n\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1)\n return NULL;\n\n new_data = (char *)_pya_malloc(stride);\n\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions,\n dest_nd, src->data, src_strides,\n src_dimensions, src_nd, elsize, copies);\n\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *,\n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int\nPyArray_INCREF(PyArrayObject *mp)\n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap)\n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n\n\n if ((numitems == 1) || (itemsize == srcstrides))\n memcpy(d1, s1, itemsize*numitems);\n else {\n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n }\n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG\n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i)\n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp\nPyArray_Size(PyObject *op)\n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n }\n\telse {\n return 0;\n }\n}\n\n/* If destination is not the right type, then src\n will be cast to destination.\n*/\n\n/* Does a flat iterator-based copy.\n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however.\n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n\n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError,\n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n\n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, elsize);\n PyArray_INCREF(dest);\n return 0;\n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n }\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int\nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)\n{\n PyArrayObject *src;\n int ret;\n\t\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d,\n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t}\n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,\n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd,\n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran,\n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\n return (PyObject *)ret;\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) {\n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED;\n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=0;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use\n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifndef Py_UNICODE_WIDE\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\treturn obj;\n#endif\n\t\t}\n\t\telse {\n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, itemsize);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this.\n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag\n*/\n\n/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp)\n{\n\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n\n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int\nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs,\n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/*\n copyies over from the old descr table for anything\n NULL or zero in what is given.\n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)\n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data,\n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError,\n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr,\n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element\"\\\n \" %d to file\",\n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj);\n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj),\n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\",\n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1)\n fwrite(sep, 1, n3, fp);\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self)\n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0)\n\t\treturn self->descr->f->getitem(self->data,self);\n\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n\n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void\narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an\n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE\n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n\n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\narray_length(PyArrayObject *self)\n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i)\n{\n\tchar *item;\n\tPyArrayObject *r;\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1,\n\t\t\t\t\t\t self->dimensions+1,\n\t\t\t\t\t\t self->strides+1, item,\n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\nstatic PyObject *\narray_item_nice(PyArrayObject *self, _int_or_ssize_t i)\n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\n\nstatic int\narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v)\n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret;\n }\n\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if PY_VERSION_HEX < 0x02050000\n #if SIZEOF_INT == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#else\n #if SIZEOF_SIZE_T == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#endif\n#ifndef array_ass_item\nstatic int\narray_ass_item(PyArrayObject *self, _int_or_ssize_t i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int\nparse_index(PyArrayObject *self, PyObject *op,\n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError,\n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\n nd_old = nd_new = 0;\n\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n\t/* tuple for transpose is\n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of\n\t the broadcasted index array\n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the\n\t result\n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2)\n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call.\n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type,\n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret))\n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, PyArray_ITEMSIZE(arr));\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS];\n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL)\n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0\n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from\n Python when using a[object] unless object is a standard slice object\n (not an extended one).\n\n*/\n\n/* There are two situations:\n\n 1 - the subscript is a standard view and a reference to the\n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned.\n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *);\n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op)\n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr,\n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis) {\n\t\t\t/* XXX: This leads to a small inconsistency\n\t\t\t XXX: with the nd>0 case where (x[...] is x)\n\t\t\t XXX: is false for nd>0 case. */\n\t\t\tPy_INCREF(self);\n\t\t\treturn (PyObject *)self;\n\t\t}\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op)) {\n\t\t\t\tPy_INCREF(self);\n\t\t\t\treturn (PyObject *)self;\n\t\t\t}\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset))\n == -1)\n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset,\n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL)\n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be\n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *);\n\nstatic int\narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)\n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr,\n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1;\n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to\n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op)\n{\n\t/* The following is just a copy of PyArray_Return with an\n\t additional logic in the nd == 0 case. More efficient\n\t implementation may be possible by refactoring\n\t array_subscript */\n\n\tPyArrayObject *mp = (PyArrayObject *)array_subscript(self, op);\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tBool noellipses = TRUE;\n\t\tif (op == Py_Ellipsis)\n\t\t\tnoellipses = FALSE;\n\t\telse if (PySequence_Check(op)) {\n\t\t\tint n, i;\n\t\t\tn = PySequence_Size(op);\n\t\t\tfor (i = 0; i < n; ++i) \n\t\t\t\tif (PySequence_GetItem(op, i) == Py_Ellipsis) {\n\t\t\t\t\tnoellipses = FALSE;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t\tif (noellipses) {\n\t\t\tPyObject *ret;\n\t\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\t\tPy_DECREF(mp);\n\t\t\treturn ret;\n\t\t}\n\t}\n\treturn (PyObject *)mp;\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t /*mp_length*/\n#else\n (inquiry)array_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic _int_or_ssize_t\narray_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp)\n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic _int_or_ssize_t\narray_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"accessing non-existing array segment\");\n return -1;\n }\n\n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic _int_or_ssize_t\narray_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (PyArray_CHKFLAGS(self, WRITEABLE))\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic _int_or_ssize_t\narray_getcharbuf(PyArrayObject *self, _int_or_ssize_t segment, const char **ptrptr)\n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError,\n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (writebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (segcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (charbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#else\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#endif\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n *square,\n *reciprocal,\n *ones_like,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum,\n\t\t*rint;\n} NumericOps;\n\nstatic NumericOps n_ops; /* NB: static objects inlitialized to zero */\n\n/* Dictionary can contain any of the numeric operations, by name.\n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n\n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint\nPyArray_SetNumericOps(PyObject *dict)\n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n SET(square);\n SET(reciprocal);\n SET(ones_like);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\n SET(true_divide);\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n\tSET(rint);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void)\n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL)\n\t\treturn NULL;\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n GET(square);\n GET(reciprocal);\n GET(ones_like);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide);\n GET(true_divide);\n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\tGET(rint);\n\treturn dict;\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,\n\t\t\t\t PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2)\n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\n\nstatic PyObject *array_float(PyArrayObject *v);\n\n\nstatic int\narray_power_is_scalar(PyObject *o2, double* exp)\n{\n PyObject *temp;\n const int optimize_fpexps = 1;\n if (PyInt_Check(o2)) {\n *exp = (double)PyInt_AsLong(o2);\n return 1;\n }\n if (optimize_fpexps && PyFloat_Check(o2)) {\n *exp = PyFloat_AsDouble(o2);\n return 1;\n }\n if (PyArray_CheckScalar(o2)) {\n if (PyArray_ISINTEGER(o2) || (optimize_fpexps && PyArray_ISFLOAT(o2))) {\n temp = array_float((PyArrayObject *)o2);\n if (temp != NULL) {\n *exp = PyFloat_AsDouble(o2);\n Py_DECREF(temp);\n return 1;\n }\n }\n }\n return 0;\n}\n\n/* optimize float array or complex array to a scalar power */\nstatic PyObject *\nfast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) {\n double exp;\n if (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) || PyArray_ISCOMPLEX(a1))) {\n if (array_power_is_scalar(o2, &exp)) {\n PyObject *fastop = NULL;\n if (exp == 1.0) {\n /* we have to do this one special, as the \"copy\" method of\n array objects isn't set up early enough to be added\n by PyArray_SetNumericOps.\n */\n if (inplace) {\n return (PyObject *)a1;\n } else {\n return PyArray_Copy(a1);\n }\n } else if (exp == -1.0) {\n fastop = n_ops.reciprocal;\n } else if (exp == 0.0) {\n fastop = n_ops.ones_like;\n } else if (exp == 0.5) {\n fastop = n_ops.sqrt;\n } else if (exp == 2.0) {\n fastop = n_ops.square;\n } else {\n return NULL;\n }\n if (inplace) {\n PyArray_GenericInplaceUnaryFunction(a1, fastop);\n } else {\n return PyArray_GenericUnaryFunction(a1, fastop);\n }\n }\n }\n return NULL;\n}\n\nstatic PyObject *\narray_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 0);\n if (!value) {\n value = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\n\nstatic PyObject *\narray_negative(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 1);\n if (!value) {\n value = PyArray_GenericInplaceBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int\narray_any_nonzero(PyArrayObject *mp)\n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2)\n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_float(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to a \"\\\n\t\t\t\t\"float; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_long(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/\n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected\n*/\n\n\nstatic PyObject *\narray_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t _int_or_ssize_t ihigh)\n{\n PyArrayObject *r;\n _int_or_ssize_t l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n self->dimensions[0] = l;\n\tif (r == NULL) return NULL;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS);\n return (PyObject *)r;\n}\n\n\nstatic int\narray_ass_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t\t_int_or_ssize_t ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res;\n int ret;\n\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\nstatic PySequenceMethods array_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (ssizeargfunc)NULL,\n\t(ssizeargfunc)array_item_nice,\n\t(ssizessizeargfunc)array_slice,\n (ssizeobjargproc)array_ass_item,\t /*sq_ass_item*/\n (ssizessizeobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(ssizeargfunc)NULL,\n#else\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t /*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n#endif\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int\ndump_data(char **string, int *n, int *max_n, char *data, int nd,\n intp *dimensions, intp *strides, PyArrayObject* self)\n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\n if (nd == 0) {\n\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata,\n\t\t self->nd, self->dimensions,\n self->strides, self) < 0) {\n\t\t_pya_free(string); return NULL;\n\t}\n\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void\nPyArray_SetStringFunction(PyObject *op, int repr)\n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_ReprFunction = op;\n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_StrFunction = op;\n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)\n{\n PyObject *array_other, *result;\n\tint typenum;\n\n switch (cmp_op)\n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then return False\n\t\t\t\t This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of False\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the\n\t\t\t two array objects can not be compared together so\n\t\t\t return zero\n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be\n\t\t\t\t compared and cannot be equal, therefore,\n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t other,\n\t\t\t\t\t\t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL,\n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int\n_IsFortranContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap)\n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object\n\t If it is a writeable array, then return TRUE\n\t If we can find an array object\n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable\n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA))\n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly\n\t and unpickled array can be set and reset writeable\n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t\telse ret->flags &= ~WRITEABLE;\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not\n ever be able to walk outside of the memory implied numbytes and offset.\n\n The available memory is assumed to start at -offset and proceed\n to numbytes-offset. The strides are checked to ensure\n that accessing memory using striding will not try to reach beyond\n this memory for any of the axes.\n\n If numbytes is 0 it will be calculated using the dimensions and\n element-size.\n\n This function checks for walking beyond the beginning and right-end\n of the buffer and therefore works for any integer stride (positive\n or negative).\n*/\n\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\tintp byte_begin;\n\tintp begin;\n\tintp end;\n\n\tif (numbytes == 0)\n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\n\tbegin = -offset;\n\tend = numbytes - offset - elsize;\n\tfor (i=0; i end))\n\t\t\treturn FALSE;\n\t}\n\treturn TRUE;\n\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings\n depending on data and strides:\n\n If data is given, then flags is flags associated with data.\n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument\n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set).\n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired.\n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize,\n\t\t int inflag, int *objflags)\n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\n/* and update the dimensions and strides\n appropriately. Dimensions and strides are added\n to the end unless we have a FORTRAN array\n and then they are added to the beginning\n\n Strides are only added if given (because data is given).\n*/\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,\n\t\t\t intp *newstrides, int oldnd, int isfortran)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\tint tuple;\n\n\told = *des;\n\t*des = old->subarray->base;\n\n\n\tmydim = newdims + oldnd;\n\ttuple = PyTuple_Check(old->subarray->shape);\n\tif (tuple) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t}\n\telse {\n\t\tnumnew = 1;\n\t}\n\n\n\tnewnd = oldnd + numnew;\n\tif (newnd > MAX_DIMS) goto finish;\n\tif (isfortran) {\n\t\tmemmove(newdims+numnew, newdims, oldnd*sizeof(intp));\n\t\tmydim = newdims;\n\t}\n\n\tif (tuple) {\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\tif (isfortran) {\n\t\t\tmemmove(newstrides+numnew, newstrides,\n\t\t\t\toldnd*sizeof(intp));\n\t\t\tmystrides = newstrides;\n\t\t}\n\t\t/* Make new strides -- alwasy C-contiguous */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\n finish:\n\tPy_INCREF(*des);\n\tPy_DECREF(old);\n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,\n\t\t intp *dims, intp *strides, void *data,\n\t\t int flags, PyObject *obj)\n{\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tint isfortran=0;\n\t\tisfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || \\\n\t\t\t(!data && flags);\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims,\n\t\t\t\t\t\t newstrides, nd, isfortran);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims,\n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { \n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN;\n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse { /* we allow strides even when we create\n\t\t\t the memory, but be careful with this...\n\t\t */\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays\n\t\t e.g. shape=(0,) -- otherwise buffer exposure\n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in,\n\t\t\t\t\t this object won't own it\n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for\n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype.\n\t If obj is NULL, then call method with Py_None \n\t*/\n\tif ((subtype != &PyArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (strides != NULL) { /* did not allocate own data \n\t\t\t\t\t or funny strides */\n\t\t\t/* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tif (obj == NULL) obj=Py_None;\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n If refcheck is 0, then the reference count is not checked\n and assumed to be 1.\n You still must own this data and have no weak-references and no base\n object.\n*/\nstatic PyObject *\nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\n if (!PyArray_ISONESEGMENT(self)) {\n PyErr_SetString(PyExc_ValueError,\n \"resize only works on single-segment arrays\");\n return NULL;\n }\n\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n\n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (refcheck) refcnt = REFCOUNT(self);\n\t\telse refcnt = 1;\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (newsize == 0) sd = self->descr->elsize;\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n\n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) {\n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0,\n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n\n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n\n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n self->flags, &(self->flags));\n\n\n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\n return Py_None;\n\n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\tPyArray_FillWithScalarFunc* fillwithscalar =\n\t\t\tarr->descr->f->fillwithscalar;\n\t\tif (fillwithscalar && PyArray_ISALIGNED(arr)) {\n\t\t\tcopyswap(fromptr, NULL, swap, itemsize);\n\t\t\tfillwithscalar(toptr, size, fromptr, arr);\n\t\t}\n\t\telse {\n\t\t\twhile (size--) {\n\t\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\t\ttoptr += itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL;\n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous\n\t array of a specific type and shape.\n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims,\n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter,\n &strides,\n &fortran))\n\t\tgoto fail;\n\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"data-type with unspecified variable length\");\n\t\tgoto fail;\n\t}\n\t\n\tif (strides.ptr != NULL) {\n\t\tintp nb, off;\n\t\tif (strides.len != dims.len) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides, if given, must be \"\t\\\n\t\t\t\t\t\"the same length as shape\");\n\t\t\tgoto fail;\n\t\t}\n\n\t\tif (buffer.ptr == NULL) {\n\t\t\tnb = 0;\n\t\t\toff = 0;\n\t\t}\n\t\telse {\n\t\t\tnb = buffer.len;\n\t\t\toff = offset;\n\t\t}\n\t\t\n\n\t\tif (!PyArray_CheckStrides(itemsize, dims.len, \n\t\t\t\t\t nb, off,\n\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides is incompatible \"\t\\\n\t\t\t\t\t\"with shape of requested \"\t\\\n\t\t\t\t\t\"array and size of buffer\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\t\t\t\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len,\n\t\t\t\t\t dims.ptr,\n\t\t\t\t\t strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = (buffer.len-offset) / itemsize;\n }\n else if ((strides.ptr == NULL) && \\\n\t\t\t buffer.len < itemsize*\t\t\t\t\\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError,\n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t offset + (char *)buffer.ptr,\n\t\t\t\t\t buffer.flags, NULL);\n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base);\n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyArray_NewFlagsObject((PyObject *)self);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n\tint nd;\n\tPyObject *ret;\n\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret),\n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret),\n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes=0;\n\tintp offset=0;\n\tint buf_len;\n\tchar *buf;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base && PyArray_Check(new->base)) {\n\t\tnew = (PyArrayObject *)(new->base);\n\t}\n\t/* Get the available memory through the buffer\n\t interface on new->base or if that fails\n\t from the current new */\n\tif (new->base && PyObject_AsReadBuffer(new->base,\n\t\t\t\t\t (const void **)&buf,\n\t\t\t\t\t &buf_len) >= 0) {\n\t\toffset = self->data - buf;\n\t\tnumbytes = buf_len + offset;\n\t}\n\telse {\n\t\tPyErr_Clear();\n \t\tnumbytes = PyArray_MultiplyList(new->dimensions,\n\t\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\toffset = self->data - new->data;\n\t}\n\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes,\n\t\t\t\t offset,\n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self))\n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self)\n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0,\n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf,\n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse\n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse\n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed.\n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the\n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0)\n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n\telse if (newtype->elsize > self->descr->elsize) {\n\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update\n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\t/* We would decref newtype here --- temp will\n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tif (temp == NULL) return -1;\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\tPy_INCREF(temp->descr);\n\t\t/* Fool deallocator not to delete these*/\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype;\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA);\n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num -\n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type,\n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new);\n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int\narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode,\n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr));\n memmove(selfit->dataptr, arrit->dataptr,\n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size)\n PyArray_ITER_RESET(arrit);\n }\n retval = 0;\n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->descr->elsize);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size)\n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\",\n\t (getter)array_ndim_get,\n\t NULL,\n\t \"number of array dimensions\"},\n {\"flags\",\n\t (getter)array_flags_get,\n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\",\n\t (getter)array_shape_get,\n\t (setter)array_shape_set,\n\t \"tuple of array dimensions\"},\n {\"strides\",\n\t (getter)array_strides_get,\n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)array_data_get,\n\t (setter)array_data_set,\n\t \"pointer to start of data\"},\n {\"itemsize\",\n\t (getter)array_itemsize_get,\n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\",\n\t (getter)array_real_get,\n\t (setter)array_real_set,\n\t \"real part of array\"},\n {\"imag\",\n\t (getter)array_imag_get,\n\t (setter)array_imag_set,\n\t \"imaginary part of array\"},\n\t{\"flat\",\n\t (getter)array_flat_get,\n\t (setter)array_flat_set,\n\t \"a 1-d view of a contiguous array\"},\n\t{\"__array_data__\",\n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\",\n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n\t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */\n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] =\n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\nstatic PyTypeObject PyArray_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0,\t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n &array_as_sequence,\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str,\t /*tp_str*/\n\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n &array_as_buffer, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT\n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter,\t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n array_alloc,\t /* tp_alloc */\n (newfunc)array_new,\t\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int\ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple)\n{\n int d=0;\n PyObject *e;\n\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0)\n\t\treturn 1;\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize)\n{\n\tint n, r, i;\n\tPyObject *e;\n\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s)\n\t\t\t*itemsize = MAX(*itemsize, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype ---\n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately\n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE &&\n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\nstatic PyArray_Descr *\n_array_find_python_scalar_type(PyObject *op)\n{\n if (PyFloat_Check(op)) {\n return PyArray_DescrFromType(PyArray_DOUBLE);\n } else if (PyComplex_Check(op)) {\n return PyArray_DescrFromType(PyArray_CDOUBLE);\n } else if (PyInt_Check(op)) {\n /* bools are a subclass of int */\n if (PyBool_Check(op)) {\n return PyArray_DescrFromType(PyArray_BOOL);\n } else {\n return PyArray_DescrFromType(PyArray_LONG);\n }\n } else if (PyLong_Check(op)) {\n /* if integer can fit into a longlong then return that\n */\n if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n PyErr_Clear();\n return PyArray_DescrFromType(PyArray_OBJECT);\n }\n return PyArray_DescrFromType(PyArray_LONGLONG);\n }\n return NULL;\n}\n\n/* op is an object to be converted to an ndarray.\n\n minitype is the minimum type-descriptor needed.\n\n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n\n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\n\tif (minitype == NULL)\n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\n if (max < 0) goto deflt;\n\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n chktype = _array_find_python_scalar_type(op);\n if (chktype) {\n goto finish;\n }\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n\n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind,\n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n }\n\n\tif (PyInstance_Check(op)) goto deflt;\n\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\n finish:\n\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype;\n}\n\nstatic int\nAssign_Array(PyArrayObject *self, PyObject *v)\n{\n PyObject *e;\n int l, r;\n\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\n l=PyObject_Length(v);\n if(l < 0) return -1;\n\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1;\n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */\n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode)\n{\n PyArrayObject *ret;\n\tint itemsize;\n\tint type;\n\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= 4;\n\n\t\tif (itemsize != typecode->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(typecode);\n\t\t\ttypecode->elsize = itemsize;\n\t\t}\n\t}\n\n ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL,\n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\tif (ret == NULL) return NULL;\n\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode */\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string,\n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid input sequence\");\n\t\tgoto fail;\n }\n\n\tif (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {\n\t\tnd = max_depth;\n\t}\n\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid number of dimensions\");\n\t\tgoto fail;\n }\n\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\n if(!r) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int\nPyArray_ValidType(int type)\n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in))\n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, 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\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n oelsize);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject *\nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING)\n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd,\n\t\t\t\t mp->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\n}\n\n/* The number of elements in out must be an integer multiple\n of the number of elements in mp.\n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1;\n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * mpsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr,\n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)\n{\n\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1)\n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse {\n if ((flags & ENSUREARRAY)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype,\n\t\t\t\t\t\t newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr;\n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\n\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong))\n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char))\n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long))\n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap)\n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n\n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL;\n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n\n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data,\n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr));\n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n\n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context)\n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, \n\t\t\t\t\t\t\t\t NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None,\n\t\t\t\t\t\t context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", \n\t\t\t\t\t\t typecode, context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", \n\t\t\t\t\t\t\t typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError,\n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n}\n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,\n int max_depth, int flags, PyObject *context)\n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op))\n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t} else if (newtype == NULL &&\n (newtype = _array_find_python_scalar_type(op))) {\n r = Array_FromScalar(op, newtype);\n }\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, \n\t\t\t\t\t\tflags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\n\t/* Be sure we succeed here */\n\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int\nPyArray_ObjectType(PyObject *op, int minimum_type)\n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of\n CONTIGUOUS,\n FORTRAN,\n ALIGNED,\n WRITEABLE,\n NOTSWAPPED,\n ENSURECOPY,\n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should\n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or\n not it has such features.\n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well.\n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n\n FORTRAN can be set in the FLAGS to request a FORTRAN array.\n Fortran arrays are always behaved (aligned,\n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d).\n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array.\n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe.\n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,\n int max_depth, int requires, PyObject *context)\n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0,\n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place\n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op)) return op;\n\n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int\nPyArray_CanCastSafely(int fromtype, int totype)\n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype))\n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode\n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\n\t\t*/\n\t}\n\treturn ret;\n}\n\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n\n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd;\n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D)\n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic _int_or_ssize_t\niter_length(PyArrayIterObject *self)\n{\n return self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr,\n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1)\n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t 1, &n_steps,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail;\n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0,\n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n\t\t\t\t itemsize);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size)\n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size)\n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)\n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size)\n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0,\n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)iter_length,\t\t /*mp_length*/\n#else\n (inquiry)iter_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op)\n{\n\n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options:\n 1) underlying array is contiguous\n -- return 1-d wrapper around it\n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, it->ao->data,\n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r);\n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n\n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\",\n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &iter_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t\t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular\n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators\n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++)\n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already\n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1)\n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\n\t\t\t\t\t\t\t\"to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of\n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord,\n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t sizeof(intp));\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so,\n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size.\n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere.\n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well.\n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0\n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t/* But, be sure to do it with a true array.\n\t */\n\tif (PyArray_CheckExact(arr)) {\n\t\tsub = array_subscript(arr, mit->indexobj);\n\t}\n\telse {\n\t\tPy_INCREF(arr);\n\t\tobj = PyArray_EnsureArray((PyObject *)arr);\n\t\tif (obj == NULL) goto fail;\n\t\tsub = array_subscript((PyArrayObject *)obj, mit->indexobj);\n\t\tPy_DECREF(obj);\n\t}\n\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects\n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been\n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj))\n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj,\n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1;\n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) *indptr, (int) (dimsize-1),\n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0,\n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n\tmit->index = 0;\n\tmit->ait = NULL;\n\tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY\n#undef SOBJ_ISFANCY\n#undef SOBJ_BADARRAY\n#undef SOBJ_TOOMANY\n#undef SOBJ_LISTTUP\n\n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple\n\t (with at least 1 list or arrayobject or Bool object), */\n\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i,\n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing\n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n\n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work.\n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a);\n mapiter is equivalent to a[indexobj].flat but the latter gets to use\n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t\t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t\t /* tp_iter */\n (iternextfunc)0,\t /* tp_iternext */\n 0,\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\n\tint i, err=0;\n\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\n\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL)\n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i,\n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(multi->iters[i]);\n\t_pya_free(multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\",\n\t (getter)arraymultiter_size_get,\n\t NULL,\n\t \"total size of broadcasted result\"},\n {\"index\",\n\t (getter)arraymultiter_index_get,\n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter),\n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t\t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods,\t /* tp_methods */\n arraymultiter_members,\t\t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types.\n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these\n builtins will be attempted leading to problems.\n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically\n allocated).\n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless\n there is a reference-count problem\n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set.\n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base,\n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0)\n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\",\n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self)\n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\",\n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr)\n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr)\n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv))\n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\n\t/* Now return the state which is at least\n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize\n and alignment for EXTENDED arrays\n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\n\tif (PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are:\n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args)\n{\n\tchar endian=PyArray_SWAP;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS,\n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n\tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\ndescr_length(PyArray_Descr *self)\n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op)\n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError,\n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)descr_length,\t\t /*mp_length*/\n#else\n (inquiry)descr_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t\t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &descr_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t/* tp_iternext */\n arraydescr_methods,\t\t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n\n/** Array Flags Object **/\n\ntypedef struct PyArrayFlagsObject {\n PyObject_HEAD\n PyObject *arr;\n int flags;\n} PyArrayFlagsObject;\n\n/*OBJECT_API\n Get New ArrayFlagsObject\n*/\nstatic PyObject *\nPyArray_NewFlagsObject(PyObject *obj)\n{\n PyObject *flagobj;\n int flags;\n if (obj == NULL) {\n flags = CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n }\n else {\n flags = PyArray_FLAGS(obj);\n }\n flagobj = PyArrayFlags_Type.tp_alloc(&PyArrayFlags_Type, 0);\n if (flagobj == NULL) return NULL;\n Py_XINCREF(obj);\n ((PyArrayFlagsObject *)flagobj)->arr = obj;\n ((PyArrayFlagsObject *)flagobj)->flags = flags;\n\n return flagobj;\n}\n\nstatic void\narrayflags_dealloc(PyArrayFlagsObject *self)\n{\n\tPy_XDECREF(self->arr);\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n\n#define _define_get(UPPER, lower) \\\nstatic PyObject * \\\narrayflags_ ## lower ## _get(PyArrayFlagsObject *self) \\\n{ \\\n PyObject *item; \\\n item = ((self->flags & (UPPER)) == (UPPER)) ? Py_True : Py_False; \\\n Py_INCREF(item); \\\n return item; \\\n}\n\n_define_get(CONTIGUOUS, contiguous)\n_define_get(FORTRAN, fortran)\n_define_get(UPDATEIFCOPY, updateifcopy)\n_define_get(OWNDATA, owndata)\n_define_get(ALIGNED, aligned)\n_define_get(WRITEABLE, writeable)\n\n_define_get(ALIGNED|WRITEABLE, behaved)\n_define_get(ALIGNED|WRITEABLE|CONTIGUOUS, carray)\n\nstatic PyObject *\narrayflags_forc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) ||\n ((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_fnc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_farray_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & (ALIGNED|WRITEABLE|FORTRAN)) == \\\n (ALIGNED|WRITEABLE|FORTRAN)) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_num_get(PyArrayFlagsObject *self)\n{\n return PyInt_FromLong(self->flags);\n}\n\n/* relies on setflags order being write, align, uic */\nstatic int\narrayflags_updateifcopy_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False));\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_aligned_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_writeable_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None, Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\n\nstatic PyGetSetDef arrayflags_getsets[] = {\n\t{\"contiguous\",\n\t (getter)arrayflags_contiguous_get,\n\t NULL,\n\t \"\"},\n {\"fortran\",\n (getter)arrayflags_fortran_get,\n NULL,\n \"\"},\n {\"updateifcopy\",\n (getter)arrayflags_updateifcopy_get,\n (setter)arrayflags_updateifcopy_set,\n \"\"},\n {\"owndata\",\n (getter)arrayflags_owndata_get,\n NULL,\n \"\"},\n {\"aligned\",\n (getter)arrayflags_aligned_get,\n (setter)arrayflags_aligned_set,\n \"\"},\n {\"writeable\",\n (getter)arrayflags_writeable_get,\n (setter)arrayflags_writeable_set,\n \"\"},\n {\"fnc\",\n (getter)arrayflags_fnc_get,\n NULL,\n \"\"},\n {\"forc\",\n (getter)arrayflags_forc_get,\n NULL,\n \"\"},\n {\"behaved\",\n (getter)arrayflags_behaved_get,\n NULL,\n \"\"},\n {\"carray\",\n (getter)arrayflags_carray_get,\n NULL,\n \"\"},\n {\"farray\",\n (getter)arrayflags_farray_get,\n NULL,\n \"\"},\n {\"num\",\n (getter)arrayflags_num_get,\n NULL,\n \"\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyObject *\narrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)\n{\n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n\tswitch(n) {\n\tcase 1:\n\t\tswitch(key[0]) {\n\t\tcase 'C':\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tcase 'F':\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tcase 'W':\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tcase 'B':\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tcase 'O':\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tcase 'A':\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tcase 'U':\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tdefault:\n\t\t\tgoto fail;\n\t\t}\n\t\tbreak;\n\tcase 2:\n\t\tif (strncmp(key, \"CA\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FA\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 3:\n\t\tif (strncmp(key, \"FNC\", n)==0)\n\t\t\treturn arrayflags_fnc_get(self);\n\t\tbreak;\n\tcase 4:\n\t\tif (strncmp(key, \"FORC\", n)==0)\n\t\t\treturn arrayflags_forc_get(self);\n\t\tbreak;\n\tcase 6:\n\t\tif (strncmp(key, \"CARRAY\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FARRAY\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 7:\n\t\tif (strncmp(key,\"FORTRAN\",n)==0)\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tif (strncmp(key,\"BEHAVED\",n)==0)\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tif (strncmp(key,\"OWNDATA\",n)==0)\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tif (strncmp(key,\"ALIGNED\",n)==0)\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tbreak;\n\tcase 9:\t\n\t\tif (strncmp(key,\"WRITEABLE\",n)==0)\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tbreak;\n\tcase 10:\n\t\tif (strncmp(key,\"CONTIGUOUS\",n)==0)\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tbreak;\n\tcase 12:\n\t\tif (strncmp(key, \"UPDATEIFCOPY\", n)==0)\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tbreak;\n\t}\n\n fail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return NULL;\n}\n\nstatic int\narrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)\n{ \n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n if (((n==9) && (strncmp(key, \"WRITEABLE\", n)==0)) ||\n\t ((n==1) && (strncmp(key, \"W\", n)==0)))\n return arrayflags_writeable_set(self, item);\n else if (((n==7) && (strncmp(key, \"ALIGNED\", n)==0)) || \n ((n==1) && (strncmp(key, \"A\", n)==0)))\n return arrayflags_aligned_set(self, item);\n else if (((n==12) && (strncmp(key, \"UPDATEIFCOPY\", n)==0)) ||\n ((n==1) && (strncmp(key, \"U\", n)==0)))\n return arrayflags_updateifcopy_set(self, item); \n\nfail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return -1;\n}\n\nstatic char *\n_torf_(int flags, int val)\n{\n if ((flags & val) == val) return \"True\";\n else return \"False\"; \n}\n\nstatic PyObject *\narrayflags_print(PyArrayFlagsObject *self)\n{\n int fl = self->flags;\n \n return PyString_FromFormat(\" %s : %s\\n %s : %s\\n %s : %s\\n\"\\\n \" %s : %s\\n %s : %s\\n %s : %s\",\n \"CONTIGUOUS\", _torf_(fl, CONTIGUOUS),\n \"FORTRAN\", _torf_(fl, FORTRAN),\n \"OWNDATA\", _torf_(fl, OWNDATA),\n \"WRITEABLE\", _torf_(fl, WRITEABLE),\n \"ALIGNED\", _torf_(fl, ALIGNED),\n \"UPDATEIFCOPY\", _torf_(fl, UPDATEIFCOPY));\n}\n\n\nstatic PyMappingMethods arrayflags_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)NULL, \t\t /*mp_length*/\n#else\n (inquiry)NULL, \t\t /*mp_length*/\n#endif\n (binaryfunc)arrayflags_getitem,\t /*mp_subscript*/\n (objobjargproc)arrayflags_setitem, /*mp_ass_subscript*/\n};\n\n\nstatic PyObject *\narrayflags_new(PyTypeObject *self, PyObject *args, PyObject *kwds)\n{\n PyObject *arg=NULL;\n if (!PyArg_UnpackTuple(args, \"flagsobj\", 0, 1, &arg))\n return NULL;\n\n if ((arg != NULL) && PyArray_Check(arg)) {\n return PyArray_NewFlagsObject(arg);\n }\n else {\n return PyArray_NewFlagsObject(NULL);\n }\n}\n\nstatic PyTypeObject PyArrayFlags_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\n \"numpy.flagsobj\",\n sizeof(PyArrayFlagsObject),\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayflags_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t0,\t\t /* tp_compare */\n (reprfunc)arrayflags_print, /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &arrayflags_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arrayflags_print, /* tp_str */\n 0,\t \t /* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t /* tp_iternext */\n 0,\t \t /* tp_methods */\n 0,\t /* tp_members */\n arrayflags_getsets, /* tp_getset */\n 0,\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t /* tp_init */\n 0,\t /* tp_alloc */\n arrayflags_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "source_code_before": "/*\n Provide multidimensional arrays as a basic object type in python.\n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004\n\nHeavily modified in 2005 with inspiration from Numarray\n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University\n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by\nSpace Science Telescope Institute\n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_)\n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear();\n priority = default_;\n }\n Py_XDECREF(ret);\n return priority;\n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a\n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n }\n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int\ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides,\n\t intp *src_dimensions, int src_nd, int elsize,\n\t int copies) {\n intp i, j;\n\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1,\n dest_dimensions+1, dest_nd-1,\n src, src_strides,\n src_dimensions, src_nd,\n elsize, copies) == -1)\n return -1;\n }\n return 0;\n }\n\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError,\n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) &&\n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] !=\n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src)\n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\n dest_strides_ptr = dest_strides;\n\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1)\n return NULL;\n\n new_data = (char *)_pya_malloc(stride);\n\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions,\n dest_nd, src->data, src_strides,\n src_dimensions, src_nd, elsize, copies);\n\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *,\n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int\nPyArray_INCREF(PyArrayObject *mp)\n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap)\n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n\n\n if ((numitems == 1) || (itemsize == srcstrides))\n memcpy(d1, s1, itemsize*numitems);\n else {\n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n }\n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG\n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i)\n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp\nPyArray_Size(PyObject *op)\n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n }\n\telse {\n return 0;\n }\n}\n\n/* If destination is not the right type, then src\n will be cast to destination.\n*/\n\n/* Does a flat iterator-based copy.\n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however.\n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n\n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError,\n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n\n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, elsize);\n PyArray_INCREF(dest);\n return 0;\n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n }\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int\nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)\n{\n PyArrayObject *src;\n int ret;\n\t\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d,\n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t}\n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,\n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd,\n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran,\n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\n return (PyObject *)ret;\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) {\n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED;\n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=0;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use\n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifndef Py_UNICODE_WIDE\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\treturn obj;\n#endif\n\t\t}\n\t\telse {\n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, itemsize);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this.\n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag\n*/\n\n/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp)\n{\n\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n\n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int\nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs,\n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/*\n copyies over from the old descr table for anything\n NULL or zero in what is given.\n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)\n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data,\n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError,\n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr,\n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element\"\\\n \" %d to file\",\n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj);\n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj),\n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\",\n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1)\n fwrite(sep, 1, n3, fp);\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self)\n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0)\n\t\treturn self->descr->f->getitem(self->data,self);\n\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n\n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void\narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an\n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE\n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n\n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\narray_length(PyArrayObject *self)\n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i)\n{\n\tchar *item;\n\tPyArrayObject *r;\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1,\n\t\t\t\t\t\t self->dimensions+1,\n\t\t\t\t\t\t self->strides+1, item,\n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\nstatic PyObject *\narray_item_nice(PyArrayObject *self, _int_or_ssize_t i)\n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\n\nstatic int\narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v)\n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret;\n }\n\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if PY_VERSION_HEX < 0x02050000\n #if SIZEOF_INT == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#else\n #if SIZEOF_SIZE_T == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#endif\n#ifndef array_ass_item\nstatic int\narray_ass_item(PyArrayObject *self, _int_or_ssize_t i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int\nparse_index(PyArrayObject *self, PyObject *op,\n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError,\n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\n nd_old = nd_new = 0;\n\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n\t/* tuple for transpose is\n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of\n\t the broadcasted index array\n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the\n\t result\n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2)\n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call.\n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type,\n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret))\n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, PyArray_ITEMSIZE(arr));\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS];\n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL)\n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0\n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from\n Python when using a[object] unless object is a standard slice object\n (not an extended one).\n\n*/\n\n/* There are two situations:\n\n 1 - the subscript is a standard view and a reference to the\n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned.\n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *);\n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op)\n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr,\n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis) {\n\t\t\t/* XXX: This leads to a small inconsistency\n\t\t\t XXX: with the nd>0 case where (x[...] is x)\n\t\t\t XXX: is false for nd>0 case. */\n\t\t\tPy_INCREF(self);\n\t\t\treturn (PyObject *)self;\n\t\t}\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op)) {\n\t\t\t\tPy_INCREF(self);\n\t\t\t\treturn (PyObject *)self;\n\t\t\t}\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset))\n == -1)\n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset,\n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL)\n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be\n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *);\n\nstatic int\narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)\n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr,\n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1;\n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to\n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op)\n{\n\t/* The following is just a copy of PyArray_Return with an\n\t additional logic in the nd == 0 case. More efficient\n\t implementation may be possible by refactoring\n\t array_subscript */\n\n\tPyArrayObject *mp = (PyArrayObject *)array_subscript(self, op);\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tBool noellipses = TRUE;\n\t\tif (op == Py_Ellipsis)\n\t\t\tnoellipses = FALSE;\n\t\telse if (PySequence_Check(op)) {\n\t\t\tint n, i;\n\t\t\tn = PySequence_Size(op);\n\t\t\tfor (i = 0; i < n; ++i) \n\t\t\t\tif (PySequence_GetItem(op, i) == Py_Ellipsis) {\n\t\t\t\t\tnoellipses = FALSE;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t\tif (noellipses) {\n\t\t\tPyObject *ret;\n\t\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\t\tPy_DECREF(mp);\n\t\t\treturn ret;\n\t\t}\n\t}\n\treturn (PyObject *)mp;\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t /*mp_length*/\n#else\n (inquiry)array_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic _int_or_ssize_t\narray_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp)\n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic _int_or_ssize_t\narray_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"accessing non-existing array segment\");\n return -1;\n }\n\n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic _int_or_ssize_t\narray_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (PyArray_CHKFLAGS(self, WRITEABLE))\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic _int_or_ssize_t\narray_getcharbuf(PyArrayObject *self, _int_or_ssize_t segment, const char **ptrptr)\n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError,\n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (writebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (segcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (charbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#else\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#endif\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n *square,\n *reciprocal,\n *ones_like,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum,\n\t\t*rint;\n} NumericOps;\n\nstatic NumericOps n_ops; /* NB: static objects inlitialized to zero */\n\n/* Dictionary can contain any of the numeric operations, by name.\n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n\n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint\nPyArray_SetNumericOps(PyObject *dict)\n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n SET(square);\n SET(reciprocal);\n SET(ones_like);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\n SET(true_divide);\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n\tSET(rint);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void)\n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL)\n\t\treturn NULL;\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n GET(square);\n GET(reciprocal);\n GET(ones_like);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide);\n GET(true_divide);\n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\tGET(rint);\n\treturn dict;\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,\n\t\t\t\t PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2)\n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\n\nstatic PyObject *array_float(PyArrayObject *v);\n\n\nstatic int\narray_power_is_scalar(PyObject *o2, double* exp)\n{\n PyObject *temp;\n const int optimize_fpexps = 1;\n if (PyInt_Check(o2)) {\n *exp = (double)PyInt_AsLong(o2);\n return 1;\n }\n if (optimize_fpexps && PyFloat_Check(o2)) {\n *exp = PyFloat_AsDouble(o2);\n return 1;\n }\n if (PyArray_CheckScalar(o2)) {\n if (PyArray_ISINTEGER(o2) || (optimize_fpexps && PyArray_ISFLOAT(o2))) {\n temp = array_float((PyArrayObject *)o2);\n if (temp != NULL) {\n *exp = PyFloat_AsDouble(o2);\n Py_DECREF(temp);\n return 1;\n }\n }\n }\n return 0;\n}\n\n/* optimize float array or complex array to a scalar power */\nstatic PyObject *\nfast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) {\n double exp;\n if (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) || PyArray_ISCOMPLEX(a1))) {\n if (array_power_is_scalar(o2, &exp)) {\n PyObject *fastop = NULL;\n if (exp == 1.0) {\n /* we have to do this one special, as the \"copy\" method of\n array objects isn't set up early enough to be added\n by PyArray_SetNumericOps.\n */\n if (inplace) {\n return (PyObject *)a1;\n } else {\n return PyArray_Copy(a1);\n }\n } else if (exp == -1.0) {\n fastop = n_ops.reciprocal;\n } else if (exp == 0.0) {\n fastop = n_ops.ones_like;\n } else if (exp == 0.5) {\n fastop = n_ops.sqrt;\n } else if (exp == 2.0) {\n fastop = n_ops.square;\n } else {\n return NULL;\n }\n if (inplace) {\n PyArray_GenericInplaceUnaryFunction(a1, fastop);\n } else {\n return PyArray_GenericUnaryFunction(a1, fastop);\n }\n }\n }\n return NULL;\n}\n\nstatic PyObject *\narray_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 0);\n if (!value) {\n value = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\n\nstatic PyObject *\narray_negative(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 1);\n if (!value) {\n value = PyArray_GenericInplaceBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int\narray_any_nonzero(PyArrayObject *mp)\n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2)\n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_float(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to a \"\\\n\t\t\t\t\"float; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_long(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/\n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected\n*/\n\n\nstatic PyObject *\narray_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t _int_or_ssize_t ihigh)\n{\n PyArrayObject *r;\n _int_or_ssize_t l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n self->dimensions[0] = l;\n\tif (r == NULL) return NULL;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS);\n return (PyObject *)r;\n}\n\n\nstatic int\narray_ass_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t\t_int_or_ssize_t ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res;\n int ret;\n\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\nstatic PySequenceMethods array_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (ssizeargfunc)NULL,\n\t(ssizeargfunc)array_item_nice,\n\t(ssizessizeargfunc)array_slice,\n (ssizeobjargproc)array_ass_item,\t /*sq_ass_item*/\n (ssizessizeobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(ssizeargfunc)NULL,\n#else\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t /*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n#endif\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int\ndump_data(char **string, int *n, int *max_n, char *data, int nd,\n intp *dimensions, intp *strides, PyArrayObject* self)\n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\n if (nd == 0) {\n\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata,\n\t\t self->nd, self->dimensions,\n self->strides, self) < 0) {\n\t\t_pya_free(string); return NULL;\n\t}\n\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void\nPyArray_SetStringFunction(PyObject *op, int repr)\n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_ReprFunction = op;\n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_StrFunction = op;\n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)\n{\n PyObject *array_other, *result;\n\tint typenum;\n\n switch (cmp_op)\n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then return False\n\t\t\t\t This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of False\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the\n\t\t\t two array objects can not be compared together so\n\t\t\t return zero\n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be\n\t\t\t\t compared and cannot be equal, therefore,\n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t other,\n\t\t\t\t\t\t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL,\n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int\n_IsFortranContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap)\n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object\n\t If it is a writeable array, then return TRUE\n\t If we can find an array object\n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable\n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA))\n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly\n\t and unpickled array can be set and reset writeable\n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t\telse ret->flags &= ~WRITEABLE;\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not\n ever be able to walk outside of the memory implied numbytes and offset.\n\n The available memory is assumed to start at -offset and proceed\n to numbytes-offset. The strides are checked to ensure\n that accessing memory using striding will not try to reach beyond\n this memory for any of the axes.\n\n If numbytes is 0 it will be calculated using the dimensions and\n element-size.\n\n This function checks for walking beyond the beginning and right-end\n of the buffer and therefore works for any integer stride (positive\n or negative).\n*/\n\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\tintp byte_begin;\n\tintp begin;\n\tintp end;\n\n\tif (numbytes == 0)\n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\n\tbegin = -offset;\n\tend = numbytes - offset - elsize;\n\tfor (i=0; i end))\n\t\t\treturn FALSE;\n\t}\n\treturn TRUE;\n\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings\n depending on data and strides:\n\n If data is given, then flags is flags associated with data.\n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument\n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set).\n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired.\n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize,\n\t\t int inflag, int *objflags)\n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\n/* and update the dimensions and strides\n appropriately. Dimensions and strides are added\n to the end unless we have a FORTRAN array\n and then they are added to the beginning\n\n Strides are only added if given (because data is given).\n*/\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,\n\t\t\t intp *newstrides, int oldnd, int isfortran)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\tint tuple;\n\n\told = *des;\n\t*des = old->subarray->base;\n\n\n\tmydim = newdims + oldnd;\n\ttuple = PyTuple_Check(old->subarray->shape);\n\tif (tuple) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t}\n\telse {\n\t\tnumnew = 1;\n\t}\n\n\n\tnewnd = oldnd + numnew;\n\tif (newnd > MAX_DIMS) goto finish;\n\tif (isfortran) {\n\t\tmemmove(newdims+numnew, newdims, oldnd*sizeof(intp));\n\t\tmydim = newdims;\n\t}\n\n\tif (tuple) {\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\tif (isfortran) {\n\t\t\tmemmove(newstrides+numnew, newstrides,\n\t\t\t\toldnd*sizeof(intp));\n\t\t\tmystrides = newstrides;\n\t\t}\n\t\t/* Make new strides -- alwasy C-contiguous */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\n finish:\n\tPy_INCREF(*des);\n\tPy_DECREF(old);\n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,\n\t\t intp *dims, intp *strides, void *data,\n\t\t int flags, PyObject *obj)\n{\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tint isfortran=0;\n\t\tisfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || \\\n\t\t\t(!data && flags);\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims,\n\t\t\t\t\t\t newstrides, nd, isfortran);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims,\n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { \n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN;\n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse { /* we allow strides even when we create\n\t\t\t the memory, but be careful with this...\n\t\t */\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays\n\t\t e.g. shape=(0,) -- otherwise buffer exposure\n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in,\n\t\t\t\t\t this object won't own it\n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for\n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype.\n\t If obj is NULL, then call method with Py_None \n\t*/\n\tif ((subtype != &PyArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (strides != NULL) { /* did not allocate own data \n\t\t\t\t\t or funny strides */\n\t\t\t/* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tif (obj == NULL) obj=Py_None;\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n If refcheck is 0, then the reference count is not checked\n and assumed to be 1.\n You still must own this data and have no weak-references and no base\n object.\n*/\nstatic PyObject *\nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\n if (!PyArray_ISONESEGMENT(self)) {\n PyErr_SetString(PyExc_ValueError,\n \"resize only works on single-segment arrays\");\n return NULL;\n }\n\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n\n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (refcheck) refcnt = REFCOUNT(self);\n\t\telse refcnt = 1;\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (newsize == 0) sd = self->descr->elsize;\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n\n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) {\n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0,\n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n\n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n\n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n self->flags, &(self->flags));\n\n\n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\n return Py_None;\n\n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\tPyArray_FillWithScalarFunc* fillwithscalar =\n\t\t\tarr->descr->f->fillwithscalar;\n\t\tif (fillwithscalar && PyArray_ISALIGNED(arr)) {\n\t\t\tcopyswap(fromptr, NULL, swap, itemsize);\n\t\t\tfillwithscalar(toptr, size, fromptr, arr);\n\t\t}\n\t\telse {\n\t\t\twhile (size--) {\n\t\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\t\ttoptr += itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL;\n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous\n\t array of a specific type and shape.\n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims,\n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter,\n &strides,\n &fortran))\n\t\tgoto fail;\n\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"data-type with unspecified variable length\");\n\t\tgoto fail;\n\t}\n\t\n\tif (strides.ptr != NULL) {\n\t\tintp nb, off;\n\t\tif (strides.len != dims.len) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides, if given, must be \"\t\\\n\t\t\t\t\t\"the same length as shape\");\n\t\t\tgoto fail;\n\t\t}\n\n\t\tif (buffer.ptr == NULL) {\n\t\t\tnb = 0;\n\t\t\toff = 0;\n\t\t}\n\t\telse {\n\t\t\tnb = buffer.len;\n\t\t\toff = offset;\n\t\t}\n\t\t\n\n\t\tif (!PyArray_CheckStrides(itemsize, dims.len, \n\t\t\t\t\t nb, off,\n\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides is incompatible \"\t\\\n\t\t\t\t\t\"with shape of requested \"\t\\\n\t\t\t\t\t\"array and size of buffer\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\t\t\t\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len,\n\t\t\t\t\t dims.ptr,\n\t\t\t\t\t strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = (buffer.len-offset) / itemsize;\n }\n else if ((strides.ptr == NULL) && \\\n\t\t\t buffer.len < itemsize*\t\t\t\t\\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError,\n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t offset + (char *)buffer.ptr,\n\t\t\t\t\t buffer.flags, NULL);\n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base);\n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyArray_NewFlagsObject((PyObject *)self);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n\tint nd;\n\tPyObject *ret;\n\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret),\n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret),\n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes=0;\n\tintp offset=0;\n\tint buf_len;\n\tchar *buf;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base && PyArray_Check(new->base)) {\n\t\tnew = (PyArrayObject *)(new->base);\n\t}\n\t/* Get the available memory through the buffer\n\t interface on new->base or if that fails\n\t from the current new */\n\tif (new->base && PyObject_AsReadBuffer(new->base,\n\t\t\t\t\t (const void **)&buf,\n\t\t\t\t\t &buf_len) >= 0) {\n\t\toffset = self->data - buf;\n\t\tnumbytes = buf_len + offset;\n\t}\n\telse {\n\t\tPyErr_Clear();\n \t\tnumbytes = PyArray_MultiplyList(new->dimensions,\n\t\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\toffset = self->data - new->data;\n\t}\n\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes,\n\t\t\t\t offset,\n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self))\n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self)\n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0,\n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf,\n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse\n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse\n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed.\n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the\n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0)\n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n\telse if (newtype->elsize > self->descr->elsize) {\n\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update\n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\t/* We would decref newtype here --- temp will\n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tif (temp == NULL) return -1;\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\tPy_INCREF(temp->descr);\n\t\t/* Fool deallocator not to delete these*/\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype;\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA);\n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num -\n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type,\n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new);\n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int\narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode,\n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr));\n memmove(selfit->dataptr, arrit->dataptr,\n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size)\n PyArray_ITER_RESET(arrit);\n }\n retval = 0;\n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->descr->elsize);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size)\n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\",\n\t (getter)array_ndim_get,\n\t NULL,\n\t \"number of array dimensions\"},\n {\"flags\",\n\t (getter)array_flags_get,\n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\",\n\t (getter)array_shape_get,\n\t (setter)array_shape_set,\n\t \"tuple of array dimensions\"},\n {\"strides\",\n\t (getter)array_strides_get,\n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)array_data_get,\n\t (setter)array_data_set,\n\t \"pointer to start of data\"},\n {\"itemsize\",\n\t (getter)array_itemsize_get,\n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\",\n\t (getter)array_real_get,\n\t (setter)array_real_set,\n\t \"real part of array\"},\n {\"imag\",\n\t (getter)array_imag_get,\n\t (setter)array_imag_set,\n\t \"imaginary part of array\"},\n\t{\"flat\",\n\t (getter)array_flat_get,\n\t (setter)array_flat_set,\n\t \"a 1-d view of a contiguous array\"},\n\t{\"__array_data__\",\n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\",\n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n\t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */\n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] =\n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\nstatic PyTypeObject PyArray_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0,\t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n &array_as_sequence,\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str,\t /*tp_str*/\n\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n &array_as_buffer, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT\n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter,\t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n array_alloc,\t /* tp_alloc */\n (newfunc)array_new,\t\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int\ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple)\n{\n int d=0;\n PyObject *e;\n\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0)\n\t\treturn 1;\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize)\n{\n\tint n, r, i;\n\tPyObject *e;\n\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s)\n\t\t\t*itemsize = MAX(*itemsize, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype ---\n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately\n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE &&\n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\nstatic PyArray_Descr *\n_array_find_python_scalar_type(PyObject *op)\n{\n if (PyFloat_Check(op)) {\n return PyArray_DescrFromType(PyArray_DOUBLE);\n } else if (PyComplex_Check(op)) {\n return PyArray_DescrFromType(PyArray_CDOUBLE);\n } else if (PyInt_Check(op)) {\n /* bools are a subclass of int */\n if (PyBool_Check(op)) {\n return PyArray_DescrFromType(PyArray_BOOL);\n } else {\n return PyArray_DescrFromType(PyArray_LONG);\n }\n } else if (PyLong_Check(op)) {\n /* if integer can fit into a longlong then return that\n */\n if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n PyErr_Clear();\n return PyArray_DescrFromType(PyArray_OBJECT);\n }\n return PyArray_DescrFromType(PyArray_LONGLONG);\n }\n return NULL;\n}\n\n/* op is an object to be converted to an ndarray.\n\n minitype is the minimum type-descriptor needed.\n\n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n\n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\n\tif (minitype == NULL)\n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\n if (max < 0) goto deflt;\n\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n chktype = _array_find_python_scalar_type(op);\n if (chktype) {\n goto finish;\n }\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n\n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind,\n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n }\n\n\tif (PyInstance_Check(op)) goto deflt;\n\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\n finish:\n\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype;\n}\n\nstatic int\nAssign_Array(PyArrayObject *self, PyObject *v)\n{\n PyObject *e;\n int l, r;\n\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\n l=PyObject_Length(v);\n if(l < 0) return -1;\n\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1;\n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */\n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode)\n{\n PyArrayObject *ret;\n\tint itemsize;\n\tint type;\n\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= 4;\n\n\t\tif (itemsize != typecode->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(typecode);\n\t\t\ttypecode->elsize = itemsize;\n\t\t}\n\t}\n\n ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL,\n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\tif (ret == NULL) return NULL;\n\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode */\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string,\n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid input sequence\");\n\t\tgoto fail;\n }\n\n\tif (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {\n\t\tnd = max_depth;\n\t}\n\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid number of dimensions\");\n\t\tgoto fail;\n }\n\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\n if(!r) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int\nPyArray_ValidType(int type)\n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in))\n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, 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\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n oelsize);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject *\nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING)\n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd,\n\t\t\t\t mp->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\n}\n\n/* The number of elements in out must be an integer multiple\n of the number of elements in mp.\n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1;\n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * mpsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr,\n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)\n{\n\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1)\n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse {\n if ((flags & ENSUREARRAY)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype,\n\t\t\t\t\t\t newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr;\n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\n\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong))\n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char))\n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long))\n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap)\n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n\n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL;\n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n\n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data,\n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr));\n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n\n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context)\n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, \n\t\t\t\t\t\t\t\t NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None,\n\t\t\t\t\t\t context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", \n\t\t\t\t\t\t typecode, context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", \n\t\t\t\t\t\t\t typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError,\n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n}\n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,\n int max_depth, int flags, PyObject *context)\n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op))\n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t} else if (newtype == NULL &&\n (newtype = _array_find_python_scalar_type(op))) {\n r = Array_FromScalar(op, newtype);\n }\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, \n\t\t\t\t\t\tflags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\n\t/* Be sure we succeed here */\n\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int\nPyArray_ObjectType(PyObject *op, int minimum_type)\n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of\n CONTIGUOUS,\n FORTRAN,\n ALIGNED,\n WRITEABLE,\n NOTSWAPPED,\n ENSURECOPY,\n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should\n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or\n not it has such features.\n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well.\n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n\n FORTRAN can be set in the FLAGS to request a FORTRAN array.\n Fortran arrays are always behaved (aligned,\n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d).\n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array.\n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe.\n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,\n int max_depth, int requires, PyObject *context)\n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0,\n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place\n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op)) return op;\n\n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int\nPyArray_CanCastSafely(int fromtype, int totype)\n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype))\n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode\n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\n\t\t*/\n\t}\n\treturn ret;\n}\n\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n\n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd;\n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D)\n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic _int_or_ssize_t\niter_length(PyArrayIterObject *self)\n{\n return self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr,\n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1)\n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t 1, &n_steps,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail;\n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0,\n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n\t\t\t\t itemsize);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size)\n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size)\n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)\n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size)\n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0,\n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)iter_length,\t\t /*mp_length*/\n#else\n (inquiry)iter_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op)\n{\n\n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options:\n 1) underlying array is contiguous\n -- return 1-d wrapper around it\n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, it->ao->data,\n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r);\n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n\n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\",\n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &iter_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t\t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular\n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators\n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++)\n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already\n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1)\n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\n\t\t\t\t\t\t\t\"to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of\n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord,\n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t sizeof(intp));\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so,\n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size.\n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere.\n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well.\n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0\n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t/* But, be sure to do it with a true array.\n\t */\n\tif (PyArray_CheckExact(arr)) {\n\t\tsub = array_subscript(arr, mit->indexobj);\n\t}\n\telse {\n\t\tPy_INCREF(arr);\n\t\tobj = PyArray_EnsureArray((PyObject *)arr);\n\t\tif (obj == NULL) goto fail;\n\t\tsub = array_subscript((PyArrayObject *)obj, mit->indexobj);\n\t\tPy_DECREF(obj);\n\t}\n\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects\n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been\n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj))\n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj,\n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1;\n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) *indptr, (int) (dimsize-1),\n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0,\n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n\tmit->index = 0;\n\tmit->ait = NULL;\n\tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY\n#undef SOBJ_ISFANCY\n#undef SOBJ_BADARRAY\n#undef SOBJ_TOOMANY\n#undef SOBJ_LISTTUP\n\n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple\n\t (with at least 1 list or arrayobject or Bool object), */\n\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i,\n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing\n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n\n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work.\n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a);\n mapiter is equivalent to a[indexobj].flat but the latter gets to use\n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t\t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t\t /* tp_iter */\n (iternextfunc)0,\t /* tp_iternext */\n 0,\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\n\tint i, err=0;\n\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\n\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL)\n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i,\n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(multi->iters[i]);\n\t_pya_free(multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\",\n\t (getter)arraymultiter_size_get,\n\t NULL,\n\t \"total size of broadcasted result\"},\n {\"index\",\n\t (getter)arraymultiter_index_get,\n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter),\n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t\t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods,\t /* tp_methods */\n arraymultiter_members,\t\t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types.\n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these\n builtins will be attempted leading to problems.\n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically\n allocated).\n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless\n there is a reference-count problem\n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set.\n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base,\n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0)\n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\",\n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self)\n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\",\n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr)\n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr)\n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv))\n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\n\t/* Now return the state which is at least\n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize\n and alignment for EXTENDED arrays\n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\n\tif (PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are:\n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args)\n{\n\tchar endian=PyArray_SWAP;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS,\n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n\tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\ndescr_length(PyArray_Descr *self)\n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op)\n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError,\n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)descr_length,\t\t /*mp_length*/\n#else\n (inquiry)descr_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t\t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &descr_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t/* tp_iternext */\n arraydescr_methods,\t\t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n\n/** Array Flags Object **/\n\ntypedef struct PyArrayFlagsObject {\n PyObject_HEAD\n PyObject *arr;\n int flags;\n} PyArrayFlagsObject;\n\n/*OBJECT_API\n Get New ArrayFlagsObject\n*/\nstatic PyObject *\nPyArray_NewFlagsObject(PyObject *obj)\n{\n PyObject *flagobj;\n int flags;\n if (obj == NULL) {\n flags = CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n }\n else {\n flags = PyArray_FLAGS(obj);\n }\n flagobj = PyArrayFlags_Type.tp_alloc(&PyArrayFlags_Type, 0);\n if (flagobj == NULL) return NULL;\n Py_XINCREF(obj);\n ((PyArrayFlagsObject *)flagobj)->arr = obj;\n ((PyArrayFlagsObject *)flagobj)->flags = flags;\n\n return flagobj;\n}\n\nstatic void\narrayflags_dealloc(PyArrayFlagsObject *self)\n{\n\tPy_XDECREF(self->arr);\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n\n#define _define_get(UPPER, lower) \\\nstatic PyObject * \\\narrayflags_ ## lower ## _get(PyArrayFlagsObject *self) \\\n{ \\\n PyObject *item; \\\n item = ((self->flags & (UPPER)) == (UPPER)) ? Py_True : Py_False; \\\n Py_INCREF(item); \\\n return item; \\\n}\n\n_define_get(CONTIGUOUS, contiguous)\n_define_get(FORTRAN, fortran)\n_define_get(UPDATEIFCOPY, updateifcopy)\n_define_get(OWNDATA, owndata)\n_define_get(ALIGNED, aligned)\n_define_get(WRITEABLE, writeable)\n\n_define_get(ALIGNED|WRITEABLE, behaved)\n_define_get(ALIGNED|WRITEABLE|CONTIGUOUS, carray)\n\nstatic PyObject *\narrayflags_forc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) ||\n ((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_fnc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_farray_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & (ALIGNED|WRITEABLE|FORTRAN)) == \\\n (ALIGNED|WRITEABLE|FORTRAN)) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_num_get(PyArrayFlagsObject *self)\n{\n return PyInt_FromLong(self->flags);\n}\n\n/* relies on setflags order being write, align, uic */\nstatic int\narrayflags_updateifcopy_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False));\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_aligned_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_writeable_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None, Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\n\nstatic PyGetSetDef arrayflags_getsets[] = {\n\t{\"contiguous\",\n\t (getter)arrayflags_contiguous_get,\n\t NULL,\n\t \"\"},\n {\"fortran\",\n (getter)arrayflags_fortran_get,\n NULL,\n \"\"},\n {\"updateifcopy\",\n (getter)arrayflags_updateifcopy_get,\n (setter)arrayflags_updateifcopy_set,\n \"\"},\n {\"owndata\",\n (getter)arrayflags_owndata_get,\n NULL,\n \"\"},\n {\"aligned\",\n (getter)arrayflags_aligned_get,\n (setter)arrayflags_aligned_set,\n \"\"},\n {\"writeable\",\n (getter)arrayflags_writeable_get,\n (setter)arrayflags_writeable_set,\n \"\"},\n {\"fnc\",\n (getter)arrayflags_fnc_get,\n NULL,\n \"\"},\n {\"forc\",\n (getter)arrayflags_forc_get,\n NULL,\n \"\"},\n {\"behaved\",\n (getter)arrayflags_behaved_get,\n NULL,\n \"\"},\n {\"carray\",\n (getter)arrayflags_carray_get,\n NULL,\n \"\"},\n {\"farray\",\n (getter)arrayflags_farray_get,\n NULL,\n \"\"},\n {\"num\",\n (getter)arrayflags_num_get,\n NULL,\n \"\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyObject *\narrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)\n{\n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n if ((strncmp(key,\"CONTIGUOUS\",n)==0) ||\n (strncmp(key,\"C\",n)))\n return arrayflags_contiguous_get(self);\n else if ((strncmp(key, \"FORTRAN\", n)==0) ||\n (strncmp(key, \"F\", n)==0)) \n return arrayflags_fortran_get(self);\n else if ((strncmp(key, \"WRITEABLE\", n)==0) ||\n (strncmp(key, \"W\", n)==0))\n return arrayflags_writeable_get(self);\n else if ((strncmp(key, \"BEHAVED\", n)==0) ||\n (strncmp(key, \"B\", n)==0))\n return arrayflags_behaved_get(self);\n else if ((strncmp(key, \"OWNDATA\", n)==0) ||\n (strncmp(key, \"O\", n)==0))\n return arrayflags_owndata_get(self);\n else if ((strncmp(key, \"ALIGNED\", n)==0) ||\n (strncmp(key, \"A\", n)==0))\n return arrayflags_aligned_get(self);\n else if ((strncmp(key, \"UPDATEIFCOPY\", n)==0) ||\n (strncmp(key, \"U\", n)==0))\n return arrayflags_updateifcopy_get(self);\n else if ((strncmp(key, \"FNC\", n)==0))\n return arrayflags_fnc_get(self);\n else if ((strncmp(key, \"FORC\", n)==0))\n return arrayflags_forc_get(self);\n else if ((strncmp(key, \"CARRAY\", n)==0) ||\n (strncmp(key, \"CA\", n)==0))\n return arrayflags_carray_get(self);\n else if ((strncmp(key, \"FARRAY\", n)==0) ||\n (strncmp(key, \"FA\", n)==0))\n return arrayflags_farray_get(self);\n else goto fail;\n\n fail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return NULL;\n}\n\nstatic int\narrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)\n{ \n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n if ((strncmp(key, \"WRITEABLE\", n)==0) ||\n (strncmp(key, \"W\", n)==0))\n return arrayflags_writeable_set(self, item);\n else if ((strncmp(key, \"ALIGNED\", n)==0) ||\n (strncmp(key, \"A\", n)==0))\n return arrayflags_aligned_set(self, item);\n else if ((strncmp(key, \"UPDATEIFCOPY\", n)==0) ||\n (strncmp(key, \"U\", n)==0))\n return arrayflags_updateifcopy_set(self, item); \n else goto fail;\n return 0;\n\nfail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return -1;\n}\n\nstatic char *\n_torf_(int flags, int val)\n{\n if ((flags & val) == val) return \"True\";\n else return \"False\"; \n}\n\nstatic PyObject *\narrayflags_print(PyArrayFlagsObject *self)\n{\n int fl = self->flags;\n \n return PyString_FromFormat(\" %s : %s\\n %s : %s\\n %s : %s\\n\"\\\n \" %s : %s\\n %s : %s\\n %s : %s\",\n \"CONTIGUOUS\", _torf_(fl, CONTIGUOUS),\n \"FORTRAN\", _torf_(fl, FORTRAN),\n \"OWNDATA\", _torf_(fl, OWNDATA),\n \"WRITEABLE\", _torf_(fl, WRITEABLE),\n \"ALIGNED\", _torf_(fl, ALIGNED),\n \"UPDATEIFCOPY\", _torf_(fl, UPDATEIFCOPY));\n}\n\n\nstatic PyMappingMethods arrayflags_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)NULL, \t\t /*mp_length*/\n#else\n (inquiry)NULL, \t\t /*mp_length*/\n#endif\n (binaryfunc)arrayflags_getitem,\t /*mp_subscript*/\n (objobjargproc)arrayflags_setitem, /*mp_ass_subscript*/\n};\n\n\nstatic PyObject *\narrayflags_new(PyTypeObject *self, PyObject *args, PyObject *kwds)\n{\n PyObject *arg=NULL;\n if (!PyArg_UnpackTuple(args, \"flagsobj\", 0, 1, &arg))\n return NULL;\n\n if ((arg != NULL) && PyArray_Check(arg)) {\n return PyArray_NewFlagsObject(arg);\n }\n else {\n return PyArray_NewFlagsObject(NULL);\n }\n}\n\nstatic PyTypeObject PyArrayFlags_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\n \"numpy.flagsobj\",\n sizeof(PyArrayFlagsObject),\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayflags_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t0,\t\t /* tp_compare */\n (reprfunc)arrayflags_print, /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &arrayflags_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arrayflags_print, /* tp_str */\n 0,\t \t /* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t /* tp_iternext */\n 0,\t \t /* tp_methods */\n 0,\t /* tp_members */\n arrayflags_getsets, /* tp_getset */\n 0,\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t /* tp_init */\n 0,\t /* tp_alloc */\n arrayflags_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "methods": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 76, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 65, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 99, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 134, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 207, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 241, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 291, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 319, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 344, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 387, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 427, + "end_line": 509, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 516, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 593, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Size", + "long_name": "PyArray_Size( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 33, + "parameters": [ + "op" + ], + "start_line": 614, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 638, + "end_line": 718, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyObject", + "long_name": "PyArray_CopyObject( PyArrayObject * dest , PyObject * src_object)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 722, + "end_line": 736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDimsAndDataAndDescr", + "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 137, + "parameters": [ + "nd", + "d", + "descr", + "data" + ], + "start_line": 749, + "end_line": 775, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDims", + "long_name": "PyArray_FromDims( int nd , int * d , int type)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "nd", + "d", + "type" + ], + "start_line": 781, + "end_line": 795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewCopy", + "long_name": "PyArray_NewCopy( PyArrayObject * m1 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 804, + "end_line": 824, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 17, + "token_count": 616, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 833, + "end_line": 949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 965, + "end_line": 968, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Return", + "long_name": "PyArray_Return( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 91, + "parameters": [ + "mp" + ], + "start_line": 978, + "end_line": 1000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDataType", + "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 9, + "token_count": 229, + "parameters": [ + "type" + ], + "start_line": 1014, + "end_line": 1054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDescrForType", + "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 214, + "parameters": [ + "typenum", + "descr" + ], + "start_line": 1069, + "end_line": 1110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToFile", + "long_name": "PyArray_ToFile( PyArrayObject * self , FILE * fp , char * sep , char * format)", + "filename": "arrayobject.c", + "nloc": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1117, + "end_line": 1208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToList", + "long_name": "PyArray_ToList( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self" + ], + "start_line": 1214, + "end_line": 1243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToString", + "long_name": "PyArray_ToString( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 170, + "parameters": [ + "self" + ], + "start_line": 1246, + "end_line": 1282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_dealloc", + "long_name": "array_dealloc( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 1291, + "end_line": 1328, + "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": 1335, + "end_line": 1343, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_big_item", + "long_name": "array_big_item( PyArrayObject * self , intp i)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 4, + "token_count": 151, + "parameters": [ + "self", + "i" + ], + "start_line": 1346, + "end_line": 1371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , _int_or_ssize_t i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1374, + "end_line": 1377, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_ass_big_item", + "long_name": "array_ass_big_item( PyArrayObject * self , intp i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1380, + "end_line": 1415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , _int_or_ssize_t i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1428, + "end_line": 1431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "slice_coerce_index", + "long_name": "slice_coerce_index( PyObject * o , intp * v)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "o", + "v" + ], + "start_line": 1437, + "end_line": 1445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "slice_GetIndices", + "long_name": "slice_GetIndices( PySliceObject * r , intp length , intp * start , intp * stop , intp * step , intp * slicelength)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 24, + "token_count": 376, + "parameters": [ + "r", + "length", + "start", + "stop", + "step", + "slicelength" + ], + "start_line": 1451, + "end_line": 1501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "parse_subindex", + "long_name": "parse_subindex( PyObject * op , intp * step_size , intp * n_steps , intp max)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "step_size", + "n_steps", + "max" + ], + "start_line": 1508, + "end_line": 1553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "parse_index", + "long_name": "parse_index( PyArrayObject * self , PyObject * op , intp * dimensions , intp * strides , intp * offset_ptr)", + "filename": "arrayobject.c", + "nloc": 88, + "complexity": 20, + "token_count": 539, + "parameters": [ + "self", + "op", + "dimensions", + "strides", + "offset_ptr" + ], + "start_line": 1557, + "end_line": 1651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "_swap_axes", + "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1654, + "end_line": 1691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1703, + "end_line": 1756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetMap", + "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 53, + "complexity": 12, + "token_count": 382, + "parameters": [ + "mit", + "op" + ], + "start_line": 1759, + "end_line": 1819, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 0 + }, + { + "name": "count_new_axes_0d", + "long_name": "count_new_axes_0d( PyObject * tuple)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 7, + "token_count": 124, + "parameters": [ + "tuple" + ], + "start_line": 1822, + "end_line": 1849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "add_new_axes_0d", + "long_name": "add_new_axes_0d( PyArrayObject * arr , int newaxis_count)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 121, + "parameters": [ + "arr", + "newaxis_count" + ], + "start_line": 1852, + "end_line": 1871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 1883, + "end_line": 1945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 107, + "complexity": 28, + "token_count": 674, + "parameters": [ + "self", + "op" + ], + "start_line": 1969, + "end_line": 2094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2109, + "end_line": 2214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 10, + "token_count": 182, + "parameters": [ + "self", + "op" + ], + "start_line": 2223, + "end_line": 2262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , _int_or_ssize_t * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2285, + "end_line": 2297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2300, + "end_line": 2315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2319, + "end_line": 2328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , _int_or_ssize_t segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2331, + "end_line": 2342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 1, + "token_count": 182, + "parameters": [ + "dict" + ], + "start_line": 2420, + "end_line": 2457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 2, + "token_count": 203, + "parameters": [], + "start_line": 2467, + "end_line": 2510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2513, + "end_line": 2536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericAccumulateFunction", + "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2540, + "end_line": 2563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericBinaryFunction", + "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 44, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2567, + "end_line": 2574, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericUnaryFunction", + "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 38, + "parameters": [ + "m1", + "op" + ], + "start_line": 2577, + "end_line": 2584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceBinaryFunction", + "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 46, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2587, + "end_line": 2595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceUnaryFunction", + "long_name": "PyArray_GenericInplaceUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 40, + "parameters": [ + "m1", + "op" + ], + "start_line": 2598, + "end_line": 2605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2608, + "end_line": 2611, + "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": 2614, + "end_line": 2617, + "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": 2620, + "end_line": 2623, + "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": 2626, + "end_line": 2629, + "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": 2632, + "end_line": 2635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power_is_scalar", + "long_name": "array_power_is_scalar( PyObject * o2 , double * exp)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 132, + "parameters": [ + "o2", + "exp" + ], + "start_line": 2642, + "end_line": 2665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "fast_scalar_power", + "long_name": "fast_scalar_power( PyArrayObject * a1 , PyObject * o2 , int inplace)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 12, + "token_count": 181, + "parameters": [ + "a1", + "o2", + "inplace" + ], + "start_line": 2669, + "end_line": 2703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2706, + "end_line": 2715, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2719, + "end_line": 2722, + "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": 2725, + "end_line": 2728, + "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": 2731, + "end_line": 2734, + "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": 2737, + "end_line": 2740, + "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": 2743, + "end_line": 2746, + "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": 2749, + "end_line": 2752, + "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": 2755, + "end_line": 2758, + "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": 2761, + "end_line": 2764, + "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": 2767, + "end_line": 2770, + "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": 2773, + "end_line": 2776, + "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": 2779, + "end_line": 2782, + "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": 2785, + "end_line": 2788, + "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": 2791, + "end_line": 2794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2797, + "end_line": 2806, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2809, + "end_line": 2812, + "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": 2815, + "end_line": 2818, + "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": 2821, + "end_line": 2824, + "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": 2827, + "end_line": 2830, + "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": 2833, + "end_line": 2836, + "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": 2839, + "end_line": 2842, + "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": 2845, + "end_line": 2848, + "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": 2851, + "end_line": 2855, + "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": 2858, + "end_line": 2862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_any_nonzero", + "long_name": "array_any_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 95, + "parameters": [ + "mp" + ], + "start_line": 2866, + "end_line": 2884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_array_nonzero", + "long_name": "_array_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 3, + "token_count": 72, + "parameters": [ + "mp" + ], + "start_line": 2887, + "end_line": 2904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_divmod", + "long_name": "array_divmod( PyArrayObject * op1 , PyObject * op2)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 89, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2909, + "end_line": 2924, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_int", + "long_name": "array_int( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2928, + "end_line": 2954, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_float", + "long_name": "array_float( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2957, + "end_line": 2982, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_long", + "long_name": "array_long( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 2985, + "end_line": 3007, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_oct", + "long_name": "array_oct( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3010, + "end_line": 3032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_hex", + "long_name": "array_hex( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3035, + "end_line": 3057, + "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": 3060, + "end_line": 3064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 12, + "token_count": 268, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 3125, + "end_line": 3166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 3170, + "end_line": 3192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 3195, + "end_line": 3207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dump_data", + "long_name": "dump_data( char ** string , int * n , int * max_n , char * data , int nd , intp * dimensions , intp * strides , PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 7, + "token_count": 310, + "parameters": [ + "string", + "n", + "max_n", + "data", + "nd", + "dimensions", + "strides", + "self" + ], + "start_line": 3240, + "end_line": 3287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_repr_builtin", + "long_name": "array_repr_builtin( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 4, + "token_count": 224, + "parameters": [ + "self" + ], + "start_line": 3290, + "end_line": 3326, + "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": 3335, + "end_line": 3352, + "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": 3355, + "end_line": 3367, + "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": 3370, + "end_line": 3382, + "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": 90, + "complexity": 19, + "token_count": 392, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3385, + "end_line": 3491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 171, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3494, + "end_line": 3523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntTupleFromIntp", + "long_name": "PyArray_IntTupleFromIntp( int len , intp * vals)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 109, + "parameters": [ + "len", + "vals" + ], + "start_line": 3529, + "end_line": 3549, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3557, + "end_line": 3592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3598, + "end_line": 3617, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 3621, + "end_line": 3639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 3642, + "end_line": 3659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_IsWriteable", + "long_name": "_IsWriteable( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 107, + "parameters": [ + "ap" + ], + "start_line": 3662, + "end_line": 3695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_UpdateFlags", + "long_name": "PyArray_UpdateFlags( PyArrayObject * ret , int flagmask)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 11, + "token_count": 157, + "parameters": [ + "ret", + "flagmask" + ], + "start_line": 3702, + "end_line": 3729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 117, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 3749, + "end_line": 3769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 3789, + "end_line": 3813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_New", + "long_name": "PyArray_New( PyTypeObject * subtype , int nd , intp * dims , int type_num , intp * strides , * data , int itemsize , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 4, + "token_count": 128, + "parameters": [ + "subtype", + "nd", + "dims", + "type_num", + "strides", + "data", + "itemsize", + "flags", + "obj" + ], + "start_line": 3819, + "end_line": 3841, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd , int isfortran)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 10, + "token_count": 311, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd", + "isfortran" + ], + "start_line": 3852, + "end_line": 3914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 132, + "complexity": 29, + "token_count": 785, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3922, + "end_line": 4088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 167, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape , int refcheck)", + "filename": "arrayobject.c", + "nloc": 83, + "complexity": 16, + "token_count": 511, + "parameters": [ + "self", + "newshape", + "refcheck" + ], + "start_line": 4101, + "end_line": 4200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 100, + "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": 4206, + "end_line": 4223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 8, + "token_count": 279, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4227, + "end_line": 4277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 21, + "token_count": 620, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4280, + "end_line": 4411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 132, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4415, + "end_line": 4423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ndim_get", + "long_name": "array_ndim_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4429, + "end_line": 4432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flags_get", + "long_name": "array_flags_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 4435, + "end_line": 4438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_get", + "long_name": "array_shape_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4441, + "end_line": 4444, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_set", + "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4448, + "end_line": 4477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "array_strides_get", + "long_name": "array_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4481, + "end_line": 4484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 9, + "token_count": 304, + "parameters": [ + "self", + "obj" + ], + "start_line": 4487, + "end_line": 4541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4545, + "end_line": 4552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4555, + "end_line": 4561, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4565, + "end_line": 4571, + "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": 4574, + "end_line": 4588, + "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": 4591, + "end_line": 4635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_itemsize_get", + "long_name": "array_itemsize_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 4639, + "end_line": 4642, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_size_get", + "long_name": "array_size_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4645, + "end_line": 4656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nbytes_get", + "long_name": "array_nbytes_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4659, + "end_line": 4670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4676, + "end_line": 4679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_descr_get", + "long_name": "array_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 4682, + "end_line": 4686, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "arg" + ], + "start_line": 4700, + "end_line": 4787, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 4790, + "end_line": 4808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_struct_get", + "long_name": "array_struct_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 2, + "token_count": 130, + "parameters": [ + "self" + ], + "start_line": 4811, + "end_line": 4829, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 4832, + "end_line": 4842, + "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": 4846, + "end_line": 4871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_real_set", + "long_name": "array_real_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 4, + "token_count": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 4875, + "end_line": 4908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_get", + "long_name": "array_imag_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self" + ], + "start_line": 4911, + "end_line": 4944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 4947, + "end_line": 4984, + "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": 4987, + "end_line": 4990, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flat_set", + "long_name": "array_flat_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 9, + "token_count": 348, + "parameters": [ + "self", + "val" + ], + "start_line": 4993, + "end_line": 5043, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_alloc", + "long_name": "array_alloc( PyTypeObject * type , int nitems)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 1, + "token_count": 39, + "parameters": [ + "type", + "nitems" + ], + "start_line": 5133, + "end_line": 5140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "discover_depth", + "long_name": "discover_depth( PyObject * s , int max , int stop_at_string , int stop_at_tuple)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 19, + "token_count": 243, + "parameters": [ + "s", + "max", + "stop_at_string", + "stop_at_tuple" + ], + "start_line": 5228, + "end_line": 5261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5264, + "end_line": 5286, + "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": 5293, + "end_line": 5319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_array_small_type", + "long_name": "_array_small_type( PyArray_Descr * chktype , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 169, + "parameters": [ + "chktype", + "mintype" + ], + "start_line": 5325, + "end_line": 5357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_python_scalar_type", + "long_name": "_array_find_python_scalar_type( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 8, + "token_count": 120, + "parameters": [ + "op" + ], + "start_line": 5360, + "end_line": 5383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 28, + "token_count": 634, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5395, + "end_line": 5525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "Assign_Array", + "long_name": "Assign_Array( PyArrayObject * self , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 121, + "parameters": [ + "self", + "v" + ], + "start_line": 5528, + "end_line": 5551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 189, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5556, + "end_line": 5594, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 24, + "token_count": 373, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5599, + "end_line": 5666, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 68, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 5673, + "end_line": 5682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_bufferedcast", + "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 18, + "token_count": 525, + "parameters": [ + "out", + "in" + ], + "start_line": 5688, + "end_line": 5781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5791, + "end_line": 5837, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastTo", + "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 241, + "parameters": [ + "out", + "mp" + ], + "start_line": 5847, + "end_line": 5900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 31, + "token_count": 658, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5905, + "end_line": 6031, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 501, + "parameters": [ + "str" + ], + "start_line": 6035, + "end_line": 6143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 6147, + "end_line": 6187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 6191, + "end_line": 6329, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6333, + "end_line": 6376, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 21, + "token_count": 410, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6382, + "end_line": 6466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6471, + "end_line": 6474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ObjectType", + "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 69, + "parameters": [ + "op", + "minimum_type" + ], + "start_line": 6481, + "end_line": 6494, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6540, + "end_line": 6556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 84, + "parameters": [ + "op" + ], + "start_line": 6569, + "end_line": 6585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastSafely", + "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 39, + "token_count": 444, + "parameters": [ + "fromtype", + "totype" + ], + "start_line": 6591, + "end_line": 6679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 6684, + "end_line": 6712, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterNew", + "long_name": "PyArray_IterNew( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 269, + "parameters": [ + "obj" + ], + "start_line": 6725, + "end_line": 6763, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterAllButAxis", + "long_name": "PyArray_IterAllButAxis( PyObject * obj , int axis)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 88, + "parameters": [ + "obj", + "axis" + ], + "start_line": 6771, + "end_line": 6788, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_next", + "long_name": "arrayiter_next( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 48, + "parameters": [ + "it" + ], + "start_line": 6793, + "end_line": 6803, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_dealloc", + "long_name": "arrayiter_dealloc( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "it" + ], + "start_line": 6806, + "end_line": 6810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 6813, + "end_line": 6816, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_Bool", + "long_name": "iter_subscript_Bool( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 7, + "token_count": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6820, + "end_line": 6870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_int", + "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 52, + "complexity": 8, + "token_count": 352, + "parameters": [ + "self", + "ind" + ], + "start_line": 6873, + "end_line": 6927, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 6931, + "end_line": 7064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 134, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_Bool", + "long_name": "iter_ass_sub_Bool( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7068, + "end_line": 7100, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_int", + "long_name": "iter_ass_sub_int( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 8, + "token_count": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7103, + "end_line": 7145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 7148, + "end_line": 7282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "iter_array", + "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 214, + "parameters": [ + "it", + "op" + ], + "start_line": 7299, + "end_line": 7344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "iter_copy", + "long_name": "iter_copy( PyArrayIterObject * it , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "it", + "args" + ], + "start_line": 7349, + "end_line": 7353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7369, + "end_line": 7384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7449, + "end_line": 7465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Broadcast", + "long_name": "PyArray_Broadcast( PyArrayMultiIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 13, + "token_count": 464, + "parameters": [ + "mit" + ], + "start_line": 7472, + "end_line": 7541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterReset", + "long_name": "PyArray_MapIterReset( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7545, + "end_line": 7582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7588, + "end_line": 7632, + "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": 107, + "complexity": 23, + "token_count": 715, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7650, + "end_line": 7789, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 140, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7795, + "end_line": 7867, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 7870, + "end_line": 7996, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 8000, + "end_line": 8009, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiIterNew", + "long_name": "PyArray_MultiIterNew( int n , ...)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 10, + "token_count": 231, + "parameters": [ + "n" + ], + "start_line": 8080, + "end_line": 8129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_new", + "long_name": "arraymultiter_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 11, + "token_count": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8132, + "end_line": 8177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_next", + "long_name": "arraymultiter_next( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 111, + "parameters": [ + "multi" + ], + "start_line": 8180, + "end_line": 8199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_dealloc", + "long_name": "arraymultiter_dealloc( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 41, + "parameters": [ + "multi" + ], + "start_line": 8202, + "end_line": 8209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_size_get", + "long_name": "arraymultiter_size_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8212, + "end_line": 8222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_index_get", + "long_name": "arraymultiter_index_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8225, + "end_line": 8235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_shape_get", + "long_name": "arraymultiter_shape_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 8238, + "end_line": 8241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_iters_get", + "long_name": "arraymultiter_iters_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 8244, + "end_line": 8256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_reset", + "long_name": "arraymultiter_reset( PyArrayMultiIterObject * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 38, + "parameters": [ + "self", + "args" + ], + "start_line": 8286, + "end_line": 8293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewFromType", + "long_name": "PyArray_DescrNewFromType( int type_num)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 1, + "token_count": 37, + "parameters": [ + "type_num" + ], + "start_line": 8352, + "end_line": 8361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNew", + "long_name": "PyArray_DescrNew( PyArray_Descr * base)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 151, + "parameters": [ + "base" + ], + "start_line": 8379, + "end_line": 8401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_dealloc", + "long_name": "arraydescr_dealloc( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 8407, + "end_line": 8417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_subdescr_get", + "long_name": "arraydescr_subdescr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 8436, + "end_line": 8444, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8447, + "end_line": 8462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8465, + "end_line": 8487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8490, + "end_line": 8498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8501, + "end_line": 8508, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 8511, + "end_line": 8530, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isbuiltin_get", + "long_name": "arraydescr_isbuiltin_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 8537, + "end_line": 8544, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isnative_get", + "long_name": "arraydescr_isnative_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 8547, + "end_line": 8554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_fields_get", + "long_name": "arraydescr_fields_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 8557, + "end_line": 8564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_new", + "long_name": "arraydescr_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 272, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8612, + "end_line": 8664, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 8670, + "end_line": 8731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8739, + "end_line": 8781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewByteorder", + "long_name": "PyArray_DescrNewByteorder( PyArray_Descr * self , char newendian)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 386, + "parameters": [ + "self", + "newendian" + ], + "start_line": 8801, + "end_line": 8867, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_newbyteorder", + "long_name": "arraydescr_newbyteorder( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 47, + "parameters": [ + "self", + "args" + ], + "start_line": 8878, + "end_line": 8886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_str", + "long_name": "arraydescr_str( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 6, + "token_count": 287, + "parameters": [ + "self" + ], + "start_line": 8901, + "end_line": 8946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_repr", + "long_name": "arraydescr_repr( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 8949, + "end_line": 8958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_compare", + "long_name": "arraydescr_compare( PyArray_Descr * self , PyObject * other)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "other" + ], + "start_line": 8961, + "end_line": 8971, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 8978, + "end_line": 8985, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 8988, + "end_line": 9019, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFlagsObject", + "long_name": "PyArray_NewFlagsObject( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 3, + "token_count": 96, + "parameters": [ + "obj" + ], + "start_line": 9097, + "end_line": 9114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_dealloc", + "long_name": "arrayflags_dealloc( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 9117, + "end_line": 9121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_forc_get", + "long_name": "arrayflags_forc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 9145, + "end_line": 9157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_fnc_get", + "long_name": "arrayflags_fnc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9160, + "end_line": 9172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_farray_get", + "long_name": "arrayflags_farray_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 9175, + "end_line": 9188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_num_get", + "long_name": "arrayflags_num_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 9191, + "end_line": 9194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_updateifcopy_set", + "long_name": "arrayflags_updateifcopy_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9198, + "end_line": 9210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_aligned_set", + "long_name": "arrayflags_aligned_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9213, + "end_line": 9226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_writeable_set", + "long_name": "arrayflags_writeable_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9229, + "end_line": 9242, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_getitem", + "long_name": "arrayflags_getitem( PyArrayFlagsObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 75, + "complexity": 31, + "token_count": 431, + "parameters": [ + "self", + "ind" + ], + "start_line": 9298, + "end_line": 9373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_setitem", + "long_name": "arrayflags_setitem( PyArrayFlagsObject * self , PyObject * ind , PyObject * item)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 14, + "token_count": 219, + "parameters": [ + "self", + "ind", + "item" + ], + "start_line": 9376, + "end_line": 9396, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_torf_", + "long_name": "_torf_( int flags , int val)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 27, + "parameters": [ + "flags", + "val" + ], + "start_line": 9399, + "end_line": 9403, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_print", + "long_name": "arrayflags_print( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 1, + "token_count": 77, + "parameters": [ + "self" + ], + "start_line": 9406, + "end_line": 9418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_new", + "long_name": "arrayflags_new( PyTypeObject * self , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9433, + "end_line": 9445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 76, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 65, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 99, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 134, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 207, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 241, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 291, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 319, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 344, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 387, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 427, + "end_line": 509, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 516, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 593, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Size", + "long_name": "PyArray_Size( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 33, + "parameters": [ + "op" + ], + "start_line": 614, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 638, + "end_line": 718, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyObject", + "long_name": "PyArray_CopyObject( PyArrayObject * dest , PyObject * src_object)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 722, + "end_line": 736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDimsAndDataAndDescr", + "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 137, + "parameters": [ + "nd", + "d", + "descr", + "data" + ], + "start_line": 749, + "end_line": 775, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDims", + "long_name": "PyArray_FromDims( int nd , int * d , int type)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "nd", + "d", + "type" + ], + "start_line": 781, + "end_line": 795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewCopy", + "long_name": "PyArray_NewCopy( PyArrayObject * m1 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 804, + "end_line": 824, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 17, + "token_count": 616, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 833, + "end_line": 949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 965, + "end_line": 968, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Return", + "long_name": "PyArray_Return( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 91, + "parameters": [ + "mp" + ], + "start_line": 978, + "end_line": 1000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDataType", + "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 9, + "token_count": 229, + "parameters": [ + "type" + ], + "start_line": 1014, + "end_line": 1054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDescrForType", + "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 214, + "parameters": [ + "typenum", + "descr" + ], + "start_line": 1069, + "end_line": 1110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToFile", + "long_name": "PyArray_ToFile( PyArrayObject * self , FILE * fp , char * sep , char * format)", + "filename": "arrayobject.c", + "nloc": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1117, + "end_line": 1208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToList", + "long_name": "PyArray_ToList( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self" + ], + "start_line": 1214, + "end_line": 1243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToString", + "long_name": "PyArray_ToString( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 170, + "parameters": [ + "self" + ], + "start_line": 1246, + "end_line": 1282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_dealloc", + "long_name": "array_dealloc( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 1291, + "end_line": 1328, + "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": 1335, + "end_line": 1343, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_big_item", + "long_name": "array_big_item( PyArrayObject * self , intp i)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 4, + "token_count": 151, + "parameters": [ + "self", + "i" + ], + "start_line": 1346, + "end_line": 1371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , _int_or_ssize_t i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1374, + "end_line": 1377, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_ass_big_item", + "long_name": "array_ass_big_item( PyArrayObject * self , intp i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1380, + "end_line": 1415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , _int_or_ssize_t i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1428, + "end_line": 1431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "slice_coerce_index", + "long_name": "slice_coerce_index( PyObject * o , intp * v)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "o", + "v" + ], + "start_line": 1437, + "end_line": 1445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "slice_GetIndices", + "long_name": "slice_GetIndices( PySliceObject * r , intp length , intp * start , intp * stop , intp * step , intp * slicelength)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 24, + "token_count": 376, + "parameters": [ + "r", + "length", + "start", + "stop", + "step", + "slicelength" + ], + "start_line": 1451, + "end_line": 1501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "parse_subindex", + "long_name": "parse_subindex( PyObject * op , intp * step_size , intp * n_steps , intp max)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "step_size", + "n_steps", + "max" + ], + "start_line": 1508, + "end_line": 1553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "parse_index", + "long_name": "parse_index( PyArrayObject * self , PyObject * op , intp * dimensions , intp * strides , intp * offset_ptr)", + "filename": "arrayobject.c", + "nloc": 88, + "complexity": 20, + "token_count": 539, + "parameters": [ + "self", + "op", + "dimensions", + "strides", + "offset_ptr" + ], + "start_line": 1557, + "end_line": 1651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "_swap_axes", + "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1654, + "end_line": 1691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1703, + "end_line": 1756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetMap", + "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 53, + "complexity": 12, + "token_count": 382, + "parameters": [ + "mit", + "op" + ], + "start_line": 1759, + "end_line": 1819, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 0 + }, + { + "name": "count_new_axes_0d", + "long_name": "count_new_axes_0d( PyObject * tuple)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 7, + "token_count": 124, + "parameters": [ + "tuple" + ], + "start_line": 1822, + "end_line": 1849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "add_new_axes_0d", + "long_name": "add_new_axes_0d( PyArrayObject * arr , int newaxis_count)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 121, + "parameters": [ + "arr", + "newaxis_count" + ], + "start_line": 1852, + "end_line": 1871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 1883, + "end_line": 1945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 107, + "complexity": 28, + "token_count": 674, + "parameters": [ + "self", + "op" + ], + "start_line": 1969, + "end_line": 2094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2109, + "end_line": 2214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 10, + "token_count": 182, + "parameters": [ + "self", + "op" + ], + "start_line": 2223, + "end_line": 2262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , _int_or_ssize_t * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2285, + "end_line": 2297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2300, + "end_line": 2315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2319, + "end_line": 2328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , _int_or_ssize_t segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2331, + "end_line": 2342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 1, + "token_count": 182, + "parameters": [ + "dict" + ], + "start_line": 2420, + "end_line": 2457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 2, + "token_count": 203, + "parameters": [], + "start_line": 2467, + "end_line": 2510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2513, + "end_line": 2536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericAccumulateFunction", + "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2540, + "end_line": 2563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericBinaryFunction", + "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 44, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2567, + "end_line": 2574, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericUnaryFunction", + "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 38, + "parameters": [ + "m1", + "op" + ], + "start_line": 2577, + "end_line": 2584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceBinaryFunction", + "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 46, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2587, + "end_line": 2595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceUnaryFunction", + "long_name": "PyArray_GenericInplaceUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 40, + "parameters": [ + "m1", + "op" + ], + "start_line": 2598, + "end_line": 2605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2608, + "end_line": 2611, + "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": 2614, + "end_line": 2617, + "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": 2620, + "end_line": 2623, + "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": 2626, + "end_line": 2629, + "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": 2632, + "end_line": 2635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power_is_scalar", + "long_name": "array_power_is_scalar( PyObject * o2 , double * exp)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 132, + "parameters": [ + "o2", + "exp" + ], + "start_line": 2642, + "end_line": 2665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "fast_scalar_power", + "long_name": "fast_scalar_power( PyArrayObject * a1 , PyObject * o2 , int inplace)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 12, + "token_count": 181, + "parameters": [ + "a1", + "o2", + "inplace" + ], + "start_line": 2669, + "end_line": 2703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2706, + "end_line": 2715, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2719, + "end_line": 2722, + "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": 2725, + "end_line": 2728, + "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": 2731, + "end_line": 2734, + "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": 2737, + "end_line": 2740, + "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": 2743, + "end_line": 2746, + "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": 2749, + "end_line": 2752, + "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": 2755, + "end_line": 2758, + "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": 2761, + "end_line": 2764, + "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": 2767, + "end_line": 2770, + "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": 2773, + "end_line": 2776, + "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": 2779, + "end_line": 2782, + "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": 2785, + "end_line": 2788, + "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": 2791, + "end_line": 2794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2797, + "end_line": 2806, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2809, + "end_line": 2812, + "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": 2815, + "end_line": 2818, + "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": 2821, + "end_line": 2824, + "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": 2827, + "end_line": 2830, + "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": 2833, + "end_line": 2836, + "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": 2839, + "end_line": 2842, + "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": 2845, + "end_line": 2848, + "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": 2851, + "end_line": 2855, + "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": 2858, + "end_line": 2862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_any_nonzero", + "long_name": "array_any_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 95, + "parameters": [ + "mp" + ], + "start_line": 2866, + "end_line": 2884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_array_nonzero", + "long_name": "_array_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 3, + "token_count": 72, + "parameters": [ + "mp" + ], + "start_line": 2887, + "end_line": 2904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_divmod", + "long_name": "array_divmod( PyArrayObject * op1 , PyObject * op2)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 89, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2909, + "end_line": 2924, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_int", + "long_name": "array_int( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2928, + "end_line": 2954, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_float", + "long_name": "array_float( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2957, + "end_line": 2982, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_long", + "long_name": "array_long( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 2985, + "end_line": 3007, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_oct", + "long_name": "array_oct( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3010, + "end_line": 3032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_hex", + "long_name": "array_hex( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3035, + "end_line": 3057, + "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": 3060, + "end_line": 3064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 12, + "token_count": 268, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 3125, + "end_line": 3166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 3170, + "end_line": 3192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 3195, + "end_line": 3207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dump_data", + "long_name": "dump_data( char ** string , int * n , int * max_n , char * data , int nd , intp * dimensions , intp * strides , PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 7, + "token_count": 310, + "parameters": [ + "string", + "n", + "max_n", + "data", + "nd", + "dimensions", + "strides", + "self" + ], + "start_line": 3240, + "end_line": 3287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_repr_builtin", + "long_name": "array_repr_builtin( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 4, + "token_count": 224, + "parameters": [ + "self" + ], + "start_line": 3290, + "end_line": 3326, + "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": 3335, + "end_line": 3352, + "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": 3355, + "end_line": 3367, + "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": 3370, + "end_line": 3382, + "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": 90, + "complexity": 19, + "token_count": 392, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3385, + "end_line": 3491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 171, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3494, + "end_line": 3523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntTupleFromIntp", + "long_name": "PyArray_IntTupleFromIntp( int len , intp * vals)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 109, + "parameters": [ + "len", + "vals" + ], + "start_line": 3529, + "end_line": 3549, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3557, + "end_line": 3592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3598, + "end_line": 3617, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 3621, + "end_line": 3639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 3642, + "end_line": 3659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_IsWriteable", + "long_name": "_IsWriteable( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 107, + "parameters": [ + "ap" + ], + "start_line": 3662, + "end_line": 3695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_UpdateFlags", + "long_name": "PyArray_UpdateFlags( PyArrayObject * ret , int flagmask)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 11, + "token_count": 157, + "parameters": [ + "ret", + "flagmask" + ], + "start_line": 3702, + "end_line": 3729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 117, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 3749, + "end_line": 3769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 3789, + "end_line": 3813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_New", + "long_name": "PyArray_New( PyTypeObject * subtype , int nd , intp * dims , int type_num , intp * strides , * data , int itemsize , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 4, + "token_count": 128, + "parameters": [ + "subtype", + "nd", + "dims", + "type_num", + "strides", + "data", + "itemsize", + "flags", + "obj" + ], + "start_line": 3819, + "end_line": 3841, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd , int isfortran)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 10, + "token_count": 311, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd", + "isfortran" + ], + "start_line": 3852, + "end_line": 3914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 132, + "complexity": 29, + "token_count": 785, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3922, + "end_line": 4088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 167, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape , int refcheck)", + "filename": "arrayobject.c", + "nloc": 83, + "complexity": 16, + "token_count": 511, + "parameters": [ + "self", + "newshape", + "refcheck" + ], + "start_line": 4101, + "end_line": 4200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 100, + "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": 4206, + "end_line": 4223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 8, + "token_count": 279, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4227, + "end_line": 4277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 21, + "token_count": 620, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4280, + "end_line": 4411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 132, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4415, + "end_line": 4423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ndim_get", + "long_name": "array_ndim_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4429, + "end_line": 4432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flags_get", + "long_name": "array_flags_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 4435, + "end_line": 4438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_get", + "long_name": "array_shape_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4441, + "end_line": 4444, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_set", + "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4448, + "end_line": 4477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "array_strides_get", + "long_name": "array_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4481, + "end_line": 4484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 9, + "token_count": 304, + "parameters": [ + "self", + "obj" + ], + "start_line": 4487, + "end_line": 4541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4545, + "end_line": 4552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4555, + "end_line": 4561, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4565, + "end_line": 4571, + "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": 4574, + "end_line": 4588, + "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": 4591, + "end_line": 4635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_itemsize_get", + "long_name": "array_itemsize_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 4639, + "end_line": 4642, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_size_get", + "long_name": "array_size_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4645, + "end_line": 4656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nbytes_get", + "long_name": "array_nbytes_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4659, + "end_line": 4670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4676, + "end_line": 4679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_descr_get", + "long_name": "array_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 4682, + "end_line": 4686, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "arg" + ], + "start_line": 4700, + "end_line": 4787, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 4790, + "end_line": 4808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_struct_get", + "long_name": "array_struct_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 2, + "token_count": 130, + "parameters": [ + "self" + ], + "start_line": 4811, + "end_line": 4829, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 4832, + "end_line": 4842, + "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": 4846, + "end_line": 4871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_real_set", + "long_name": "array_real_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 4, + "token_count": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 4875, + "end_line": 4908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_get", + "long_name": "array_imag_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self" + ], + "start_line": 4911, + "end_line": 4944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 4947, + "end_line": 4984, + "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": 4987, + "end_line": 4990, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flat_set", + "long_name": "array_flat_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 9, + "token_count": 348, + "parameters": [ + "self", + "val" + ], + "start_line": 4993, + "end_line": 5043, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_alloc", + "long_name": "array_alloc( PyTypeObject * type , int nitems)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 1, + "token_count": 39, + "parameters": [ + "type", + "nitems" + ], + "start_line": 5133, + "end_line": 5140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "discover_depth", + "long_name": "discover_depth( PyObject * s , int max , int stop_at_string , int stop_at_tuple)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 19, + "token_count": 243, + "parameters": [ + "s", + "max", + "stop_at_string", + "stop_at_tuple" + ], + "start_line": 5228, + "end_line": 5261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5264, + "end_line": 5286, + "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": 5293, + "end_line": 5319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_array_small_type", + "long_name": "_array_small_type( PyArray_Descr * chktype , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 169, + "parameters": [ + "chktype", + "mintype" + ], + "start_line": 5325, + "end_line": 5357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_python_scalar_type", + "long_name": "_array_find_python_scalar_type( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 8, + "token_count": 120, + "parameters": [ + "op" + ], + "start_line": 5360, + "end_line": 5383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 28, + "token_count": 634, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5395, + "end_line": 5525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "Assign_Array", + "long_name": "Assign_Array( PyArrayObject * self , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 121, + "parameters": [ + "self", + "v" + ], + "start_line": 5528, + "end_line": 5551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 189, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5556, + "end_line": 5594, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 24, + "token_count": 373, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5599, + "end_line": 5666, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 68, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 5673, + "end_line": 5682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_bufferedcast", + "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 18, + "token_count": 525, + "parameters": [ + "out", + "in" + ], + "start_line": 5688, + "end_line": 5781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5791, + "end_line": 5837, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastTo", + "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 241, + "parameters": [ + "out", + "mp" + ], + "start_line": 5847, + "end_line": 5900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 31, + "token_count": 658, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5905, + "end_line": 6031, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 501, + "parameters": [ + "str" + ], + "start_line": 6035, + "end_line": 6143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 6147, + "end_line": 6187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 6191, + "end_line": 6329, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6333, + "end_line": 6376, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 21, + "token_count": 410, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6382, + "end_line": 6466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6471, + "end_line": 6474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ObjectType", + "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 69, + "parameters": [ + "op", + "minimum_type" + ], + "start_line": 6481, + "end_line": 6494, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6540, + "end_line": 6556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 84, + "parameters": [ + "op" + ], + "start_line": 6569, + "end_line": 6585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastSafely", + "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 39, + "token_count": 444, + "parameters": [ + "fromtype", + "totype" + ], + "start_line": 6591, + "end_line": 6679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 6684, + "end_line": 6712, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterNew", + "long_name": "PyArray_IterNew( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 269, + "parameters": [ + "obj" + ], + "start_line": 6725, + "end_line": 6763, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterAllButAxis", + "long_name": "PyArray_IterAllButAxis( PyObject * obj , int axis)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 88, + "parameters": [ + "obj", + "axis" + ], + "start_line": 6771, + "end_line": 6788, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_next", + "long_name": "arrayiter_next( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 48, + "parameters": [ + "it" + ], + "start_line": 6793, + "end_line": 6803, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_dealloc", + "long_name": "arrayiter_dealloc( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "it" + ], + "start_line": 6806, + "end_line": 6810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 6813, + "end_line": 6816, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_Bool", + "long_name": "iter_subscript_Bool( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 7, + "token_count": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6820, + "end_line": 6870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_int", + "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 52, + "complexity": 8, + "token_count": 352, + "parameters": [ + "self", + "ind" + ], + "start_line": 6873, + "end_line": 6927, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 6931, + "end_line": 7064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 134, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_Bool", + "long_name": "iter_ass_sub_Bool( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7068, + "end_line": 7100, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_int", + "long_name": "iter_ass_sub_int( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 8, + "token_count": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7103, + "end_line": 7145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 7148, + "end_line": 7282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "iter_array", + "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 214, + "parameters": [ + "it", + "op" + ], + "start_line": 7299, + "end_line": 7344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "iter_copy", + "long_name": "iter_copy( PyArrayIterObject * it , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "it", + "args" + ], + "start_line": 7349, + "end_line": 7353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7369, + "end_line": 7384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7449, + "end_line": 7465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Broadcast", + "long_name": "PyArray_Broadcast( PyArrayMultiIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 13, + "token_count": 464, + "parameters": [ + "mit" + ], + "start_line": 7472, + "end_line": 7541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterReset", + "long_name": "PyArray_MapIterReset( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7545, + "end_line": 7582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7588, + "end_line": 7632, + "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": 107, + "complexity": 23, + "token_count": 715, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7650, + "end_line": 7789, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 140, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7795, + "end_line": 7867, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 7870, + "end_line": 7996, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 8000, + "end_line": 8009, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiIterNew", + "long_name": "PyArray_MultiIterNew( int n , ...)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 10, + "token_count": 231, + "parameters": [ + "n" + ], + "start_line": 8080, + "end_line": 8129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_new", + "long_name": "arraymultiter_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 11, + "token_count": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8132, + "end_line": 8177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_next", + "long_name": "arraymultiter_next( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 111, + "parameters": [ + "multi" + ], + "start_line": 8180, + "end_line": 8199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_dealloc", + "long_name": "arraymultiter_dealloc( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 41, + "parameters": [ + "multi" + ], + "start_line": 8202, + "end_line": 8209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_size_get", + "long_name": "arraymultiter_size_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8212, + "end_line": 8222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_index_get", + "long_name": "arraymultiter_index_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8225, + "end_line": 8235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_shape_get", + "long_name": "arraymultiter_shape_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 8238, + "end_line": 8241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_iters_get", + "long_name": "arraymultiter_iters_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 8244, + "end_line": 8256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_reset", + "long_name": "arraymultiter_reset( PyArrayMultiIterObject * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 38, + "parameters": [ + "self", + "args" + ], + "start_line": 8286, + "end_line": 8293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewFromType", + "long_name": "PyArray_DescrNewFromType( int type_num)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 1, + "token_count": 37, + "parameters": [ + "type_num" + ], + "start_line": 8352, + "end_line": 8361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNew", + "long_name": "PyArray_DescrNew( PyArray_Descr * base)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 151, + "parameters": [ + "base" + ], + "start_line": 8379, + "end_line": 8401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_dealloc", + "long_name": "arraydescr_dealloc( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 8407, + "end_line": 8417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_subdescr_get", + "long_name": "arraydescr_subdescr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 8436, + "end_line": 8444, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8447, + "end_line": 8462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8465, + "end_line": 8487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8490, + "end_line": 8498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8501, + "end_line": 8508, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 8511, + "end_line": 8530, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isbuiltin_get", + "long_name": "arraydescr_isbuiltin_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 8537, + "end_line": 8544, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isnative_get", + "long_name": "arraydescr_isnative_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 8547, + "end_line": 8554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_fields_get", + "long_name": "arraydescr_fields_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 8557, + "end_line": 8564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_new", + "long_name": "arraydescr_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 272, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8612, + "end_line": 8664, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 8670, + "end_line": 8731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8739, + "end_line": 8781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewByteorder", + "long_name": "PyArray_DescrNewByteorder( PyArray_Descr * self , char newendian)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 386, + "parameters": [ + "self", + "newendian" + ], + "start_line": 8801, + "end_line": 8867, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_newbyteorder", + "long_name": "arraydescr_newbyteorder( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 47, + "parameters": [ + "self", + "args" + ], + "start_line": 8878, + "end_line": 8886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_str", + "long_name": "arraydescr_str( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 6, + "token_count": 287, + "parameters": [ + "self" + ], + "start_line": 8901, + "end_line": 8946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_repr", + "long_name": "arraydescr_repr( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 8949, + "end_line": 8958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_compare", + "long_name": "arraydescr_compare( PyArray_Descr * self , PyObject * other)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "other" + ], + "start_line": 8961, + "end_line": 8971, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 8978, + "end_line": 8985, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 8988, + "end_line": 9019, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFlagsObject", + "long_name": "PyArray_NewFlagsObject( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 3, + "token_count": 96, + "parameters": [ + "obj" + ], + "start_line": 9097, + "end_line": 9114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_dealloc", + "long_name": "arrayflags_dealloc( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 9117, + "end_line": 9121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_forc_get", + "long_name": "arrayflags_forc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 9145, + "end_line": 9157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_fnc_get", + "long_name": "arrayflags_fnc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9160, + "end_line": 9172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_farray_get", + "long_name": "arrayflags_farray_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 9175, + "end_line": 9188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_num_get", + "long_name": "arrayflags_num_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 9191, + "end_line": 9194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_updateifcopy_set", + "long_name": "arrayflags_updateifcopy_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9198, + "end_line": 9210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_aligned_set", + "long_name": "arrayflags_aligned_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9213, + "end_line": 9226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_writeable_set", + "long_name": "arrayflags_writeable_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9229, + "end_line": 9242, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_getitem", + "long_name": "arrayflags_getitem( PyArrayFlagsObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 22, + "token_count": 416, + "parameters": [ + "self", + "ind" + ], + "start_line": 9298, + "end_line": 9341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_setitem", + "long_name": "arrayflags_setitem( PyArrayFlagsObject * self , PyObject * ind , PyObject * item)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 8, + "token_count": 178, + "parameters": [ + "self", + "ind", + "item" + ], + "start_line": 9344, + "end_line": 9366, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_torf_", + "long_name": "_torf_( int flags , int val)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 27, + "parameters": [ + "flags", + "val" + ], + "start_line": 9369, + "end_line": 9373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_print", + "long_name": "arrayflags_print( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 1, + "token_count": 77, + "parameters": [ + "self" + ], + "start_line": 9376, + "end_line": 9388, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_new", + "long_name": "arrayflags_new( PyTypeObject * self , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9403, + "end_line": 9415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "arrayflags_getitem", + "long_name": "arrayflags_getitem( PyArrayFlagsObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 75, + "complexity": 31, + "token_count": 431, + "parameters": [ + "self", + "ind" + ], + "start_line": 9298, + "end_line": 9373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_setitem", + "long_name": "arrayflags_setitem( PyArrayFlagsObject * self , PyObject * ind , PyObject * item)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 14, + "token_count": 219, + "parameters": [ + "self", + "ind", + "item" + ], + "start_line": 9376, + "end_line": 9396, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + } + ], + "nloc": 7540, + "complexity": 1626, + "token_count": 43765, + "diff_parsed": { + "added": [ + "\tswitch(n) {", + "\tcase 1:", + "\t\tswitch(key[0]) {", + "\t\tcase 'C':", + "\t\t\treturn arrayflags_contiguous_get(self);", + "\t\tcase 'F':", + "\t\t\treturn arrayflags_fortran_get(self);", + "\t\tcase 'W':", + "\t\t\treturn arrayflags_writeable_get(self);", + "\t\tcase 'B':", + "\t\t\treturn arrayflags_behaved_get(self);", + "\t\tcase 'O':", + "\t\t\treturn arrayflags_owndata_get(self);", + "\t\tcase 'A':", + "\t\t\treturn arrayflags_aligned_get(self);", + "\t\tcase 'U':", + "\t\t\treturn arrayflags_updateifcopy_get(self);", + "\t\tdefault:", + "\t\t\tgoto fail;", + "\t\t}", + "\t\tbreak;", + "\tcase 2:", + "\t\tif (strncmp(key, \"CA\", n)==0)", + "\t\t\treturn arrayflags_carray_get(self);", + "\t\tif (strncmp(key, \"FA\", n)==0)", + "\t\t\treturn arrayflags_farray_get(self);", + "\t\tbreak;", + "\tcase 3:", + "\t\tif (strncmp(key, \"FNC\", n)==0)", + "\t\t\treturn arrayflags_fnc_get(self);", + "\t\tbreak;", + "\tcase 4:", + "\t\tif (strncmp(key, \"FORC\", n)==0)", + "\t\t\treturn arrayflags_forc_get(self);", + "\t\tbreak;", + "\tcase 6:", + "\t\tif (strncmp(key, \"CARRAY\", n)==0)", + "\t\t\treturn arrayflags_carray_get(self);", + "\t\tif (strncmp(key, \"FARRAY\", n)==0)", + "\t\t\treturn arrayflags_farray_get(self);", + "\t\tbreak;", + "\tcase 7:", + "\t\tif (strncmp(key,\"FORTRAN\",n)==0)", + "\t\t\treturn arrayflags_fortran_get(self);", + "\t\tif (strncmp(key,\"BEHAVED\",n)==0)", + "\t\t\treturn arrayflags_behaved_get(self);", + "\t\tif (strncmp(key,\"OWNDATA\",n)==0)", + "\t\t\treturn arrayflags_owndata_get(self);", + "\t\tif (strncmp(key,\"ALIGNED\",n)==0)", + "\t\t\treturn arrayflags_aligned_get(self);", + "\t\tbreak;", + "\tcase 9:", + "\t\tif (strncmp(key,\"WRITEABLE\",n)==0)", + "\t\t\treturn arrayflags_writeable_get(self);", + "\t\tbreak;", + "\tcase 10:", + "\t\tif (strncmp(key,\"CONTIGUOUS\",n)==0)", + "\t\t\treturn arrayflags_contiguous_get(self);", + "\t\tbreak;", + "\tcase 12:", + "\t\tif (strncmp(key, \"UPDATEIFCOPY\", n)==0)", + "\t\t\treturn arrayflags_updateifcopy_get(self);", + "\t\tbreak;", + "\t}", + " if (((n==9) && (strncmp(key, \"WRITEABLE\", n)==0)) ||", + "\t ((n==1) && (strncmp(key, \"W\", n)==0)))", + " else if (((n==7) && (strncmp(key, \"ALIGNED\", n)==0)) ||", + " ((n==1) && (strncmp(key, \"A\", n)==0)))", + " else if (((n==12) && (strncmp(key, \"UPDATEIFCOPY\", n)==0)) ||", + " ((n==1) && (strncmp(key, \"U\", n)==0)))" + ], + "deleted": [ + " if ((strncmp(key,\"CONTIGUOUS\",n)==0) ||", + " (strncmp(key,\"C\",n)))", + " return arrayflags_contiguous_get(self);", + " else if ((strncmp(key, \"FORTRAN\", n)==0) ||", + " (strncmp(key, \"F\", n)==0))", + " return arrayflags_fortran_get(self);", + " else if ((strncmp(key, \"WRITEABLE\", n)==0) ||", + " (strncmp(key, \"W\", n)==0))", + " return arrayflags_writeable_get(self);", + " else if ((strncmp(key, \"BEHAVED\", n)==0) ||", + " (strncmp(key, \"B\", n)==0))", + " return arrayflags_behaved_get(self);", + " else if ((strncmp(key, \"OWNDATA\", n)==0) ||", + " (strncmp(key, \"O\", n)==0))", + " return arrayflags_owndata_get(self);", + " else if ((strncmp(key, \"ALIGNED\", n)==0) ||", + " (strncmp(key, \"A\", n)==0))", + " return arrayflags_aligned_get(self);", + " else if ((strncmp(key, \"UPDATEIFCOPY\", n)==0) ||", + " (strncmp(key, \"U\", n)==0))", + " return arrayflags_updateifcopy_get(self);", + " else if ((strncmp(key, \"FNC\", n)==0))", + " return arrayflags_fnc_get(self);", + " else if ((strncmp(key, \"FORC\", n)==0))", + " return arrayflags_forc_get(self);", + " else if ((strncmp(key, \"CARRAY\", n)==0) ||", + " (strncmp(key, \"CA\", n)==0))", + " return arrayflags_carray_get(self);", + " else if ((strncmp(key, \"FARRAY\", n)==0) ||", + " (strncmp(key, \"FA\", n)==0))", + " return arrayflags_farray_get(self);", + " else goto fail;", + " if ((strncmp(key, \"WRITEABLE\", n)==0) ||", + " (strncmp(key, \"W\", n)==0))", + " else if ((strncmp(key, \"ALIGNED\", n)==0) ||", + " (strncmp(key, \"A\", n)==0))", + " else if ((strncmp(key, \"UPDATEIFCOPY\", n)==0) ||", + " (strncmp(key, \"U\", n)==0))", + " else goto fail;", + " return 0;" + ] + } + } + ] + }, + { + "hash": "5a712837f673a194353113ebad72d5050ad1f68f", + "msg": "Fix bug when setting uic to False.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-15T11:36:26+00:00", + "author_timezone": 0, + "committer_date": "2006-03-15T11:36:26+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "75f139dacec2845ed18424bb65efbed3280fd0b2" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 1, + "insertions": 1, + "lines": 2, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/arraymethods.c", + "new_path": "numpy/core/src/arraymethods.c", + "filename": "arraymethods.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -1539,7 +1539,7 @@ array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)\n }\n else {\n self->flags &= ~UPDATEIFCOPY;\n- Py_DECREF(self->base);\n+ Py_XDECREF(self->base);\n self->base = NULL;\n }\n }\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "\n/* Should only be used if x is known to be an nd-array */\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_take[] = \"a.take(indices, axis=None). Selects the elements \"\\\n\t\"in indices from array a along the given axis.\";\n\nstatic PyObject *\narray_take(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint dimension=MAX_DIMS;\n\tPyObject *indices;\n\tstatic char *kwlist[] = {\"indices\", \"axis\", NULL};\n\t\n\tdimension=0;\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &indices, PyArray_AxisConverter,\n\t\t\t\t\t &dimension))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Take(self, indices, dimension));\n}\n\nstatic char doc_fill[] = \"a.fill(value) places the scalar value at every \"\\\n\t\"position in the array.\";\n\nstatic PyObject *\narray_fill(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *obj;\n\tif (!PyArg_ParseTuple(args, \"O\", &obj))\n\t\treturn NULL;\n\tif (PyArray_FillWithScalar(self, obj) < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_put[] = \"a.put(values, indices) sets a.flat[n] = v[n] \"\\\n\t\"for each n in indices. v can be scalar or shorter than indices, \"\\\n\t\"will repeat.\";\n\nstatic PyObject *\narray_put(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *indices, *values;\n\tstatic char *kwlist[] = {\"values\", \"indices\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &values, &indices))\n\t\treturn NULL;\n\treturn PyArray_Put(self, values, indices);\n}\n\nstatic char doc_putmask[] = \"a.putmask(values, mask) sets a.flat[n] = v[n] \"\\\n\t\"for each n where mask.flat[n] is TRUE. v can be scalar.\";\n\nstatic PyObject *\narray_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *mask, *values;\n\n\tstatic char *kwlist[] = {\"values\", \"mask\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &values, &mask))\n\t\treturn NULL;\n\treturn PyArray_PutMask(self, values, mask);\n}\n\n/* Used to reshape a Fortran Array */\nstatic void\n_reverse_shape(PyArray_Dims *newshape)\n{\n\tint i, n = newshape->len;\n\tintp *ptr = newshape->ptr;\n\tintp *eptr;\n\tintp tmp;\n\tint len = n >> 1;\n\n\teptr = ptr+n-1;\n\tfor(i=0; i) return a new view of array with same data. type can be either a new sub-type object or a data-descriptor object\";\n\nstatic PyObject *\narray_view(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *otype=NULL;\n PyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTuple(args, \"|O\", &otype)) return NULL;\n\n\tif (otype) {\n\t\tif (PyType_Check(otype) &&\t\t\t\\\n\t\t PyType_IsSubtype((PyTypeObject *)otype, \n\t\t\t\t &PyArray_Type)) {\n\t\t\treturn PyArray_View(self, NULL, \n (PyTypeObject *)otype);\n }\n\t\telse {\n\t\t\tif (PyArray_DescrConverter(otype, &type) == PY_FAIL) \n\t\t\t\treturn NULL;\n\t\t}\n\t}\n\treturn PyArray_View(self, type, NULL);\n}\n\nstatic char doc_argmax[] = \"a.argmax(axis=None)\";\n\nstatic PyObject *\narray_argmax(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\n\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\n\t\n\treturn PyArray_Min(self, axis);\n}\n\nstatic char doc_swapaxes[] = \"a.swapaxes(axis1, axis2) returns new view with axes swapped.\";\n\nstatic PyObject *\narray_swapaxes(PyArrayObject *self, PyObject *args)\n{\n\tint axis1, axis2;\n\n\tif (!PyArg_ParseTuple(args, \"ii\", &axis1, &axis2)) return NULL;\n\n\treturn PyArray_SwapAxes(self, axis1, axis2);\n}\n\nstatic char doc_getfield[] = \"m.getfield(dtype, offset) returns a field \"\\\n\t\" of the given array as a certain type. A field is a view of \"\\\n\t\" the array's data with each itemsize determined by the given type\"\\\n\t\" and the offset into the current array.\";\n\n/* steals typed reference */\n/*OBJECT_API\n Get a subset of bytes from each element of the array\n*/\nstatic PyObject *\nPyArray_GetField(PyArrayObject *self, PyArray_Descr *typed, int offset)\n{\n\tPyObject *ret=NULL;\n\n\tif (offset < 0 || (offset + typed->elsize) > self->descr->elsize) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need 0 <= offset <= %d for requested type \" \\\n\t\t\t \"but received offset = %d\",\n\t\t\t self->descr->elsize-typed->elsize, offset);\n\t\tPy_DECREF(typed);\n\t\treturn NULL;\n\t}\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t typed,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, \n\t\t\t\t self->data + offset,\n\t\t\t\t self->flags, (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self; \n\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\treturn ret;\n}\n\nstatic PyObject *\narray_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\n PyArray_Descr *dtype;\n\tint offset = 0;\n\tstatic char *kwlist[] = {\"dtype\", \"offset\", 0};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|i\", kwlist,\n\t\t\t\t\t PyArray_DescrConverter,\n\t\t\t\t\t &dtype, &offset)) return NULL;\n\t\n\treturn _ARET(PyArray_GetField(self, dtype, offset));\n}\n\n\nstatic char doc_setfield[] = \"m.setfield(value, dtype, offset) places val \"\\\n\t\"into field of the given array defined by the data type and offset.\";\n\n/*OBJECT_API\n Set a subset of bytes from each element of the array\n*/\nstatic int\nPyArray_SetField(PyArrayObject *self, PyArray_Descr *dtype,\n\t\t int offset, PyObject *val)\n{\n\tPyObject *ret=NULL;\n\tint retval = 0;\n \n\tif (offset < 0 || (offset + dtype->elsize) > self->descr->elsize) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need 0 <= offset <= %d for requested type \" \\\n\t\t\t \"but received offset = %d\",\n\t\t\t self->descr->elsize-dtype->elsize, offset);\n\t\tPy_DECREF(dtype);\n\t\treturn -1;\n\t}\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t dtype, self->nd, self->dimensions,\n\t\t\t\t self->strides, self->data + offset,\n\t\t\t\t self->flags, (PyObject *)self);\n\tif (ret == NULL) return -1;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self;\n\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\t\n\tretval = PyArray_CopyObject((PyArrayObject *)ret, val);\n\tPy_DECREF(ret);\n\treturn retval;\n}\n\nstatic PyObject *\narray_setfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n PyArray_Descr *dtype;\n\tint offset = 0;\n\tPyObject *value;\n\tstatic char *kwlist[] = {\"value\", \"dtype\", \"offset\", 0};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO&|i\", kwlist,\n\t\t\t\t\t &value, PyArray_DescrConverter,\n\t\t\t\t\t &dtype, &offset)) return NULL;\n\n\tif (PyArray_SetField(self, dtype, offset, value) < 0)\n\t\treturn NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n/* This doesn't change the descriptor just the actual data...\n */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_Byteswap(PyArrayObject *self, Bool inplace)\n{\n PyArrayObject *ret;\n\tintp size;\n\tPyArray_CopySwapNFunc *copyswapn;\n\tPyArray_CopySwapFunc *copyswap;\n\tPyArrayIterObject *it;\n\n\tif (inplace) {\n\t\tcopyswapn = self->descr->f->copyswapn;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\t\tif (PyArray_ISONESEGMENT(self)) {\n\t\t\tcopyswapn(self->data, NULL, size, 1, \n\t\t\t\t self->descr->elsize);\n\t\t}\n\t\telse { /* Use iterator */\n\t\t\t\n\t\t\tit = (PyArrayIterObject *)\\\n\t\t\t\tPyArray_IterNew((PyObject *)self);\n\t\t\tcopyswap = self->descr->f->copyswap;\n\t\t\twhile (it->index < it->size) {\n\t\t\t\tcopyswap(it->dataptr, NULL, 1, \n\t\t\t\t\t self->descr->elsize);\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t}\n\t\t\tPy_DECREF(it);\n\t\t}\n\t\t\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tif ((ret = (PyArrayObject *)PyArray_NewCopy(self,-1)) == NULL) \n\t\t\treturn NULL;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\n\t\t/* now ret has the same dtypedescr as self (including\n\t\t byteorder)\n\t\t*/\n\n\t\tret->descr->f->copyswapn(ret->data, NULL, size, 1, \n\t\t\t\t\t ret->descr->elsize);\n\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic char doc_byteswap[] = \"m.byteswap(False) Swap the bytes in\"\\\n\t\" the array. Return the byteswapped array. If the first argument\"\\\n\t\" is TRUE, byteswap in-place and return a reference to self.\";\n\nstatic PyObject *\narray_byteswap(PyArrayObject *self, PyObject *args) \n{\n\tBool inplace=FALSE;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter, &inplace))\n\t\treturn NULL;\n\t\n\treturn PyArray_Byteswap(self, inplace);\n}\n\nstatic char doc_tolist[] = \"m.tolist().\t Copy the data portion of the array\"\\\n\t\" to a hierarchical python list and return that list.\";\n\nstatic PyObject *\narray_tolist(PyArrayObject *self, PyObject *args) \n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n if (self->nd <= 0) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"can't convert a 0-d array to a list\");\n return NULL;\n }\n\t\n return PyArray_ToList(self);\n}\n\nstatic char doc_tostring[] = \"m.tostring() Construct a Python string \"\\\n \"containing the raw bytes in the array\";\n\nstatic PyObject *\narray_tostring(PyArrayObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n return PyArray_ToString(self);\n}\n\nstatic char doc_tofile[] = \"m.tofile(fid, sep=\"\") write the data to a file.\";\n\nstatic PyObject *\narray_tofile(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tint ret;\n PyObject *file;\n\tFILE *fd;\n char *sep=\"\";\n\tchar *format=\"\";\n\tchar *mode=\"\";\n\tstatic char *kwlist[] = {\"file\", \"sep\", \"format\", NULL};\n \n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ss\", kwlist, \n &file, &sep, &format)) return NULL;\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"wb\";\n\t\telse mode=\"w\";\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), mode);\n\t\tif (file==NULL) return NULL;\n\t}\n\telse {\n\t\tPy_INCREF(file);\n\t}\n\tfd = PyFile_AsFile(file);\n\tif (fd == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \"first argument must be a \" \\\n\t\t\t\t\"string or open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_ToFile(self, fd, sep, format);\n\tPy_DECREF(file);\n\tif (ret < 0) return NULL;\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_toscalar[] = \"m.item(). Copy the first data point of \"\\\n\t\"the array to a standard Python scalar and return it.\";\n\nstatic PyObject *\narray_toscalar(PyArrayObject *self, PyObject *args) {\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\tif (self->nd == 0 || PyArray_SIZE(self) == 1) \n\t\treturn self->descr->f->getitem(self->data, self);\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError, \"can only convert an\"\t\\\n\t\t\t\t\" array of size 1 to Python scalar.\");\n\t\treturn NULL;\n\t}\n}\n\nstatic char doc_cast[] = \"m.astype(t).\tCast array m to type t.\t \\n\\n\"\\\n\t\"t can be either a string representing a typecode, or a python type\"\\\n\t\" object of type int, float, or complex.\";\n\nstatic PyObject *\narray_cast(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Descr *descr=NULL;\n\tPyObject *obj;\n\t\n if (!PyArg_ParseTuple(args, \"O&\", PyArray_DescrConverter,\n\t\t\t &descr)) return NULL;\n\t\n\tif (descr == self->descr) {\n\t\tobj = _ARET(PyArray_NewCopy(self,0));\n\t\tPy_XDECREF(descr);\n\t\treturn obj;\n\t}\n\treturn _ARET(PyArray_CastToType(self, descr, 0));\n}\t \n\n/* default sub-type implementation */\n\nstatic char doc_wraparray[] = \"m.__array_wrap__(obj) returns an object of \"\\\n\t\"type m from the ndarray object obj\";\n\nstatic PyObject *\narray_wraparray(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *arr;\n\tPyObject *ret;\n\t\n\tif (PyTuple_Size(args) < 1) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"only accepts 1 argument\");\n\t\treturn NULL;\n\t}\n\tarr = PyTuple_GET_ITEM(args, 0);\n\tif (!PyArray_Check(arr)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"can only be called with ndarray object\");\n\t\treturn NULL;\n\t}\t\n\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t PyArray_NDIM(arr),\n\t\t\t\t PyArray_DIMS(arr), \n\t\t\t\t PyArray_STRIDES(arr), PyArray_DATA(arr),\n\t\t\t\t PyArray_FLAGS(arr), (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(arr);\n\tPyArray_BASE(ret) = arr;\n\treturn ret;\n}\n\n/* NO-OP --- just so all subclasses will have one by default. */\nstatic PyObject *\narray_finalize(PyArrayObject *self, PyObject *args)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic char doc_array_getarray[] = \"m.__array__(|dtype) just returns either a new reference to self if dtype is not given or a new array of provided data type if dtype is different from the current dtype of the array.\";\n\nstatic PyObject *\narray_getarray(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Descr *newtype=NULL;\n\tPyObject *ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_DescrConverter,\n\t\t\t &newtype)) return NULL;\n\t\n\t/* convert to PyArray_Type */\n\tif (!PyArray_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 = &PyArray_Type;\n\t\t}\n\t\t\n\t\tPy_INCREF(PyArray_DESCR(self));\n\t\tnew = PyArray_NewFromDescr(subtype, \n\t\t\t\t\t PyArray_DESCR(self),\n\t\t\t\t\t PyArray_NDIM(self),\n\t\t\t\t\t PyArray_DIMS(self), \n\t\t\t\t\t PyArray_STRIDES(self), \n\t\t\t\t\t PyArray_DATA(self),\n\t\t\t\t\t PyArray_FLAGS(self), NULL);\n\t\tif (new == NULL) return NULL;\n\t\tPy_INCREF(self);\n\t\tPyArray_BASE(new) = (PyObject *)self;\n\t\tself = (PyArrayObject *)new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t}\n\t\t\n\tif ((newtype == NULL) || \\\n\t PyArray_EquivTypes(self->descr, newtype)) {\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tret = PyArray_CastToType(self, newtype, 0);\n\t\tPy_DECREF(self);\n\t\treturn ret;\n\t}\n}\n\nstatic char doc_copy[] = \"m.copy(|fortran). Return a copy of the array.\\n\"\\\n\t\"If fortran == 0 then the result is contiguous (default). \\n\"\\\n\t\"If fortran > 0 then the result has fortran data order. \\n\"\\\n\t\"If fortran < 0 then the result has fortran data order only if m\\n\"\n\t\" is already in fortran order.\";\n\nstatic PyObject *\narray_copy(PyArrayObject *self, PyObject *args) \n{\n\tint fortran=0;\n if (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n\t\n return PyArray_NewCopy(self, fortran);\n}\n\nstatic char doc_resize[] = \"self.resize(new_shape, refcheck=True). \"\\\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, PyObject *kwds) \n{\n PyArray_Dims newshape;\n PyObject *ret;\n\tint n;\n\tint refcheck = 1;\n\t\n\tif (kwds != NULL) {\n\t\tPyObject *ref;\n\t\tref = PyDict_GetItemString(kwds, \"refcheck\");\n\t\tif (ref) {\n\t\t\trefcheck = PyInt_AsLong(ref);\n\t\t\tif (refcheck==-1 && PyErr_Occurred()) {\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\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\t\n\tret = PyArray_Resize(self, &newshape, refcheck);\n PyDimMem_FREE(newshape.ptr);\n if (ret == NULL) return NULL;\n\tPy_DECREF(ret);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_repeat[] = \"a.repeat(repeats=, axis=None)\\n\"\\\n\t\"\\n\"\\\n\t\" Copy elements of a, repeats times. The repeats argument must\\n\"\\\n\t\" be a sequence of length a.shape[axis] or a scalar.\";\n\nstatic PyObject *\narray_repeat(PyArrayObject *self, PyObject *args, PyObject *kwds) {\n\tPyObject *repeats;\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"repeats\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &repeats, PyArray_AxisConverter,\n\t\t\t\t\t &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_Repeat(self, repeats, axis));\n}\n\nstatic char doc_choose[] = \"a.choose(b0, b1, ..., bn)\\n\"\\\n\t\"\\n\"\\\n\t\"Return an array with elements chosen from 'a' at the positions\\n\"\\\n \"of the given arrays b_i. The array 'a' should be an integer array\\n\"\\\n \"with entries from 0 to n+1, and the b_i arrays should have the same\\n\"\\\n \"shape as 'a'.\";\n\nstatic PyObject *\narray_choose(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *choices;\n\tint n;\n\t\n\tn = PyTuple_Size(args);\n\tif (n <= 1) {\n\t\tif (!PyArg_ParseTuple(args, \"O\", &choices))\n\t\t\treturn NULL;\n\t}\n else {\n\t\tchoices = args;\n\t}\n\t\n\treturn _ARET(PyArray_Choose(self, choices));\n}\n\nstatic char doc_sort[] = \"a.sort(axis=-1,kind='quicksort') sorts in place along axis. Return is None and kind can be 'quicksort', 'mergesort', or 'heapsort'\";\n\nstatic PyObject *\narray_sort(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=-1;\n\tint val;\n\tPyArray_SORTKIND which=PyArray_QUICKSORT;\n\tstatic char *kwlist[] = {\"axis\", \"kind\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iO&\", kwlist, &axis,\n\t\t\t\t\t PyArray_SortkindConverter, &which))\n\t\treturn NULL;\n\t\n\tval = PyArray_Sort(self, axis, which);\n\tif (val < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_argsort[] = \"a.argsort(axis=-1,kind='quicksort')\\n\"\\\n\t\" Return the indexes into a that would sort it along the\"\\\n\t\" given axis; kind can be 'quicksort', 'mergesort', or 'heapsort'\";\n\nstatic PyObject *\narray_argsort(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=-1;\n\tPyArray_SORTKIND which=PyArray_QUICKSORT;\n\tstatic char *kwlist[] = {\"axis\", \"kind\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iO&\", kwlist, &axis,\n\t\t\t\t\t PyArray_SortkindConverter, &which))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_ArgSort(self, axis, which));\n}\n\nstatic char doc_searchsorted[] = \"a.searchsorted(v)\\n\"\\\n\t\" Assuming that a is a 1-D array, in ascending order and\\n\"\\\n\t\" represents bin boundaries, then a.searchsorted(values) gives an\\n\"\\\n\t\" array of bin numbers, giving the bin into which each value would\\n\"\\\n\t\" be placed. This method is helpful for histograming. \\n\"\\\n\t\" Note: No warning is given if the boundaries, in a, are not \\n\"\\\n\t\" in ascending order.\";\n\nstatic PyObject *\narray_searchsorted(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *values;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &values)) return NULL;\n\t\n\treturn _ARET(PyArray_SearchSorted(self, values));\n}\n\nstatic char doc_deepcopy[] = \"Used if copy.deepcopy is called on an array.\";\n\nstatic PyObject *\narray_deepcopy(PyArrayObject *self, PyObject *args) \n{\n PyObject* visit;\n PyObject **optr;\n PyArrayIterObject *it;\n PyObject *copy, *ret, *deepcopy, *temp, *res;\n\n if (!PyArg_ParseTuple(args, \"O\", &visit)) return NULL;\n ret = PyArray_Copy(self);\n if (PyArray_ISOBJECT(self)) {\n copy = PyImport_ImportModule(\"copy\");\n if (copy == NULL) return NULL;\n deepcopy = PyObject_GetAttrString(copy, \"deepcopy\");\n Py_DECREF(copy);\n if (deepcopy == NULL) return NULL;\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it == NULL) {Py_DECREF(deepcopy); return NULL;}\n optr = (PyObject **)PyArray_DATA(ret);\n while(it->index < it->size) {\n temp = *((PyObject **)it->dataptr);\n Py_INCREF(temp);\n /* call deepcopy on this argument */\n res = PyObject_CallFunctionObjArgs(deepcopy, \n temp, visit, NULL);\n Py_DECREF(temp);\n Py_DECREF(*optr);\n *optr++ = res;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(deepcopy);\n Py_DECREF(it);\n }\n return _ARET(ret);\n}\n\n/* Convert Object Array to flat list and pickle the flat list string */\nstatic PyObject *\n_getobject_pkl(PyArrayObject *self)\n{\n\tPyObject *theobject;\n\tPyArrayIterObject *iter=NULL;\n\tPyObject *list;\n\n\t\n\titer = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (iter == NULL) return NULL;\n\tlist = PyList_New(iter->size);\n\tif (list == NULL) {Py_DECREF(iter); return NULL;}\n\twhile (iter->index < iter->size) {\n\t\ttheobject = *((PyObject **)iter->dataptr);\n\t\tPy_INCREF(theobject);\n\t\tPyList_SET_ITEM(list, (int) iter->index, theobject);\n\t\tPyArray_ITER_NEXT(iter);\n\t}\n\tPy_DECREF(iter);\n\treturn list;\n}\n\nstatic int\n_setobject_pkl(PyArrayObject *self, PyObject *list)\n{\n\tPyObject *theobject;\n\tPyArrayIterObject *iter=NULL;\n\tint size;\n\n\tsize = self->descr->elsize;\n\t\n\titer = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (iter == NULL) return -1;\n\twhile(iter->index < iter->size) {\n\t\ttheobject = PyList_GET_ITEM(list, (int) iter->index);\n\t\tPy_INCREF(theobject);\n\t\t*((PyObject **)iter->dataptr) = theobject;\n\t\tPyArray_ITER_NEXT(iter);\n\t}\n\tPy_XDECREF(iter);\n\treturn 0;\n}\n\nstatic char doc_reduce[] = \"a.__reduce__() for pickling.\";\n\nstatic PyObject *\narray_reduce(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *ret=NULL, *state=NULL, *obj=NULL, *mod=NULL;\n\tPyObject *mybool, *thestr=NULL;\n\tPyArray_Descr *descr;\n\n\t/* Return a tuple of (callable object, arguments, object's state) */\n\t/* We will put everything in the object's state, so that on UnPickle\n\t it can use the string object as memory without a copy */\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core._internal\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"_reconstruct\");\n\tPy_DECREF(mod);\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t Py_BuildValue(\"ONN\",\n\t\t\t\t (PyObject *)self->ob_type,\n\t\t\t\t Py_BuildValue(\"(N)\",\n\t\t\t\t\t\t PyInt_FromLong(0)),\n\t\t\t\t PyObject_GetAttrString((PyObject *)(self->descr),\n\t\t\t\t\t\t\t \"char\")));\n\t\n\t/* Now fill in object's state. This is a tuple with \n\t 4 arguments\n\n\t 1) a Tuple giving the shape\n\t 2) a PyArray_Descr Object (with correct bytorder set)\n\t 3) a Bool stating if Fortran or not\n\t 4) a binary string with the data (or a list for Object arrays)\n\n\t Notice because Python does not describe a mechanism to write \n\t raw data to the pickle, this performs a copy to a string first\n\t*/\n\n\tstate = PyTuple_New(4);\n\tif (state == NULL) {\n\t\tPy_DECREF(ret); return NULL;\n\t}\n\tPyTuple_SET_ITEM(state, 0, PyObject_GetAttrString((PyObject *)self, \n\t\t\t\t\t\t\t \"shape\"));\n\tdescr = self->descr;\n\tPy_INCREF(descr);\n\tPyTuple_SET_ITEM(state, 1, (PyObject *)descr);\n\tmybool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);\n\tPy_INCREF(mybool);\n\tPyTuple_SET_ITEM(state, 2, mybool);\n\tif (PyArray_ISOBJECT(self)) {\n\t\tthestr = _getobject_pkl(self);\n\t}\n\telse {\n thestr = PyArray_ToString(self);\n\t}\n\tif (thestr == NULL) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(state);\n\t\treturn NULL;\n\t}\n\tPyTuple_SET_ITEM(state, 3, thestr);\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\nstatic char doc_setstate[] = \"a.__setstate__(tuple) for unpickling.\";\n\n/*\n\t 1) a Tuple giving the shape\n\t 2) a PyArray_Descr Object\n\t 3) a Bool stating if Fortran or not\n\t 4) a binary string with the data (or a list if Object array) \n*/\n\nstatic intp _array_fill_strides(intp *, intp *, int, intp, int, int *);\n\nstatic int _IsAligned(PyArrayObject *); \n\nstatic PyArray_Descr * _array_typedescr_fromstr(char *);\n\nstatic PyObject *\narray_setstate(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *shape;\n\tPyArray_Descr *typecode;\n\tint fortran;\n\tPyObject *rawdata;\n\tchar *datastr;\n\tint len;\n\tintp dimensions[MAX_DIMS];\n\tint nd;\n\t\n\t/* This will free any memory associated with a and\n\t use the string in setstate as the (writeable) memory.\n\t*/\n\tif (!PyArg_ParseTuple(args, \"(O!O!iO)\", &PyTuple_Type,\n\t\t\t &shape, &PyArrayDescr_Type, &typecode, \n\t\t\t &fortran, &rawdata))\n\t\treturn NULL;\n\n\tPy_XDECREF(self->descr);\n\tself->descr = typecode;\n\tPy_INCREF(typecode);\n\tnd = PyArray_IntpFromSequence(shape, dimensions, MAX_DIMS);\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (!PyList_Check(rawdata)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"object pickle not returning list\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tif (!PyString_Check(rawdata)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"pickle not returning string\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (PyString_AsStringAndSize(rawdata, &datastr, &len))\n\t\t\treturn NULL;\n\n\t\tif ((len != (self->descr->elsize *\t\t\t\\\n\t\t\t (int) PyArray_MultiplyList(dimensions, nd)))) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size does not\"\t\\\n\t\t\t\t\t\" match array size\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n if ((self->flags & OWN_DATA)) {\n\t\tif (self->data != NULL)\n\t\t\tPyDataMem_FREE(self->data);\n\t\tself->flags &= ~OWN_DATA;\n }\n\tPy_XDECREF(self->base);\n\n\tself->flags &= ~UPDATEIFCOPY;\n\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t\tself->dimensions = NULL;\n\t}\n\n\tself->flags = DEFAULT_FLAGS;\n\n\tself->nd = nd;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(nd * 2);\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dimensions, sizeof(intp)*nd);\n\t\t(void) _array_fill_strides(self->strides, dimensions, nd,\n\t\t\t\t\t self->descr->elsize, \n (fortran ? FORTRAN : CONTIGUOUS),\n\t\t\t\t\t &(self->flags));\n\t}\n\n\tif (typecode->type_num != PyArray_OBJECT) {\n\t\tself->data = datastr;\n\t\tif (!_IsAligned(self)) {\n\t\t\tintp num = PyArray_NBYTES(self);\n\t\t\tself->data = PyDataMem_NEW(num);\n\t\t\tif (self->data == NULL) {\n\t\t\t\tself->nd = 0;\n\t\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemcpy(self->data, datastr, num);\n\t\t\tself->flags |= OWN_DATA;\n\t\t\tself->base = NULL;\n\t\t}\n\t\telse {\n\t\t\tself->base = rawdata;\n\t\t\tPy_INCREF(self->base);\n\t\t}\n\t}\n\telse {\n\t\tself->data = PyDataMem_NEW(PyArray_NBYTES(self));\n\t\tif (self->data == NULL) { \n\t\t\tself->nd = 0;\n\t\t\tself->data = PyDataMem_NEW(self->descr->elsize);\n\t\t\tif (self->dimensions) PyDimMem_FREE(self->dimensions);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\t\tself->base = NULL;\n\t\tif (_setobject_pkl(self, rawdata) < 0) \n\t\t\treturn NULL;\n\t}\n\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\t\n}\n\n/*OBJECT_API*/\nstatic int\nPyArray_Dump(PyObject *self, PyObject *file, int protocol)\n{\n\tPyObject *cpick=NULL;\n\tPyObject *ret;\n\tif (protocol < 0) protocol = 2;\n\n\tcpick = PyImport_ImportModule(\"cPickle\");\n\tif (cpick==NULL) return -1;\n\n\tif PyString_Check(file) {\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), \"wb\");\n\t\tif (file==NULL) return -1;\n\t}\n\telse Py_INCREF(file);\n\tret = PyObject_CallMethod(cpick, \"dump\", \"OOi\", self, \n\t\t\t\t file, protocol);\n\tPy_XDECREF(ret);\n\tPy_DECREF(file);\n\tPy_DECREF(cpick);\n\tif (PyErr_Occurred()) return -1;\n\treturn 0;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_Dumps(PyObject *self, int protocol)\n{\n\tPyObject *cpick=NULL;\n\tPyObject *ret;\n\tif (protocol < 0) protocol = 2;\n\n\tcpick = PyImport_ImportModule(\"cPickle\");\n\tif (cpick==NULL) return NULL;\n\tret = PyObject_CallMethod(cpick, \"dumps\", \"Oi\", self, protocol);\n\tPy_DECREF(cpick);\n\treturn ret;\n}\n\n\nstatic char doc_dump[] = \"m.dump(file)\";\n\nstatic PyObject *\narray_dump(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *file=NULL;\n\tint ret;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &file))\n\t\treturn NULL;\n\tret = PyArray_Dump((PyObject *)self, file, 2);\n\tif (ret < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_dumps[] = \"m.dumps()\";\n\nstatic PyObject *\narray_dumps(PyArrayObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\"))\n\t\treturn NULL;\n\treturn PyArray_Dumps((PyObject *)self, 2);\n}\n\n\nstatic char doc_transpose[] = \"m.transpose()\";\n\nstatic PyObject *\narray_transpose(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *shape=Py_None;\n\tint n;\n\tPyArray_Dims permute;\n\tPyObject *ret;\n\n\tn = PyTuple_Size(args);\n\tif (n > 1) shape = args;\n\telse if (n == 1) shape = PyTuple_GET_ITEM(args, 0);\n\t\n\tif (shape == Py_None)\n\t\tret = PyArray_Transpose(self, NULL);\n\telse {\n\t\tif (!PyArray_IntpConverter(shape, &permute)) return NULL;\n\t\tret = PyArray_Transpose(self, &permute);\n\t\tPyDimMem_FREE(permute.ptr);\n\t}\n\t\n\treturn _ARET(ret);\n}\n\nstatic char doc_mean[] = \"a.mean(axis=None, dtype=None)\\n\\n\"\\\n \"Average the array over the given axis. If the axis is None, average\\n\"\\\n \"over all dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, dtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\\n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, dtype) * 1.0 / product(a.shape)\\n\"\\\n \"\\n\"\\\n \"The optional dtype argument is the data type for intermediate\\n\"\\\n \"calculations in the sum.\";\n\n#define _CHKTYPENUM(typ) ((typ) ? (typ)->type_num : PyArray_NOTYPE)\n\nstatic PyObject *\narray_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist,\n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\n\treturn PyArray_Mean(self, axis, _CHKTYPENUM(dtype));\n}\n\nstatic char doc_sum[] = \"a.sum(axis=None, dtype=None)\\n\\n\"\\\n \"Sum the array over the given axis. If the axis is None, sum over all\\n\"\\\n \"dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"The optional dtype argument is the data type for the returned value\\n\"\\\n \"and intermediate calculations. The default is to upcast (promote)\\n\"\\\n \"smaller integer types to the platform-dependent int. For example, on\\n\"\\\n \"32-bit platforms:\\n\"\\\n \"\\n\"\\\n \" a.dtype default sum() dtype\\n\"\\\n \" ---------------------------------------------------\\n\"\\\n \" bool, int8, int16, int32 int32\\n\"\\\n \"\\n\"\\\n \"Examples:\\n\"\\\n \"\\n\"\\\n \">>> array([0.5, 1.5]).sum()\\n\"\\\n \"2.0\\n\"\\\n \">>> array([0.5, 1.5]).sum(dtype=int32)\\n\"\\\n \"1\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum(axis=0)\\n\"\\\n \"array([0, 6])\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum(axis=1)\\n\"\\\n \"array([1, 5])\";\n\nstatic PyObject *\narray_sum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Sum(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_cumsum[] = \"a.cumsum(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_CumSum(self, axis, _CHKTYPENUM(dtype));\n}\n\nstatic char doc_prod[] = \"a.prod(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Prod(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_cumprod[] = \"a.cumprod(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_CumProd(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_any[] = \"a.any(axis=None)\";\n\nstatic PyObject *\narray_any(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\n\n\treturn PyArray_All(self, axis);\n}\n\nstatic char doc_stddev[] = \"a.std(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, _CHKTYPENUM(dtype), 0);\n}\n\nstatic char doc_variance[] = \"a.var(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_variance(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, _CHKTYPENUM(dtype), 1);\n}\n\nstatic char doc_compress[] = \"a.compress(condition=, axis=None)\";\n\nstatic PyObject *\narray_compress(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyObject *condition;\t\n\tstatic char *kwlist[] = {\"condition\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &condition, PyArray_AxisConverter,\n\t\t\t\t\t &axis)) return NULL;\n\n\treturn _ARET(PyArray_Compress(self, condition, axis));\n}\n\nstatic char doc_nonzero[] = \"a.nonzero() return a tuple of indices referencing \"\\\n\t\"the elements of a that are nonzero.\";\n\nstatic PyObject *\narray_nonzero(PyArrayObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\treturn _ARET(PyArray_Nonzero(self));\n}\n\n\nstatic char doc_trace[] = \"a.trace(offset=0, axis1=0, axis2=1, dtype=None)\\n\"\\\n\t\"return the sum along the offset diagonal of the arrays indicated\\n\" \\\n\t\"axis1 and axis2.\";\n\nstatic PyObject *\narray_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iiiO&\", kwlist, \n\t\t\t\t\t &offset, &axis1, &axis2,\n\t\t\t\t\t PyArray_DescrConverter2, &dtype))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Trace(self, offset, axis1, axis2, \n\t\t\t\t _CHKTYPENUM(dtype)));\n}\n\n#undef _CHKTYPENUM\n\n\nstatic char doc_clip[] = \"a.clip(min=, max=)\";\n\nstatic PyObject *\narray_clip(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *min, *max;\n\tstatic char *kwlist[] = {\"min\", \"max\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &min, &max)) \n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Clip(self, min, max));\n}\n\nstatic char doc_conj[] = \"a.conj()\";\n\nstatic char doc_conjugate[] = \"a.conjugate()\";\n\nstatic PyObject *\narray_conjugate(PyArrayObject *self, PyObject *args) \n{\n\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n\treturn PyArray_Conjugate(self);\n}\n\n\nstatic char doc_diagonal[] = \"a.diagonal(offset=0, axis1=0, axis2=1)\";\n\nstatic PyObject *\narray_diagonal(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iii\", kwlist, \n\t\t\t\t\t &offset, &axis1, &axis2))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Diagonal(self, offset, axis1, axis2));\n}\n\nstatic char doc_flatten[] = \"a.flatten([fortran]) return a 1-d array (always copy)\";\n\nstatic PyObject *\narray_flatten(PyArrayObject *self, PyObject *args)\n{\n\tint fortran=0;\n\n\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n \n\treturn PyArray_Flatten(self, (int) fortran);\n}\n\nstatic char doc_ravel[] = \"a.ravel([fortran]) return a 1-d array (copy only if needed)\";\n\nstatic PyObject *\narray_ravel(PyArrayObject *self, PyObject *args)\n{\n\tint fortran=0;\n\n\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n\n\treturn PyArray_Ravel(self, fortran);\n}\n\nstatic char doc_round[] = \"a.round(decimals=0)\";\n\nstatic PyObject *\narray_round(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint decimals = 0;\n\tstatic char *kwlist[] = {\"decimals\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|i\", kwlist,\n\t\t\t\t\t &decimals)) \n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Round(self, decimals));\n}\n\n\nstatic char doc_setflags[] = \"a.setflags(write=None, align=None, uic=None)\";\n\nstatic int _IsAligned(PyArrayObject *);\nstatic Bool _IsWriteable(PyArrayObject *);\n\nstatic PyObject *\narray_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"write\", \"align\", \"uic\", NULL};\n\tPyObject *write=Py_None;\n\tPyObject *align=Py_None;\n\tPyObject *uic=Py_None;\n\tint flagback = self->flags;\n\t\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|OOO\", kwlist,\n\t\t\t\t\t &write, &align, &uic))\n\t\treturn NULL;\n\n\tif (align != Py_None) {\n\t\tif (PyObject_Not(align)) self->flags &= ~ALIGNED;\n\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"cannot set aligned flag of mis-\"\\\n\t\t\t\t\t\"aligned array to True\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif (uic != Py_None) {\n if (PyObject_IsTrue(uic)) {\n\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY\" \\\n \"flag to True\");\n return NULL;\n }\n else {\n self->flags &= ~UPDATEIFCOPY;\n Py_XDECREF(self->base);\n self->base = NULL;\n }\n }\n \n if (write != Py_None) {\n if (PyObject_IsTrue(write)) \n\t\t\tif (_IsWriteable(self)) {\n\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tself->flags = flagback;\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"cannot set WRITEABLE \"\t\\\n\t\t\t\t\t\t\"flag to True of this \"\t\\\n\t\t\t\t\t\t\"array\");\t\t\\\n\t\t\t\treturn NULL;\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n \n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_newbyteorder[] = \"a.newbyteorder() is equivalent\\n\" \\\n\t\" to a.view(a.dtype.newbytorder())\\n\";\n\nstatic PyObject *\narray_newbyteorder(PyArrayObject *self, PyObject *args) \n{\n\tchar endian = PyArray_SWAP;\n\tPyArray_Descr *new;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\tnew = PyArray_DescrNewByteorder(self->descr, endian);\n\tif (!new) return NULL;\n\treturn PyArray_View(self, new, NULL);\n\n}\n\nstatic PyMethodDef array_methods[] = {\n {\"tolist\",\t (PyCFunction)array_tolist,\t1, doc_tolist},\n {\"item\", (PyCFunction)array_toscalar, METH_VARARGS, doc_toscalar},\n\t{\"tofile\", (PyCFunction)array_tofile, \n METH_VARARGS | METH_KEYWORDS, doc_tofile},\n {\"tostring\", (PyCFunction)array_tostring, METH_VARARGS, doc_tostring},\n {\"byteswap\", (PyCFunction)array_byteswap,\t1, doc_byteswap},\n {\"astype\", (PyCFunction)array_cast, 1, doc_cast},\n\t{\"getfield\", (PyCFunction)array_getfield, \n\t METH_VARARGS | METH_KEYWORDS, doc_getfield},\n\t{\"setfield\", (PyCFunction)array_setfield, \n\t METH_VARARGS | METH_KEYWORDS, doc_setfield},\n {\"copy\", (PyCFunction)array_copy, 1, doc_copy}, \n {\"resize\", (PyCFunction)array_resize, \n\t METH_VARARGS | METH_KEYWORDS, doc_resize}, \n\n\t/* for subtypes */\n\t{\"__array__\", (PyCFunction)array_getarray, 1, doc_array_getarray},\n\t{\"__array_wrap__\", (PyCFunction)array_wraparray, 1, doc_wraparray},\n\t/* default version so it is found... -- only used for subclasses */\n\t{\"__array_finalize__\", (PyCFunction)array_finalize, 1, NULL},\n\t\n\t\n\t/* for the copy module */\n {\"__copy__\", (PyCFunction)array_copy, 1, doc_copy},\t \n {\"__deepcopy__\", (PyCFunction)array_deepcopy, 1, doc_deepcopy}, \n\t\n /* for Pickling */\n {\"__reduce__\", (PyCFunction) array_reduce, 1, doc_reduce},\t\n\t{\"__setstate__\", (PyCFunction) array_setstate, 1, doc_setstate},\n\t{\"dumps\", (PyCFunction) array_dumps, 1, doc_dumps},\n\t{\"dump\", (PyCFunction) array_dump, 1, doc_dump},\n\n\t/* Extended methods added 2005 */\n\t{\"fill\", (PyCFunction)array_fill,\n\t METH_VARARGS, doc_fill},\n\t{\"transpose\",\t(PyCFunction)array_transpose, \n\t METH_VARARGS, doc_transpose},\n\t{\"take\",\t(PyCFunction)array_take, \n\t METH_VARARGS|METH_KEYWORDS, doc_take},\n\t{\"put\",\t(PyCFunction)array_put, \n\t METH_VARARGS|METH_KEYWORDS, doc_put},\n\t{\"putmask\",\t(PyCFunction)array_putmask, \n\t METH_VARARGS|METH_KEYWORDS, doc_putmask},\n\t{\"repeat\",\t(PyCFunction)array_repeat, \n\t METH_VARARGS|METH_KEYWORDS, doc_repeat},\n\t{\"choose\",\t(PyCFunction)array_choose, \n\t METH_VARARGS, doc_choose},\t\n\t{\"sort\",\t(PyCFunction)array_sort, \n\t METH_VARARGS|METH_KEYWORDS, doc_sort},\n\t{\"argsort\",\t(PyCFunction)array_argsort, \n\t METH_VARARGS|METH_KEYWORDS, doc_argsort},\n\t{\"searchsorted\", (PyCFunction)array_searchsorted, \n\t METH_VARARGS, doc_searchsorted},\t\n\t{\"argmax\",\t(PyCFunction)array_argmax, \n\t METH_VARARGS|METH_KEYWORDS, doc_argmax},\n\t{\"argmin\", (PyCFunction)array_argmin,\n\t METH_VARARGS|METH_KEYWORDS, 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|METH_KEYWORDS, doc_max},\n\t{\"min\", (PyCFunction)array_min,\n\t METH_VARARGS|METH_KEYWORDS, doc_min},\n\t{\"ptp\", (PyCFunction)array_ptp,\n\t METH_VARARGS|METH_KEYWORDS, doc_ptp},\n\t{\"mean\", (PyCFunction)array_mean,\n\t METH_VARARGS|METH_KEYWORDS, doc_mean},\n\t{\"trace\", (PyCFunction)array_trace,\n\t METH_VARARGS|METH_KEYWORDS, doc_trace},\n\t{\"diagonal\", (PyCFunction)array_diagonal,\n\t METH_VARARGS|METH_KEYWORDS, doc_diagonal},\n\t{\"clip\", (PyCFunction)array_clip,\n\t METH_VARARGS|METH_KEYWORDS, doc_clip},\n\t{\"conj\", (PyCFunction)array_conjugate,\n\t METH_VARARGS, doc_conj},\n\t{\"conjugate\", (PyCFunction)array_conjugate,\n\t METH_VARARGS, doc_conjugate},\n\t{\"nonzero\", (PyCFunction)array_nonzero,\n\t METH_VARARGS, doc_nonzero},\n\t{\"std\", (PyCFunction)array_stddev,\n\t METH_VARARGS|METH_KEYWORDS, doc_stddev},\n\t{\"var\", (PyCFunction)array_variance,\n\t METH_VARARGS|METH_KEYWORDS, doc_variance},\n\t{\"sum\", (PyCFunction)array_sum,\n\t METH_VARARGS|METH_KEYWORDS, doc_sum},\n\t{\"cumsum\", (PyCFunction)array_cumsum,\n\t METH_VARARGS|METH_KEYWORDS, doc_cumsum},\n\t{\"prod\", (PyCFunction)array_prod,\n\t METH_VARARGS|METH_KEYWORDS, doc_prod},\n\t{\"cumprod\", (PyCFunction)array_cumprod,\n\t METH_VARARGS|METH_KEYWORDS, doc_cumprod},\n\t{\"all\", (PyCFunction)array_all,\n\t METH_VARARGS|METH_KEYWORDS, doc_all},\n\t{\"any\", (PyCFunction)array_any,\n\t METH_VARARGS|METH_KEYWORDS, 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{\"round\", (PyCFunction)array_round,\n\t METH_VARARGS|METH_KEYWORDS, doc_round},\n\t{\"setflags\", (PyCFunction)array_setflags,\n\t METH_VARARGS|METH_KEYWORDS, doc_setflags},\n\t{\"newbyteorder\", (PyCFunction)array_newbyteorder,\n\t METH_VARARGS, doc_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n#undef _ARET\n\n\n", + "source_code_before": "\n/* Should only be used if x is known to be an nd-array */\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_take[] = \"a.take(indices, axis=None). Selects the elements \"\\\n\t\"in indices from array a along the given axis.\";\n\nstatic PyObject *\narray_take(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint dimension=MAX_DIMS;\n\tPyObject *indices;\n\tstatic char *kwlist[] = {\"indices\", \"axis\", NULL};\n\t\n\tdimension=0;\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &indices, PyArray_AxisConverter,\n\t\t\t\t\t &dimension))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Take(self, indices, dimension));\n}\n\nstatic char doc_fill[] = \"a.fill(value) places the scalar value at every \"\\\n\t\"position in the array.\";\n\nstatic PyObject *\narray_fill(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *obj;\n\tif (!PyArg_ParseTuple(args, \"O\", &obj))\n\t\treturn NULL;\n\tif (PyArray_FillWithScalar(self, obj) < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_put[] = \"a.put(values, indices) sets a.flat[n] = v[n] \"\\\n\t\"for each n in indices. v can be scalar or shorter than indices, \"\\\n\t\"will repeat.\";\n\nstatic PyObject *\narray_put(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *indices, *values;\n\tstatic char *kwlist[] = {\"values\", \"indices\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &values, &indices))\n\t\treturn NULL;\n\treturn PyArray_Put(self, values, indices);\n}\n\nstatic char doc_putmask[] = \"a.putmask(values, mask) sets a.flat[n] = v[n] \"\\\n\t\"for each n where mask.flat[n] is TRUE. v can be scalar.\";\n\nstatic PyObject *\narray_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *mask, *values;\n\n\tstatic char *kwlist[] = {\"values\", \"mask\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &values, &mask))\n\t\treturn NULL;\n\treturn PyArray_PutMask(self, values, mask);\n}\n\n/* Used to reshape a Fortran Array */\nstatic void\n_reverse_shape(PyArray_Dims *newshape)\n{\n\tint i, n = newshape->len;\n\tintp *ptr = newshape->ptr;\n\tintp *eptr;\n\tintp tmp;\n\tint len = n >> 1;\n\n\teptr = ptr+n-1;\n\tfor(i=0; i) return a new view of array with same data. type can be either a new sub-type object or a data-descriptor object\";\n\nstatic PyObject *\narray_view(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *otype=NULL;\n PyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTuple(args, \"|O\", &otype)) return NULL;\n\n\tif (otype) {\n\t\tif (PyType_Check(otype) &&\t\t\t\\\n\t\t PyType_IsSubtype((PyTypeObject *)otype, \n\t\t\t\t &PyArray_Type)) {\n\t\t\treturn PyArray_View(self, NULL, \n (PyTypeObject *)otype);\n }\n\t\telse {\n\t\t\tif (PyArray_DescrConverter(otype, &type) == PY_FAIL) \n\t\t\t\treturn NULL;\n\t\t}\n\t}\n\treturn PyArray_View(self, type, NULL);\n}\n\nstatic char doc_argmax[] = \"a.argmax(axis=None)\";\n\nstatic PyObject *\narray_argmax(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\n\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\n\t\n\treturn PyArray_Min(self, axis);\n}\n\nstatic char doc_swapaxes[] = \"a.swapaxes(axis1, axis2) returns new view with axes swapped.\";\n\nstatic PyObject *\narray_swapaxes(PyArrayObject *self, PyObject *args)\n{\n\tint axis1, axis2;\n\n\tif (!PyArg_ParseTuple(args, \"ii\", &axis1, &axis2)) return NULL;\n\n\treturn PyArray_SwapAxes(self, axis1, axis2);\n}\n\nstatic char doc_getfield[] = \"m.getfield(dtype, offset) returns a field \"\\\n\t\" of the given array as a certain type. A field is a view of \"\\\n\t\" the array's data with each itemsize determined by the given type\"\\\n\t\" and the offset into the current array.\";\n\n/* steals typed reference */\n/*OBJECT_API\n Get a subset of bytes from each element of the array\n*/\nstatic PyObject *\nPyArray_GetField(PyArrayObject *self, PyArray_Descr *typed, int offset)\n{\n\tPyObject *ret=NULL;\n\n\tif (offset < 0 || (offset + typed->elsize) > self->descr->elsize) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need 0 <= offset <= %d for requested type \" \\\n\t\t\t \"but received offset = %d\",\n\t\t\t self->descr->elsize-typed->elsize, offset);\n\t\tPy_DECREF(typed);\n\t\treturn NULL;\n\t}\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t typed,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, \n\t\t\t\t self->data + offset,\n\t\t\t\t self->flags, (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self; \n\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\treturn ret;\n}\n\nstatic PyObject *\narray_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\n PyArray_Descr *dtype;\n\tint offset = 0;\n\tstatic char *kwlist[] = {\"dtype\", \"offset\", 0};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|i\", kwlist,\n\t\t\t\t\t PyArray_DescrConverter,\n\t\t\t\t\t &dtype, &offset)) return NULL;\n\t\n\treturn _ARET(PyArray_GetField(self, dtype, offset));\n}\n\n\nstatic char doc_setfield[] = \"m.setfield(value, dtype, offset) places val \"\\\n\t\"into field of the given array defined by the data type and offset.\";\n\n/*OBJECT_API\n Set a subset of bytes from each element of the array\n*/\nstatic int\nPyArray_SetField(PyArrayObject *self, PyArray_Descr *dtype,\n\t\t int offset, PyObject *val)\n{\n\tPyObject *ret=NULL;\n\tint retval = 0;\n \n\tif (offset < 0 || (offset + dtype->elsize) > self->descr->elsize) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need 0 <= offset <= %d for requested type \" \\\n\t\t\t \"but received offset = %d\",\n\t\t\t self->descr->elsize-dtype->elsize, offset);\n\t\tPy_DECREF(dtype);\n\t\treturn -1;\n\t}\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t dtype, self->nd, self->dimensions,\n\t\t\t\t self->strides, self->data + offset,\n\t\t\t\t self->flags, (PyObject *)self);\n\tif (ret == NULL) return -1;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self;\n\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\t\n\tretval = PyArray_CopyObject((PyArrayObject *)ret, val);\n\tPy_DECREF(ret);\n\treturn retval;\n}\n\nstatic PyObject *\narray_setfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n PyArray_Descr *dtype;\n\tint offset = 0;\n\tPyObject *value;\n\tstatic char *kwlist[] = {\"value\", \"dtype\", \"offset\", 0};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO&|i\", kwlist,\n\t\t\t\t\t &value, PyArray_DescrConverter,\n\t\t\t\t\t &dtype, &offset)) return NULL;\n\n\tif (PyArray_SetField(self, dtype, offset, value) < 0)\n\t\treturn NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n/* This doesn't change the descriptor just the actual data...\n */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_Byteswap(PyArrayObject *self, Bool inplace)\n{\n PyArrayObject *ret;\n\tintp size;\n\tPyArray_CopySwapNFunc *copyswapn;\n\tPyArray_CopySwapFunc *copyswap;\n\tPyArrayIterObject *it;\n\n\tif (inplace) {\n\t\tcopyswapn = self->descr->f->copyswapn;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\t\tif (PyArray_ISONESEGMENT(self)) {\n\t\t\tcopyswapn(self->data, NULL, size, 1, \n\t\t\t\t self->descr->elsize);\n\t\t}\n\t\telse { /* Use iterator */\n\t\t\t\n\t\t\tit = (PyArrayIterObject *)\\\n\t\t\t\tPyArray_IterNew((PyObject *)self);\n\t\t\tcopyswap = self->descr->f->copyswap;\n\t\t\twhile (it->index < it->size) {\n\t\t\t\tcopyswap(it->dataptr, NULL, 1, \n\t\t\t\t\t self->descr->elsize);\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t}\n\t\t\tPy_DECREF(it);\n\t\t}\n\t\t\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tif ((ret = (PyArrayObject *)PyArray_NewCopy(self,-1)) == NULL) \n\t\t\treturn NULL;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\n\t\t/* now ret has the same dtypedescr as self (including\n\t\t byteorder)\n\t\t*/\n\n\t\tret->descr->f->copyswapn(ret->data, NULL, size, 1, \n\t\t\t\t\t ret->descr->elsize);\n\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic char doc_byteswap[] = \"m.byteswap(False) Swap the bytes in\"\\\n\t\" the array. Return the byteswapped array. If the first argument\"\\\n\t\" is TRUE, byteswap in-place and return a reference to self.\";\n\nstatic PyObject *\narray_byteswap(PyArrayObject *self, PyObject *args) \n{\n\tBool inplace=FALSE;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter, &inplace))\n\t\treturn NULL;\n\t\n\treturn PyArray_Byteswap(self, inplace);\n}\n\nstatic char doc_tolist[] = \"m.tolist().\t Copy the data portion of the array\"\\\n\t\" to a hierarchical python list and return that list.\";\n\nstatic PyObject *\narray_tolist(PyArrayObject *self, PyObject *args) \n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n if (self->nd <= 0) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"can't convert a 0-d array to a list\");\n return NULL;\n }\n\t\n return PyArray_ToList(self);\n}\n\nstatic char doc_tostring[] = \"m.tostring() Construct a Python string \"\\\n \"containing the raw bytes in the array\";\n\nstatic PyObject *\narray_tostring(PyArrayObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n return PyArray_ToString(self);\n}\n\nstatic char doc_tofile[] = \"m.tofile(fid, sep=\"\") write the data to a file.\";\n\nstatic PyObject *\narray_tofile(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tint ret;\n PyObject *file;\n\tFILE *fd;\n char *sep=\"\";\n\tchar *format=\"\";\n\tchar *mode=\"\";\n\tstatic char *kwlist[] = {\"file\", \"sep\", \"format\", NULL};\n \n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ss\", kwlist, \n &file, &sep, &format)) return NULL;\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"wb\";\n\t\telse mode=\"w\";\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), mode);\n\t\tif (file==NULL) return NULL;\n\t}\n\telse {\n\t\tPy_INCREF(file);\n\t}\n\tfd = PyFile_AsFile(file);\n\tif (fd == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \"first argument must be a \" \\\n\t\t\t\t\"string or open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_ToFile(self, fd, sep, format);\n\tPy_DECREF(file);\n\tif (ret < 0) return NULL;\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_toscalar[] = \"m.item(). Copy the first data point of \"\\\n\t\"the array to a standard Python scalar and return it.\";\n\nstatic PyObject *\narray_toscalar(PyArrayObject *self, PyObject *args) {\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\tif (self->nd == 0 || PyArray_SIZE(self) == 1) \n\t\treturn self->descr->f->getitem(self->data, self);\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError, \"can only convert an\"\t\\\n\t\t\t\t\" array of size 1 to Python scalar.\");\n\t\treturn NULL;\n\t}\n}\n\nstatic char doc_cast[] = \"m.astype(t).\tCast array m to type t.\t \\n\\n\"\\\n\t\"t can be either a string representing a typecode, or a python type\"\\\n\t\" object of type int, float, or complex.\";\n\nstatic PyObject *\narray_cast(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Descr *descr=NULL;\n\tPyObject *obj;\n\t\n if (!PyArg_ParseTuple(args, \"O&\", PyArray_DescrConverter,\n\t\t\t &descr)) return NULL;\n\t\n\tif (descr == self->descr) {\n\t\tobj = _ARET(PyArray_NewCopy(self,0));\n\t\tPy_XDECREF(descr);\n\t\treturn obj;\n\t}\n\treturn _ARET(PyArray_CastToType(self, descr, 0));\n}\t \n\n/* default sub-type implementation */\n\nstatic char doc_wraparray[] = \"m.__array_wrap__(obj) returns an object of \"\\\n\t\"type m from the ndarray object obj\";\n\nstatic PyObject *\narray_wraparray(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *arr;\n\tPyObject *ret;\n\t\n\tif (PyTuple_Size(args) < 1) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"only accepts 1 argument\");\n\t\treturn NULL;\n\t}\n\tarr = PyTuple_GET_ITEM(args, 0);\n\tif (!PyArray_Check(arr)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"can only be called with ndarray object\");\n\t\treturn NULL;\n\t}\t\n\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t PyArray_NDIM(arr),\n\t\t\t\t PyArray_DIMS(arr), \n\t\t\t\t PyArray_STRIDES(arr), PyArray_DATA(arr),\n\t\t\t\t PyArray_FLAGS(arr), (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(arr);\n\tPyArray_BASE(ret) = arr;\n\treturn ret;\n}\n\n/* NO-OP --- just so all subclasses will have one by default. */\nstatic PyObject *\narray_finalize(PyArrayObject *self, PyObject *args)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic char doc_array_getarray[] = \"m.__array__(|dtype) just returns either a new reference to self if dtype is not given or a new array of provided data type if dtype is different from the current dtype of the array.\";\n\nstatic PyObject *\narray_getarray(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Descr *newtype=NULL;\n\tPyObject *ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_DescrConverter,\n\t\t\t &newtype)) return NULL;\n\t\n\t/* convert to PyArray_Type */\n\tif (!PyArray_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 = &PyArray_Type;\n\t\t}\n\t\t\n\t\tPy_INCREF(PyArray_DESCR(self));\n\t\tnew = PyArray_NewFromDescr(subtype, \n\t\t\t\t\t PyArray_DESCR(self),\n\t\t\t\t\t PyArray_NDIM(self),\n\t\t\t\t\t PyArray_DIMS(self), \n\t\t\t\t\t PyArray_STRIDES(self), \n\t\t\t\t\t PyArray_DATA(self),\n\t\t\t\t\t PyArray_FLAGS(self), NULL);\n\t\tif (new == NULL) return NULL;\n\t\tPy_INCREF(self);\n\t\tPyArray_BASE(new) = (PyObject *)self;\n\t\tself = (PyArrayObject *)new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t}\n\t\t\n\tif ((newtype == NULL) || \\\n\t PyArray_EquivTypes(self->descr, newtype)) {\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tret = PyArray_CastToType(self, newtype, 0);\n\t\tPy_DECREF(self);\n\t\treturn ret;\n\t}\n}\n\nstatic char doc_copy[] = \"m.copy(|fortran). Return a copy of the array.\\n\"\\\n\t\"If fortran == 0 then the result is contiguous (default). \\n\"\\\n\t\"If fortran > 0 then the result has fortran data order. \\n\"\\\n\t\"If fortran < 0 then the result has fortran data order only if m\\n\"\n\t\" is already in fortran order.\";\n\nstatic PyObject *\narray_copy(PyArrayObject *self, PyObject *args) \n{\n\tint fortran=0;\n if (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n\t\n return PyArray_NewCopy(self, fortran);\n}\n\nstatic char doc_resize[] = \"self.resize(new_shape, refcheck=True). \"\\\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, PyObject *kwds) \n{\n PyArray_Dims newshape;\n PyObject *ret;\n\tint n;\n\tint refcheck = 1;\n\t\n\tif (kwds != NULL) {\n\t\tPyObject *ref;\n\t\tref = PyDict_GetItemString(kwds, \"refcheck\");\n\t\tif (ref) {\n\t\t\trefcheck = PyInt_AsLong(ref);\n\t\t\tif (refcheck==-1 && PyErr_Occurred()) {\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\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\t\n\tret = PyArray_Resize(self, &newshape, refcheck);\n PyDimMem_FREE(newshape.ptr);\n if (ret == NULL) return NULL;\n\tPy_DECREF(ret);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_repeat[] = \"a.repeat(repeats=, axis=None)\\n\"\\\n\t\"\\n\"\\\n\t\" Copy elements of a, repeats times. The repeats argument must\\n\"\\\n\t\" be a sequence of length a.shape[axis] or a scalar.\";\n\nstatic PyObject *\narray_repeat(PyArrayObject *self, PyObject *args, PyObject *kwds) {\n\tPyObject *repeats;\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"repeats\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &repeats, PyArray_AxisConverter,\n\t\t\t\t\t &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_Repeat(self, repeats, axis));\n}\n\nstatic char doc_choose[] = \"a.choose(b0, b1, ..., bn)\\n\"\\\n\t\"\\n\"\\\n\t\"Return an array with elements chosen from 'a' at the positions\\n\"\\\n \"of the given arrays b_i. The array 'a' should be an integer array\\n\"\\\n \"with entries from 0 to n+1, and the b_i arrays should have the same\\n\"\\\n \"shape as 'a'.\";\n\nstatic PyObject *\narray_choose(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *choices;\n\tint n;\n\t\n\tn = PyTuple_Size(args);\n\tif (n <= 1) {\n\t\tif (!PyArg_ParseTuple(args, \"O\", &choices))\n\t\t\treturn NULL;\n\t}\n else {\n\t\tchoices = args;\n\t}\n\t\n\treturn _ARET(PyArray_Choose(self, choices));\n}\n\nstatic char doc_sort[] = \"a.sort(axis=-1,kind='quicksort') sorts in place along axis. Return is None and kind can be 'quicksort', 'mergesort', or 'heapsort'\";\n\nstatic PyObject *\narray_sort(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=-1;\n\tint val;\n\tPyArray_SORTKIND which=PyArray_QUICKSORT;\n\tstatic char *kwlist[] = {\"axis\", \"kind\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iO&\", kwlist, &axis,\n\t\t\t\t\t PyArray_SortkindConverter, &which))\n\t\treturn NULL;\n\t\n\tval = PyArray_Sort(self, axis, which);\n\tif (val < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_argsort[] = \"a.argsort(axis=-1,kind='quicksort')\\n\"\\\n\t\" Return the indexes into a that would sort it along the\"\\\n\t\" given axis; kind can be 'quicksort', 'mergesort', or 'heapsort'\";\n\nstatic PyObject *\narray_argsort(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=-1;\n\tPyArray_SORTKIND which=PyArray_QUICKSORT;\n\tstatic char *kwlist[] = {\"axis\", \"kind\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iO&\", kwlist, &axis,\n\t\t\t\t\t PyArray_SortkindConverter, &which))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_ArgSort(self, axis, which));\n}\n\nstatic char doc_searchsorted[] = \"a.searchsorted(v)\\n\"\\\n\t\" Assuming that a is a 1-D array, in ascending order and\\n\"\\\n\t\" represents bin boundaries, then a.searchsorted(values) gives an\\n\"\\\n\t\" array of bin numbers, giving the bin into which each value would\\n\"\\\n\t\" be placed. This method is helpful for histograming. \\n\"\\\n\t\" Note: No warning is given if the boundaries, in a, are not \\n\"\\\n\t\" in ascending order.\";\n\nstatic PyObject *\narray_searchsorted(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *values;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &values)) return NULL;\n\t\n\treturn _ARET(PyArray_SearchSorted(self, values));\n}\n\nstatic char doc_deepcopy[] = \"Used if copy.deepcopy is called on an array.\";\n\nstatic PyObject *\narray_deepcopy(PyArrayObject *self, PyObject *args) \n{\n PyObject* visit;\n PyObject **optr;\n PyArrayIterObject *it;\n PyObject *copy, *ret, *deepcopy, *temp, *res;\n\n if (!PyArg_ParseTuple(args, \"O\", &visit)) return NULL;\n ret = PyArray_Copy(self);\n if (PyArray_ISOBJECT(self)) {\n copy = PyImport_ImportModule(\"copy\");\n if (copy == NULL) return NULL;\n deepcopy = PyObject_GetAttrString(copy, \"deepcopy\");\n Py_DECREF(copy);\n if (deepcopy == NULL) return NULL;\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it == NULL) {Py_DECREF(deepcopy); return NULL;}\n optr = (PyObject **)PyArray_DATA(ret);\n while(it->index < it->size) {\n temp = *((PyObject **)it->dataptr);\n Py_INCREF(temp);\n /* call deepcopy on this argument */\n res = PyObject_CallFunctionObjArgs(deepcopy, \n temp, visit, NULL);\n Py_DECREF(temp);\n Py_DECREF(*optr);\n *optr++ = res;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(deepcopy);\n Py_DECREF(it);\n }\n return _ARET(ret);\n}\n\n/* Convert Object Array to flat list and pickle the flat list string */\nstatic PyObject *\n_getobject_pkl(PyArrayObject *self)\n{\n\tPyObject *theobject;\n\tPyArrayIterObject *iter=NULL;\n\tPyObject *list;\n\n\t\n\titer = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (iter == NULL) return NULL;\n\tlist = PyList_New(iter->size);\n\tif (list == NULL) {Py_DECREF(iter); return NULL;}\n\twhile (iter->index < iter->size) {\n\t\ttheobject = *((PyObject **)iter->dataptr);\n\t\tPy_INCREF(theobject);\n\t\tPyList_SET_ITEM(list, (int) iter->index, theobject);\n\t\tPyArray_ITER_NEXT(iter);\n\t}\n\tPy_DECREF(iter);\n\treturn list;\n}\n\nstatic int\n_setobject_pkl(PyArrayObject *self, PyObject *list)\n{\n\tPyObject *theobject;\n\tPyArrayIterObject *iter=NULL;\n\tint size;\n\n\tsize = self->descr->elsize;\n\t\n\titer = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (iter == NULL) return -1;\n\twhile(iter->index < iter->size) {\n\t\ttheobject = PyList_GET_ITEM(list, (int) iter->index);\n\t\tPy_INCREF(theobject);\n\t\t*((PyObject **)iter->dataptr) = theobject;\n\t\tPyArray_ITER_NEXT(iter);\n\t}\n\tPy_XDECREF(iter);\n\treturn 0;\n}\n\nstatic char doc_reduce[] = \"a.__reduce__() for pickling.\";\n\nstatic PyObject *\narray_reduce(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *ret=NULL, *state=NULL, *obj=NULL, *mod=NULL;\n\tPyObject *mybool, *thestr=NULL;\n\tPyArray_Descr *descr;\n\n\t/* Return a tuple of (callable object, arguments, object's state) */\n\t/* We will put everything in the object's state, so that on UnPickle\n\t it can use the string object as memory without a copy */\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core._internal\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"_reconstruct\");\n\tPy_DECREF(mod);\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t Py_BuildValue(\"ONN\",\n\t\t\t\t (PyObject *)self->ob_type,\n\t\t\t\t Py_BuildValue(\"(N)\",\n\t\t\t\t\t\t PyInt_FromLong(0)),\n\t\t\t\t PyObject_GetAttrString((PyObject *)(self->descr),\n\t\t\t\t\t\t\t \"char\")));\n\t\n\t/* Now fill in object's state. This is a tuple with \n\t 4 arguments\n\n\t 1) a Tuple giving the shape\n\t 2) a PyArray_Descr Object (with correct bytorder set)\n\t 3) a Bool stating if Fortran or not\n\t 4) a binary string with the data (or a list for Object arrays)\n\n\t Notice because Python does not describe a mechanism to write \n\t raw data to the pickle, this performs a copy to a string first\n\t*/\n\n\tstate = PyTuple_New(4);\n\tif (state == NULL) {\n\t\tPy_DECREF(ret); return NULL;\n\t}\n\tPyTuple_SET_ITEM(state, 0, PyObject_GetAttrString((PyObject *)self, \n\t\t\t\t\t\t\t \"shape\"));\n\tdescr = self->descr;\n\tPy_INCREF(descr);\n\tPyTuple_SET_ITEM(state, 1, (PyObject *)descr);\n\tmybool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);\n\tPy_INCREF(mybool);\n\tPyTuple_SET_ITEM(state, 2, mybool);\n\tif (PyArray_ISOBJECT(self)) {\n\t\tthestr = _getobject_pkl(self);\n\t}\n\telse {\n thestr = PyArray_ToString(self);\n\t}\n\tif (thestr == NULL) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(state);\n\t\treturn NULL;\n\t}\n\tPyTuple_SET_ITEM(state, 3, thestr);\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\nstatic char doc_setstate[] = \"a.__setstate__(tuple) for unpickling.\";\n\n/*\n\t 1) a Tuple giving the shape\n\t 2) a PyArray_Descr Object\n\t 3) a Bool stating if Fortran or not\n\t 4) a binary string with the data (or a list if Object array) \n*/\n\nstatic intp _array_fill_strides(intp *, intp *, int, intp, int, int *);\n\nstatic int _IsAligned(PyArrayObject *); \n\nstatic PyArray_Descr * _array_typedescr_fromstr(char *);\n\nstatic PyObject *\narray_setstate(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *shape;\n\tPyArray_Descr *typecode;\n\tint fortran;\n\tPyObject *rawdata;\n\tchar *datastr;\n\tint len;\n\tintp dimensions[MAX_DIMS];\n\tint nd;\n\t\n\t/* This will free any memory associated with a and\n\t use the string in setstate as the (writeable) memory.\n\t*/\n\tif (!PyArg_ParseTuple(args, \"(O!O!iO)\", &PyTuple_Type,\n\t\t\t &shape, &PyArrayDescr_Type, &typecode, \n\t\t\t &fortran, &rawdata))\n\t\treturn NULL;\n\n\tPy_XDECREF(self->descr);\n\tself->descr = typecode;\n\tPy_INCREF(typecode);\n\tnd = PyArray_IntpFromSequence(shape, dimensions, MAX_DIMS);\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (!PyList_Check(rawdata)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"object pickle not returning list\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tif (!PyString_Check(rawdata)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"pickle not returning string\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (PyString_AsStringAndSize(rawdata, &datastr, &len))\n\t\t\treturn NULL;\n\n\t\tif ((len != (self->descr->elsize *\t\t\t\\\n\t\t\t (int) PyArray_MultiplyList(dimensions, nd)))) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size does not\"\t\\\n\t\t\t\t\t\" match array size\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n if ((self->flags & OWN_DATA)) {\n\t\tif (self->data != NULL)\n\t\t\tPyDataMem_FREE(self->data);\n\t\tself->flags &= ~OWN_DATA;\n }\n\tPy_XDECREF(self->base);\n\n\tself->flags &= ~UPDATEIFCOPY;\n\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t\tself->dimensions = NULL;\n\t}\n\n\tself->flags = DEFAULT_FLAGS;\n\n\tself->nd = nd;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(nd * 2);\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dimensions, sizeof(intp)*nd);\n\t\t(void) _array_fill_strides(self->strides, dimensions, nd,\n\t\t\t\t\t self->descr->elsize, \n (fortran ? FORTRAN : CONTIGUOUS),\n\t\t\t\t\t &(self->flags));\n\t}\n\n\tif (typecode->type_num != PyArray_OBJECT) {\n\t\tself->data = datastr;\n\t\tif (!_IsAligned(self)) {\n\t\t\tintp num = PyArray_NBYTES(self);\n\t\t\tself->data = PyDataMem_NEW(num);\n\t\t\tif (self->data == NULL) {\n\t\t\t\tself->nd = 0;\n\t\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemcpy(self->data, datastr, num);\n\t\t\tself->flags |= OWN_DATA;\n\t\t\tself->base = NULL;\n\t\t}\n\t\telse {\n\t\t\tself->base = rawdata;\n\t\t\tPy_INCREF(self->base);\n\t\t}\n\t}\n\telse {\n\t\tself->data = PyDataMem_NEW(PyArray_NBYTES(self));\n\t\tif (self->data == NULL) { \n\t\t\tself->nd = 0;\n\t\t\tself->data = PyDataMem_NEW(self->descr->elsize);\n\t\t\tif (self->dimensions) PyDimMem_FREE(self->dimensions);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\t\tself->base = NULL;\n\t\tif (_setobject_pkl(self, rawdata) < 0) \n\t\t\treturn NULL;\n\t}\n\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\t\n}\n\n/*OBJECT_API*/\nstatic int\nPyArray_Dump(PyObject *self, PyObject *file, int protocol)\n{\n\tPyObject *cpick=NULL;\n\tPyObject *ret;\n\tif (protocol < 0) protocol = 2;\n\n\tcpick = PyImport_ImportModule(\"cPickle\");\n\tif (cpick==NULL) return -1;\n\n\tif PyString_Check(file) {\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), \"wb\");\n\t\tif (file==NULL) return -1;\n\t}\n\telse Py_INCREF(file);\n\tret = PyObject_CallMethod(cpick, \"dump\", \"OOi\", self, \n\t\t\t\t file, protocol);\n\tPy_XDECREF(ret);\n\tPy_DECREF(file);\n\tPy_DECREF(cpick);\n\tif (PyErr_Occurred()) return -1;\n\treturn 0;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_Dumps(PyObject *self, int protocol)\n{\n\tPyObject *cpick=NULL;\n\tPyObject *ret;\n\tif (protocol < 0) protocol = 2;\n\n\tcpick = PyImport_ImportModule(\"cPickle\");\n\tif (cpick==NULL) return NULL;\n\tret = PyObject_CallMethod(cpick, \"dumps\", \"Oi\", self, protocol);\n\tPy_DECREF(cpick);\n\treturn ret;\n}\n\n\nstatic char doc_dump[] = \"m.dump(file)\";\n\nstatic PyObject *\narray_dump(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *file=NULL;\n\tint ret;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &file))\n\t\treturn NULL;\n\tret = PyArray_Dump((PyObject *)self, file, 2);\n\tif (ret < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_dumps[] = \"m.dumps()\";\n\nstatic PyObject *\narray_dumps(PyArrayObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\"))\n\t\treturn NULL;\n\treturn PyArray_Dumps((PyObject *)self, 2);\n}\n\n\nstatic char doc_transpose[] = \"m.transpose()\";\n\nstatic PyObject *\narray_transpose(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *shape=Py_None;\n\tint n;\n\tPyArray_Dims permute;\n\tPyObject *ret;\n\n\tn = PyTuple_Size(args);\n\tif (n > 1) shape = args;\n\telse if (n == 1) shape = PyTuple_GET_ITEM(args, 0);\n\t\n\tif (shape == Py_None)\n\t\tret = PyArray_Transpose(self, NULL);\n\telse {\n\t\tif (!PyArray_IntpConverter(shape, &permute)) return NULL;\n\t\tret = PyArray_Transpose(self, &permute);\n\t\tPyDimMem_FREE(permute.ptr);\n\t}\n\t\n\treturn _ARET(ret);\n}\n\nstatic char doc_mean[] = \"a.mean(axis=None, dtype=None)\\n\\n\"\\\n \"Average the array over the given axis. If the axis is None, average\\n\"\\\n \"over all dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, dtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\\n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, dtype) * 1.0 / product(a.shape)\\n\"\\\n \"\\n\"\\\n \"The optional dtype argument is the data type for intermediate\\n\"\\\n \"calculations in the sum.\";\n\n#define _CHKTYPENUM(typ) ((typ) ? (typ)->type_num : PyArray_NOTYPE)\n\nstatic PyObject *\narray_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist,\n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\n\treturn PyArray_Mean(self, axis, _CHKTYPENUM(dtype));\n}\n\nstatic char doc_sum[] = \"a.sum(axis=None, dtype=None)\\n\\n\"\\\n \"Sum the array over the given axis. If the axis is None, sum over all\\n\"\\\n \"dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"The optional dtype argument is the data type for the returned value\\n\"\\\n \"and intermediate calculations. The default is to upcast (promote)\\n\"\\\n \"smaller integer types to the platform-dependent int. For example, on\\n\"\\\n \"32-bit platforms:\\n\"\\\n \"\\n\"\\\n \" a.dtype default sum() dtype\\n\"\\\n \" ---------------------------------------------------\\n\"\\\n \" bool, int8, int16, int32 int32\\n\"\\\n \"\\n\"\\\n \"Examples:\\n\"\\\n \"\\n\"\\\n \">>> array([0.5, 1.5]).sum()\\n\"\\\n \"2.0\\n\"\\\n \">>> array([0.5, 1.5]).sum(dtype=int32)\\n\"\\\n \"1\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum(axis=0)\\n\"\\\n \"array([0, 6])\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum(axis=1)\\n\"\\\n \"array([1, 5])\";\n\nstatic PyObject *\narray_sum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Sum(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_cumsum[] = \"a.cumsum(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_CumSum(self, axis, _CHKTYPENUM(dtype));\n}\n\nstatic char doc_prod[] = \"a.prod(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Prod(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_cumprod[] = \"a.cumprod(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_CumProd(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_any[] = \"a.any(axis=None)\";\n\nstatic PyObject *\narray_any(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\n\n\treturn PyArray_All(self, axis);\n}\n\nstatic char doc_stddev[] = \"a.std(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, _CHKTYPENUM(dtype), 0);\n}\n\nstatic char doc_variance[] = \"a.var(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_variance(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, _CHKTYPENUM(dtype), 1);\n}\n\nstatic char doc_compress[] = \"a.compress(condition=, axis=None)\";\n\nstatic PyObject *\narray_compress(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyObject *condition;\t\n\tstatic char *kwlist[] = {\"condition\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &condition, PyArray_AxisConverter,\n\t\t\t\t\t &axis)) return NULL;\n\n\treturn _ARET(PyArray_Compress(self, condition, axis));\n}\n\nstatic char doc_nonzero[] = \"a.nonzero() return a tuple of indices referencing \"\\\n\t\"the elements of a that are nonzero.\";\n\nstatic PyObject *\narray_nonzero(PyArrayObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\treturn _ARET(PyArray_Nonzero(self));\n}\n\n\nstatic char doc_trace[] = \"a.trace(offset=0, axis1=0, axis2=1, dtype=None)\\n\"\\\n\t\"return the sum along the offset diagonal of the arrays indicated\\n\" \\\n\t\"axis1 and axis2.\";\n\nstatic PyObject *\narray_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iiiO&\", kwlist, \n\t\t\t\t\t &offset, &axis1, &axis2,\n\t\t\t\t\t PyArray_DescrConverter2, &dtype))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Trace(self, offset, axis1, axis2, \n\t\t\t\t _CHKTYPENUM(dtype)));\n}\n\n#undef _CHKTYPENUM\n\n\nstatic char doc_clip[] = \"a.clip(min=, max=)\";\n\nstatic PyObject *\narray_clip(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *min, *max;\n\tstatic char *kwlist[] = {\"min\", \"max\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &min, &max)) \n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Clip(self, min, max));\n}\n\nstatic char doc_conj[] = \"a.conj()\";\n\nstatic char doc_conjugate[] = \"a.conjugate()\";\n\nstatic PyObject *\narray_conjugate(PyArrayObject *self, PyObject *args) \n{\n\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n\treturn PyArray_Conjugate(self);\n}\n\n\nstatic char doc_diagonal[] = \"a.diagonal(offset=0, axis1=0, axis2=1)\";\n\nstatic PyObject *\narray_diagonal(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iii\", kwlist, \n\t\t\t\t\t &offset, &axis1, &axis2))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Diagonal(self, offset, axis1, axis2));\n}\n\nstatic char doc_flatten[] = \"a.flatten([fortran]) return a 1-d array (always copy)\";\n\nstatic PyObject *\narray_flatten(PyArrayObject *self, PyObject *args)\n{\n\tint fortran=0;\n\n\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n \n\treturn PyArray_Flatten(self, (int) fortran);\n}\n\nstatic char doc_ravel[] = \"a.ravel([fortran]) return a 1-d array (copy only if needed)\";\n\nstatic PyObject *\narray_ravel(PyArrayObject *self, PyObject *args)\n{\n\tint fortran=0;\n\n\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n\n\treturn PyArray_Ravel(self, fortran);\n}\n\nstatic char doc_round[] = \"a.round(decimals=0)\";\n\nstatic PyObject *\narray_round(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint decimals = 0;\n\tstatic char *kwlist[] = {\"decimals\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|i\", kwlist,\n\t\t\t\t\t &decimals)) \n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Round(self, decimals));\n}\n\n\nstatic char doc_setflags[] = \"a.setflags(write=None, align=None, uic=None)\";\n\nstatic int _IsAligned(PyArrayObject *);\nstatic Bool _IsWriteable(PyArrayObject *);\n\nstatic PyObject *\narray_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"write\", \"align\", \"uic\", NULL};\n\tPyObject *write=Py_None;\n\tPyObject *align=Py_None;\n\tPyObject *uic=Py_None;\n\tint flagback = self->flags;\n\t\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|OOO\", kwlist,\n\t\t\t\t\t &write, &align, &uic))\n\t\treturn NULL;\n\n\tif (align != Py_None) {\n\t\tif (PyObject_Not(align)) self->flags &= ~ALIGNED;\n\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"cannot set aligned flag of mis-\"\\\n\t\t\t\t\t\"aligned array to True\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif (uic != Py_None) {\n if (PyObject_IsTrue(uic)) {\n\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY\" \\\n \"flag to True\");\n return NULL;\n }\n else {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n }\n \n if (write != Py_None) {\n if (PyObject_IsTrue(write)) \n\t\t\tif (_IsWriteable(self)) {\n\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tself->flags = flagback;\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"cannot set WRITEABLE \"\t\\\n\t\t\t\t\t\t\"flag to True of this \"\t\\\n\t\t\t\t\t\t\"array\");\t\t\\\n\t\t\t\treturn NULL;\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n \n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_newbyteorder[] = \"a.newbyteorder() is equivalent\\n\" \\\n\t\" to a.view(a.dtype.newbytorder())\\n\";\n\nstatic PyObject *\narray_newbyteorder(PyArrayObject *self, PyObject *args) \n{\n\tchar endian = PyArray_SWAP;\n\tPyArray_Descr *new;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\tnew = PyArray_DescrNewByteorder(self->descr, endian);\n\tif (!new) return NULL;\n\treturn PyArray_View(self, new, NULL);\n\n}\n\nstatic PyMethodDef array_methods[] = {\n {\"tolist\",\t (PyCFunction)array_tolist,\t1, doc_tolist},\n {\"item\", (PyCFunction)array_toscalar, METH_VARARGS, doc_toscalar},\n\t{\"tofile\", (PyCFunction)array_tofile, \n METH_VARARGS | METH_KEYWORDS, doc_tofile},\n {\"tostring\", (PyCFunction)array_tostring, METH_VARARGS, doc_tostring},\n {\"byteswap\", (PyCFunction)array_byteswap,\t1, doc_byteswap},\n {\"astype\", (PyCFunction)array_cast, 1, doc_cast},\n\t{\"getfield\", (PyCFunction)array_getfield, \n\t METH_VARARGS | METH_KEYWORDS, doc_getfield},\n\t{\"setfield\", (PyCFunction)array_setfield, \n\t METH_VARARGS | METH_KEYWORDS, doc_setfield},\n {\"copy\", (PyCFunction)array_copy, 1, doc_copy}, \n {\"resize\", (PyCFunction)array_resize, \n\t METH_VARARGS | METH_KEYWORDS, doc_resize}, \n\n\t/* for subtypes */\n\t{\"__array__\", (PyCFunction)array_getarray, 1, doc_array_getarray},\n\t{\"__array_wrap__\", (PyCFunction)array_wraparray, 1, doc_wraparray},\n\t/* default version so it is found... -- only used for subclasses */\n\t{\"__array_finalize__\", (PyCFunction)array_finalize, 1, NULL},\n\t\n\t\n\t/* for the copy module */\n {\"__copy__\", (PyCFunction)array_copy, 1, doc_copy},\t \n {\"__deepcopy__\", (PyCFunction)array_deepcopy, 1, doc_deepcopy}, \n\t\n /* for Pickling */\n {\"__reduce__\", (PyCFunction) array_reduce, 1, doc_reduce},\t\n\t{\"__setstate__\", (PyCFunction) array_setstate, 1, doc_setstate},\n\t{\"dumps\", (PyCFunction) array_dumps, 1, doc_dumps},\n\t{\"dump\", (PyCFunction) array_dump, 1, doc_dump},\n\n\t/* Extended methods added 2005 */\n\t{\"fill\", (PyCFunction)array_fill,\n\t METH_VARARGS, doc_fill},\n\t{\"transpose\",\t(PyCFunction)array_transpose, \n\t METH_VARARGS, doc_transpose},\n\t{\"take\",\t(PyCFunction)array_take, \n\t METH_VARARGS|METH_KEYWORDS, doc_take},\n\t{\"put\",\t(PyCFunction)array_put, \n\t METH_VARARGS|METH_KEYWORDS, doc_put},\n\t{\"putmask\",\t(PyCFunction)array_putmask, \n\t METH_VARARGS|METH_KEYWORDS, doc_putmask},\n\t{\"repeat\",\t(PyCFunction)array_repeat, \n\t METH_VARARGS|METH_KEYWORDS, doc_repeat},\n\t{\"choose\",\t(PyCFunction)array_choose, \n\t METH_VARARGS, doc_choose},\t\n\t{\"sort\",\t(PyCFunction)array_sort, \n\t METH_VARARGS|METH_KEYWORDS, doc_sort},\n\t{\"argsort\",\t(PyCFunction)array_argsort, \n\t METH_VARARGS|METH_KEYWORDS, doc_argsort},\n\t{\"searchsorted\", (PyCFunction)array_searchsorted, \n\t METH_VARARGS, doc_searchsorted},\t\n\t{\"argmax\",\t(PyCFunction)array_argmax, \n\t METH_VARARGS|METH_KEYWORDS, doc_argmax},\n\t{\"argmin\", (PyCFunction)array_argmin,\n\t METH_VARARGS|METH_KEYWORDS, 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|METH_KEYWORDS, doc_max},\n\t{\"min\", (PyCFunction)array_min,\n\t METH_VARARGS|METH_KEYWORDS, doc_min},\n\t{\"ptp\", (PyCFunction)array_ptp,\n\t METH_VARARGS|METH_KEYWORDS, doc_ptp},\n\t{\"mean\", (PyCFunction)array_mean,\n\t METH_VARARGS|METH_KEYWORDS, doc_mean},\n\t{\"trace\", (PyCFunction)array_trace,\n\t METH_VARARGS|METH_KEYWORDS, doc_trace},\n\t{\"diagonal\", (PyCFunction)array_diagonal,\n\t METH_VARARGS|METH_KEYWORDS, doc_diagonal},\n\t{\"clip\", (PyCFunction)array_clip,\n\t METH_VARARGS|METH_KEYWORDS, doc_clip},\n\t{\"conj\", (PyCFunction)array_conjugate,\n\t METH_VARARGS, doc_conj},\n\t{\"conjugate\", (PyCFunction)array_conjugate,\n\t METH_VARARGS, doc_conjugate},\n\t{\"nonzero\", (PyCFunction)array_nonzero,\n\t METH_VARARGS, doc_nonzero},\n\t{\"std\", (PyCFunction)array_stddev,\n\t METH_VARARGS|METH_KEYWORDS, doc_stddev},\n\t{\"var\", (PyCFunction)array_variance,\n\t METH_VARARGS|METH_KEYWORDS, doc_variance},\n\t{\"sum\", (PyCFunction)array_sum,\n\t METH_VARARGS|METH_KEYWORDS, doc_sum},\n\t{\"cumsum\", (PyCFunction)array_cumsum,\n\t METH_VARARGS|METH_KEYWORDS, doc_cumsum},\n\t{\"prod\", (PyCFunction)array_prod,\n\t METH_VARARGS|METH_KEYWORDS, doc_prod},\n\t{\"cumprod\", (PyCFunction)array_cumprod,\n\t METH_VARARGS|METH_KEYWORDS, doc_cumprod},\n\t{\"all\", (PyCFunction)array_all,\n\t METH_VARARGS|METH_KEYWORDS, doc_all},\n\t{\"any\", (PyCFunction)array_any,\n\t METH_VARARGS|METH_KEYWORDS, 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{\"round\", (PyCFunction)array_round,\n\t METH_VARARGS|METH_KEYWORDS, doc_round},\n\t{\"setflags\", (PyCFunction)array_setflags,\n\t METH_VARARGS|METH_KEYWORDS, doc_setflags},\n\t{\"newbyteorder\", (PyCFunction)array_newbyteorder,\n\t METH_VARARGS, doc_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n#undef _ARET\n\n\n", + "methods": [ + { + "name": "array_take", + "long_name": "array_take( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 12, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "array_fill", + "long_name": "array_fill( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "args" + ], + "start_line": 28, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_put", + "long_name": "array_put( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 71, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 43, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_putmask", + "long_name": "array_putmask( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 71, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 58, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_reverse_shape", + "long_name": "_reverse_shape( PyArray_Dims * newshape)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 2, + "token_count": 81, + "parameters": [ + "newshape" + ], + "start_line": 72, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_reshape", + "long_name": "array_reshape( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 50, + "complexity": 13, + "token_count": 299, + "parameters": [ + "self", + "args" + ], + "start_line": 94, + "end_line": 147, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_squeeze", + "long_name": "array_squeeze( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self", + "args" + ], + "start_line": 152, + "end_line": 156, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_view", + "long_name": "array_view( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 19, + "complexity": 6, + "token_count": 110, + "parameters": [ + "self", + "args" + ], + "start_line": 161, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "array_argmax", + "long_name": "array_argmax( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 186, + "end_line": 197, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_argmin", + "long_name": "array_argmin( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 202, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_max", + "long_name": "array_max( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 218, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_ptp", + "long_name": "array_ptp( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 234, + "end_line": 245, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_min", + "long_name": "array_min( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 251, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "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": 267, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetField", + "long_name": "PyArray_GetField( PyArrayObject * self , PyArray_Descr * typed , int offset)", + "filename": "arraymethods.c", + "nloc": 23, + "complexity": 4, + "token_count": 155, + "parameters": [ + "self", + "typed", + "offset" + ], + "start_line": 286, + "end_line": 310, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_getfield", + "long_name": "array_getfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 313, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetField", + "long_name": "PyArray_SetField( PyArrayObject * self , PyArray_Descr * dtype , int offset , PyObject * val)", + "filename": "arraymethods.c", + "nloc": 25, + "complexity": 4, + "token_count": 184, + "parameters": [ + "self", + "dtype", + "offset", + "val" + ], + "start_line": 335, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_setfield", + "long_name": "array_setfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 100, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 364, + "end_line": 379, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Byteswap", + "long_name": "PyArray_Byteswap( PyArrayObject * self , Bool inplace)", + "filename": "arraymethods.c", + "nloc": 37, + "complexity": 5, + "token_count": 226, + "parameters": [ + "self", + "inplace" + ], + "start_line": 386, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_byteswap", + "long_name": "array_byteswap( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 440, + "end_line": 448, + "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": 454, + "end_line": 464, + "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": 470, + "end_line": 474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_tofile", + "long_name": "array_tofile( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 33, + "complexity": 7, + "token_count": 208, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 479, + "end_line": 513, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_toscalar", + "long_name": "array_toscalar( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 4, + "token_count": 71, + "parameters": [ + "self", + "args" + ], + "start_line": 519, + "end_line": 528, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_cast", + "long_name": "array_cast( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 13, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "args" + ], + "start_line": 535, + "end_line": 549, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_wraparray", + "long_name": "array_wraparray( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 27, + "complexity": 4, + "token_count": 147, + "parameters": [ + "self", + "args" + ], + "start_line": 557, + "end_line": 585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "array_finalize", + "long_name": "array_finalize( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "args" + ], + "start_line": 589, + "end_line": 593, + "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": 7, + "token_count": 218, + "parameters": [ + "self", + "args" + ], + "start_line": 599, + "end_line": 642, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "array_copy", + "long_name": "array_copy( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "args" + ], + "start_line": 651, + "end_line": 657, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_resize", + "long_name": "array_resize( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 37, + "complexity": 10, + "token_count": 190, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 665, + "end_line": 703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "array_repeat", + "long_name": "array_repeat( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 711, + "end_line": 721, + "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": 731, + "end_line": 746, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_sort", + "long_name": "array_sort( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 98, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 751, + "end_line": 766, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_argsort", + "long_name": "array_argsort( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 80, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 773, + "end_line": 784, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_searchsorted", + "long_name": "array_searchsorted( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 795, + "end_line": 802, + "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": 807, + "end_line": 840, + "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": 844, + "end_line": 863, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_setobject_pkl", + "long_name": "_setobject_pkl( PyArrayObject * self , PyObject * list)", + "filename": "arraymethods.c", + "nloc": 17, + "complexity": 3, + "token_count": 115, + "parameters": [ + "self", + "list" + ], + "start_line": 866, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_reduce", + "long_name": "array_reduce( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 46, + "complexity": 7, + "token_count": 313, + "parameters": [ + "self", + "args" + ], + "start_line": 889, + "end_line": 952, + "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": 99, + "complexity": 18, + "token_count": 585, + "parameters": [ + "self", + "args" + ], + "start_line": 970, + "end_line": 1084, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 115, + "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": 1088, + "end_line": 1109, + "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": 1113, + "end_line": 1124, + "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": 1130, + "end_line": 1141, + "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": 1146, + "end_line": 1151, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "array_transpose", + "long_name": "array_transpose( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 18, + "complexity": 5, + "token_count": 116, + "parameters": [ + "self", + "args" + ], + "start_line": 1157, + "end_line": 1177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "array_mean", + "long_name": "array_mean( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1195, + "end_line": 1207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_sum", + "long_name": "array_sum( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1234, + "end_line": 1246, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_cumsum", + "long_name": "array_cumsum( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1252, + "end_line": 1264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_prod", + "long_name": "array_prod( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1269, + "end_line": 1281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_cumprod", + "long_name": "array_cumprod( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1287, + "end_line": 1299, + "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 , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1305, + "end_line": 1316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_all", + "long_name": "array_all( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1321, + "end_line": 1332, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_stddev", + "long_name": "array_stddev( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1337, + "end_line": 1349, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_variance", + "long_name": "array_variance( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1354, + "end_line": 1366, + "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": 1371, + "end_line": 1382, + "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": 1388, + "end_line": 1393, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "array_trace", + "long_name": "array_trace( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 12, + "complexity": 2, + "token_count": 105, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1401, + "end_line": 1414, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "array_clip", + "long_name": "array_clip( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 74, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1422, + "end_line": 1432, + "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": 1439, + "end_line": 1445, + "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": 1451, + "end_line": 1461, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_flatten", + "long_name": "array_flatten( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self", + "args" + ], + "start_line": 1466, + "end_line": 1473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_ravel", + "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "args" + ], + "start_line": 1478, + "end_line": 1485, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_round", + "long_name": "array_round( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1490, + "end_line": 1500, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_setflags", + "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 53, + "complexity": 10, + "token_count": 260, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1509, + "end_line": 1566, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "array_newbyteorder", + "long_name": "array_newbyteorder( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self", + "args" + ], + "start_line": 1572, + "end_line": 1584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "array_take", + "long_name": "array_take( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 12, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "array_fill", + "long_name": "array_fill( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "args" + ], + "start_line": 28, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_put", + "long_name": "array_put( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 71, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 43, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_putmask", + "long_name": "array_putmask( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 71, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 58, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_reverse_shape", + "long_name": "_reverse_shape( PyArray_Dims * newshape)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 2, + "token_count": 81, + "parameters": [ + "newshape" + ], + "start_line": 72, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_reshape", + "long_name": "array_reshape( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 50, + "complexity": 13, + "token_count": 299, + "parameters": [ + "self", + "args" + ], + "start_line": 94, + "end_line": 147, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_squeeze", + "long_name": "array_squeeze( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self", + "args" + ], + "start_line": 152, + "end_line": 156, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_view", + "long_name": "array_view( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 19, + "complexity": 6, + "token_count": 110, + "parameters": [ + "self", + "args" + ], + "start_line": 161, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "array_argmax", + "long_name": "array_argmax( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 186, + "end_line": 197, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_argmin", + "long_name": "array_argmin( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 202, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_max", + "long_name": "array_max( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 218, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_ptp", + "long_name": "array_ptp( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 234, + "end_line": 245, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_min", + "long_name": "array_min( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 251, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "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": 267, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetField", + "long_name": "PyArray_GetField( PyArrayObject * self , PyArray_Descr * typed , int offset)", + "filename": "arraymethods.c", + "nloc": 23, + "complexity": 4, + "token_count": 155, + "parameters": [ + "self", + "typed", + "offset" + ], + "start_line": 286, + "end_line": 310, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_getfield", + "long_name": "array_getfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 313, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetField", + "long_name": "PyArray_SetField( PyArrayObject * self , PyArray_Descr * dtype , int offset , PyObject * val)", + "filename": "arraymethods.c", + "nloc": 25, + "complexity": 4, + "token_count": 184, + "parameters": [ + "self", + "dtype", + "offset", + "val" + ], + "start_line": 335, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_setfield", + "long_name": "array_setfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 100, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 364, + "end_line": 379, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Byteswap", + "long_name": "PyArray_Byteswap( PyArrayObject * self , Bool inplace)", + "filename": "arraymethods.c", + "nloc": 37, + "complexity": 5, + "token_count": 226, + "parameters": [ + "self", + "inplace" + ], + "start_line": 386, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_byteswap", + "long_name": "array_byteswap( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 440, + "end_line": 448, + "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": 454, + "end_line": 464, + "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": 470, + "end_line": 474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_tofile", + "long_name": "array_tofile( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 33, + "complexity": 7, + "token_count": 208, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 479, + "end_line": 513, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_toscalar", + "long_name": "array_toscalar( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 4, + "token_count": 71, + "parameters": [ + "self", + "args" + ], + "start_line": 519, + "end_line": 528, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_cast", + "long_name": "array_cast( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 13, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "args" + ], + "start_line": 535, + "end_line": 549, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_wraparray", + "long_name": "array_wraparray( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 27, + "complexity": 4, + "token_count": 147, + "parameters": [ + "self", + "args" + ], + "start_line": 557, + "end_line": 585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "array_finalize", + "long_name": "array_finalize( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "args" + ], + "start_line": 589, + "end_line": 593, + "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": 7, + "token_count": 218, + "parameters": [ + "self", + "args" + ], + "start_line": 599, + "end_line": 642, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "array_copy", + "long_name": "array_copy( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "args" + ], + "start_line": 651, + "end_line": 657, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_resize", + "long_name": "array_resize( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 37, + "complexity": 10, + "token_count": 190, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 665, + "end_line": 703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "array_repeat", + "long_name": "array_repeat( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 711, + "end_line": 721, + "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": 731, + "end_line": 746, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_sort", + "long_name": "array_sort( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 98, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 751, + "end_line": 766, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_argsort", + "long_name": "array_argsort( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 80, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 773, + "end_line": 784, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_searchsorted", + "long_name": "array_searchsorted( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 795, + "end_line": 802, + "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": 807, + "end_line": 840, + "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": 844, + "end_line": 863, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_setobject_pkl", + "long_name": "_setobject_pkl( PyArrayObject * self , PyObject * list)", + "filename": "arraymethods.c", + "nloc": 17, + "complexity": 3, + "token_count": 115, + "parameters": [ + "self", + "list" + ], + "start_line": 866, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_reduce", + "long_name": "array_reduce( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 46, + "complexity": 7, + "token_count": 313, + "parameters": [ + "self", + "args" + ], + "start_line": 889, + "end_line": 952, + "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": 99, + "complexity": 18, + "token_count": 585, + "parameters": [ + "self", + "args" + ], + "start_line": 970, + "end_line": 1084, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 115, + "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": 1088, + "end_line": 1109, + "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": 1113, + "end_line": 1124, + "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": 1130, + "end_line": 1141, + "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": 1146, + "end_line": 1151, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "array_transpose", + "long_name": "array_transpose( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 18, + "complexity": 5, + "token_count": 116, + "parameters": [ + "self", + "args" + ], + "start_line": 1157, + "end_line": 1177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "array_mean", + "long_name": "array_mean( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1195, + "end_line": 1207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_sum", + "long_name": "array_sum( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1234, + "end_line": 1246, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_cumsum", + "long_name": "array_cumsum( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1252, + "end_line": 1264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_prod", + "long_name": "array_prod( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1269, + "end_line": 1281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_cumprod", + "long_name": "array_cumprod( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1287, + "end_line": 1299, + "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 , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1305, + "end_line": 1316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_all", + "long_name": "array_all( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1321, + "end_line": 1332, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_stddev", + "long_name": "array_stddev( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1337, + "end_line": 1349, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_variance", + "long_name": "array_variance( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1354, + "end_line": 1366, + "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": 1371, + "end_line": 1382, + "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": 1388, + "end_line": 1393, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "array_trace", + "long_name": "array_trace( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 12, + "complexity": 2, + "token_count": 105, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1401, + "end_line": 1414, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "array_clip", + "long_name": "array_clip( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 74, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1422, + "end_line": 1432, + "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": 1439, + "end_line": 1445, + "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": 1451, + "end_line": 1461, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_flatten", + "long_name": "array_flatten( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self", + "args" + ], + "start_line": 1466, + "end_line": 1473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_ravel", + "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "args" + ], + "start_line": 1478, + "end_line": 1485, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_round", + "long_name": "array_round( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1490, + "end_line": 1500, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_setflags", + "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 53, + "complexity": 10, + "token_count": 260, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1509, + "end_line": 1566, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "array_newbyteorder", + "long_name": "array_newbyteorder( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self", + "args" + ], + "start_line": 1572, + "end_line": 1584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "array_setflags", + "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 53, + "complexity": 10, + "token_count": 260, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1509, + "end_line": 1566, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + } + ], + "nloc": 1358, + "complexity": 226, + "token_count": 8479, + "diff_parsed": { + "added": [ + " Py_XDECREF(self->base);" + ], + "deleted": [ + " Py_DECREF(self->base);" + ] + } + } + ] + }, + { + "hash": "8c9cf9ac2a07e9ebb8dae51a264f708229770624", + "msg": "clean up some imports", + "author": { + "name": "Tim Leslie", + "email": "tim.leslie@gmail.com" + }, + "committer": { + "name": "Tim Leslie", + "email": "tim.leslie@gmail.com" + }, + "author_date": "2006-03-16T04:05:58+00:00", + "author_timezone": 0, + "committer_date": "2006-03-16T04:05:58+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "5a712837f673a194353113ebad72d5050ad1f68f" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 11, + "insertions": 14, + "lines": 25, + "files": 5, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/dft/fftpack.py", + "new_path": "numpy/dft/fftpack.py", + "filename": "fftpack.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -26,7 +26,8 @@\n 'fft2d', 'inverse_fft2d', 'real_fftnd', 'real_fft2d',\n 'inverse_real_fftnd', 'inverse_real_fft2d','fftn','ifftn']\n \n-from numpy.core import *\n+from numpy.core import asarray, zeros, swapaxes, shape, Complex, conjugate, \\\n+ Float, take\n import fftpack_lite as fftpack\n from helper import *\n \n", + "added_lines": 2, + "deleted_lines": 1, + "source_code": "\"\"\"\nDiscrete Fourier Transforms - FFT.py\n\nThe underlying code for these functions is an f2c translated and modified\nversion of the FFTPACK routines.\n\nfft(a, n=None, axis=-1)\ninverse_fft(a, n=None, axis=-1)\nreal_fft(a, n=None, axis=-1)\ninverse_real_fft(a, n=None, axis=-1)\nhermite_fft(a, n=None, axis=-1)\ninverse_hermite_fft(a, n=None, axis=-1)\nfftnd(a, s=None, axes=None)\ninverse_fftnd(a, s=None, axes=None)\nreal_fftnd(a, s=None, axes=None)\ninverse_real_fftnd(a, s=None, axes=None)\nfft2d(a, s=None, axes=(-2,-1))\ninverse_fft2d(a, s=None, axes=(-2, -1))\nreal_fft2d(a, s=None, axes=(-2,-1))\ninverse_real_fft2d(a, s=None, axes=(-2, -1))\n\"\"\"\n__all__ = ['fft','inverse_fft', 'ifft', 'real_fft', 'refft',\n 'inverse_real_fft', 'irefft', 'hfft', 'ihfft', 'refftn',\n 'irefftn', 'refft2', 'irefft2', 'fft2', 'ifft2',\n 'hermite_fft','inverse_hermite_fft','fftnd','inverse_fftnd',\n 'fft2d', 'inverse_fft2d', 'real_fftnd', 'real_fft2d',\n 'inverse_real_fftnd', 'inverse_real_fft2d','fftn','ifftn']\n\nfrom numpy.core import asarray, zeros, swapaxes, shape, Complex, conjugate, \\\n Float, take\nimport fftpack_lite as fftpack\nfrom helper import *\n\n_fft_cache = {}\n_real_fft_cache = {}\n\ndef _raw_fft(a, n=None, axis=-1, init_function=fftpack.cffti,\n work_function=fftpack.cfftf, fft_cache = _fft_cache ):\n a = asarray(a)\n\n if n == None: n = a.shape[axis]\n\n try:\n wsave = fft_cache[n]\n except(KeyError):\n wsave = init_function(n)\n fft_cache[n] = wsave\n\n if a.shape[axis] != n:\n s = list(a.shape)\n if s[axis] > n:\n index = [slice(None)]*len(s)\n index[axis] = slice(0,n)\n a = a[index]\n else:\n index = [slice(None)]*len(s)\n index[axis] = slice(0,s[axis])\n s[axis] = n\n z = zeros(s, a.dtype.char)\n z[index] = a\n a = z\n\n if axis != -1:\n a = swapaxes(a, axis, -1)\n r = work_function(a, wsave)\n if axis != -1:\n r = swapaxes(r, axis, -1)\n return r\n\n\ndef fft(a, n=None, axis=-1):\n \"\"\"fft(a, n=None, axis=-1)\n\n Will return the n point discrete Fourier transform of a. n defaults to the\n length of a. If n is larger than a, then a will be zero-padded to make up\n the difference. If n is smaller than a, the first n items in a will be\n used.\n\n The packing of the result is \"standard\": If A = fft(a, n), then A[0]\n contains the zero-frequency term, A[1:n/2+1] contains the\n positive-frequency terms, and A[n/2+1:] contains the negative-frequency\n terms, in order of decreasingly negative frequency. So for an 8-point\n transform, the frequencies of the result are [ 0, 1, 2, 3, 4, -3, -2, -1].\n\n This is most efficient for n a power of two. This also stores a cache of\n working memory for different sizes of fft's, so you could theoretically\n run into memory problems if you call this too many times with too many\n different n's.\"\"\"\n\n return _raw_fft(a, n, axis, fftpack.cffti, fftpack.cfftf, _fft_cache)\n\n\ndef inverse_fft(a, n=None, axis=-1):\n \"\"\"inverse_fft(a, n=None, axis=-1)\n\n Will return the n point inverse discrete Fourier transform of a. n\n defaults to the length of a. If n is larger than a, then a will be\n zero-padded to make up the difference. If n is smaller than a, then a will\n be truncated to reduce its size.\n\n The input array is expected to be packed the same way as the output of\n fft, as discussed in it's documentation.\n\n This is the inverse of fft: inverse_fft(fft(a)) == a within numerical\n accuracy.\n\n This is most efficient for n a power of two. This also stores a cache of\n working memory for different sizes of fft's, so you could theoretically\n run into memory problems if you call this too many times with too many\n different n's.\"\"\"\n\n a = asarray(a).astype(complex)\n if n == None:\n n = shape(a)[axis]\n return _raw_fft(a, n, axis, fftpack.cffti, fftpack.cfftb, _fft_cache) / n\n\n\ndef real_fft(a, n=None, axis=-1):\n \"\"\"real_fft(a, n=None, axis=-1)\n\n Will return the n point discrete Fourier transform of the real valued\n array a. n defaults to the length of a. n is the length of the input, not\n the output.\n\n The returned array will be the nonnegative frequency terms of the\n Hermite-symmetric, complex transform of the real array. So for an 8-point\n transform, the frequencies in the result are [ 0, 1, 2, 3, 4]. The first\n term will be real, as will the last if n is even. The negative frequency\n terms are not needed because they are the complex conjugates of the\n positive frequency terms. (This is what I mean when I say\n Hermite-symmetric.)\n\n This is most efficient for n a power of two.\"\"\"\n\n a = asarray(a).astype(float)\n return _raw_fft(a, n, axis, fftpack.rffti, fftpack.rfftf, _real_fft_cache)\n\n\ndef inverse_real_fft(a, n=None, axis=-1):\n \"\"\"inverse_real_fft(a, n=None, axis=-1)\n\n Will return the real valued n point inverse discrete Fourier transform of\n a, where a contains the nonnegative frequency terms of a Hermite-symmetric\n sequence. n is the length of the result, not the input. If n is not\n supplied, the default is 2*(len(a)-1). If you want the length of the\n result to be odd, you have to say so.\n\n If you specify an n such that a must be zero-padded or truncated, the\n extra/removed values will be added/removed at high frequencies. One can\n thus resample a series to m points via Fourier interpolation by: a_resamp\n = inverse_real_fft(real_fft(a), m).\n\n This is the inverse of real_fft:\n inverse_real_fft(real_fft(a), len(a)) == a\n within numerical accuracy.\"\"\"\n\n a = asarray(a).astype(complex)\n if n == None:\n n = (shape(a)[axis] - 1) * 2\n return _raw_fft(a, n, axis, fftpack.rffti, fftpack.rfftb,\n _real_fft_cache) / n\n\n\ndef hermite_fft(a, n=None, axis=-1):\n \"\"\"hermite_fft(a, n=None, axis=-1)\n inverse_hermite_fft(a, n=None, axis=-1)\n\n These are a pair analogous to real_fft/inverse_real_fft, but for the\n opposite case: here the signal is real in the frequency domain and has\n Hermite symmetry in the time domain. So here it's hermite_fft for which\n you must supply the length of the result if it is to be odd.\n\n inverse_hermite_fft(hermite_fft(a), len(a)) == a\n within numerical accuracy.\"\"\"\n\n a = asarray(a).astype(Complex)\n if n == None:\n n = (shape(a)[axis] - 1) * 2\n return inverse_real_fft(conjugate(a), n, axis) * n\n\n\ndef inverse_hermite_fft(a, n=None, axis=-1):\n \"\"\"hermite_fft(a, n=None, axis=-1)\n inverse_hermite_fft(a, n=None, axis=-1)\n\n These are a pair analogous to real_fft/inverse_real_fft, but for the\n opposite case: here the signal is real in the frequency domain and has\n Hermite symmetry in the time domain. So here it's hermite_fft for which\n you must supply the length of the result if it is to be odd.\n\n inverse_hermite_fft(hermite_fft(a), len(a)) == a\n within numerical accuracy.\"\"\"\n\n a = asarray(a).astype(Float)\n if n == None:\n n = shape(a)[axis]\n return conjugate(real_fft(a, n, axis))/n\n\n\ndef _cook_nd_args(a, s=None, axes=None, invreal=0):\n if s is None:\n shapeless = 1\n if axes == None:\n s = list(a.shape)\n else:\n s = take(a.shape, axes)\n else:\n shapeless = 0\n s = list(s)\n if axes == None:\n axes = range(-len(s), 0)\n if len(s) != len(axes):\n raise ValueError, \"Shape and axes have different lengths.\"\n if invreal and shapeless:\n s[axes[-1]] = (s[axes[-1]] - 1) * 2\n return s, axes\n\n\ndef _raw_fftnd(a, s=None, axes=None, function=fft):\n a = asarray(a)\n s, axes = _cook_nd_args(a, s, axes)\n itl = range(len(axes))\n itl.reverse()\n for ii in itl:\n a = function(a, n=s[ii], axis=axes[ii])\n return a\n\n\ndef fftnd(a, s=None, axes=None):\n \"\"\"fftnd(a, s=None, axes=None)\n\n The n-dimensional fft of a. s is a sequence giving the shape of the input\n an result along the transformed axes, as n for fft. Results are packed\n analogously to fft: the term for zero frequency in all axes is in the\n low-order corner, while the term for the Nyquist frequency in all axes is\n in the middle.\n\n If neither s nor axes is specified, the transform is taken along all\n axes. If s is specified and axes is not, the last len(s) axes are used.\n If axes are specified and s is not, the input shape along the specified\n axes is used. If s and axes are both specified and are not the same\n length, an exception is raised.\"\"\"\n\n return _raw_fftnd(a,s,axes,fft)\n\ndef inverse_fftnd(a, s=None, axes=None):\n \"\"\"inverse_fftnd(a, s=None, axes=None)\n\n The inverse of fftnd.\"\"\"\n\n return _raw_fftnd(a, s, axes, inverse_fft)\n\n\ndef fft2d(a, s=None, axes=(-2,-1)):\n \"\"\"fft2d(a, s=None, axes=(-2,-1))\n\n The 2d fft of a. This is really just fftnd with different default\n behavior.\"\"\"\n\n return _raw_fftnd(a,s,axes,fft)\n\n\ndef inverse_fft2d(a, s=None, axes=(-2,-1)):\n \"\"\"inverse_fft2d(a, s=None, axes=(-2, -1))\n\n The inverse of fft2d. This is really just inverse_fftnd with different\n default behavior.\"\"\"\n\n return _raw_fftnd(a, s, axes, inverse_fft)\n\n\ndef real_fftnd(a, s=None, axes=None):\n \"\"\"real_fftnd(a, s=None, axes=None)\n\n The n-dimensional discrete Fourier transform of a real array a. A real\n transform as real_fft is performed along the axis specified by the last\n element of axes, then complex transforms as fft are performed along the\n other axes.\"\"\"\n\n a = asarray(a).astype(Float)\n s, axes = _cook_nd_args(a, s, axes)\n a = real_fft(a, s[-1], axes[-1])\n for ii in range(len(axes)-1):\n a = fft(a, s[ii], axes[ii])\n return a\n\ndef real_fft2d(a, s=None, axes=(-2,-1)):\n \"\"\"real_fft2d(a, s=None, axes=(-2,-1))\n\n The 2d fft of the real valued array a. This is really just real_fftnd with\n different default behavior.\"\"\"\n\n return real_fftnd(a, s, axes)\n\n\ndef inverse_real_fftnd(a, s=None, axes=None):\n \"\"\"inverse_real_fftnd(a, s=None, axes=None)\n\n The inverse of real_fftnd. The transform implemented in inverse_fft is\n applied along all axes but the last, then the transform implemented in\n inverse_real_fft is performed along the last axis. As with\n inverse_real_fft, the length of the result along that axis must be\n specified if it is to be odd.\"\"\"\n\n a = asarray(a).astype(Complex)\n s, axes = _cook_nd_args(a, s, axes, invreal=1)\n for ii in range(len(axes)-1):\n a = inverse_fft(a, s[ii], axes[ii])\n a = inverse_real_fft(a, s[-1], axes[-1])\n return a\n\n\ndef inverse_real_fft2d(a, s=None, axes=(-2,-1)):\n \"\"\"inverse_real_fft2d(a, s=None, axes=(-2, -1))\n\n The inverse of real_fft2d. This is really just inverse_real_fftnd with\n different default behavior.\"\"\"\n\n return inverse_real_fftnd(a, s, axes)\n\nifft = inverse_fft\nrefft = real_fft\nirefft = inverse_real_fft\nhfft = hermite_fft\nihfft = inverse_hermite_fft\n\nfftn = fftnd\nifftn = inverse_fftnd\nrefftn = real_fftnd\nirefftn = inverse_real_fftnd\n\nfft2 = fft2d\nifft2 = inverse_fft2d\nrefft2 = real_fft2d\nirefft2 = inverse_real_fft2d\n", + "source_code_before": "\"\"\"\nDiscrete Fourier Transforms - FFT.py\n\nThe underlying code for these functions is an f2c translated and modified\nversion of the FFTPACK routines.\n\nfft(a, n=None, axis=-1)\ninverse_fft(a, n=None, axis=-1)\nreal_fft(a, n=None, axis=-1)\ninverse_real_fft(a, n=None, axis=-1)\nhermite_fft(a, n=None, axis=-1)\ninverse_hermite_fft(a, n=None, axis=-1)\nfftnd(a, s=None, axes=None)\ninverse_fftnd(a, s=None, axes=None)\nreal_fftnd(a, s=None, axes=None)\ninverse_real_fftnd(a, s=None, axes=None)\nfft2d(a, s=None, axes=(-2,-1))\ninverse_fft2d(a, s=None, axes=(-2, -1))\nreal_fft2d(a, s=None, axes=(-2,-1))\ninverse_real_fft2d(a, s=None, axes=(-2, -1))\n\"\"\"\n__all__ = ['fft','inverse_fft', 'ifft', 'real_fft', 'refft',\n 'inverse_real_fft', 'irefft', 'hfft', 'ihfft', 'refftn',\n 'irefftn', 'refft2', 'irefft2', 'fft2', 'ifft2',\n 'hermite_fft','inverse_hermite_fft','fftnd','inverse_fftnd',\n 'fft2d', 'inverse_fft2d', 'real_fftnd', 'real_fft2d',\n 'inverse_real_fftnd', 'inverse_real_fft2d','fftn','ifftn']\n\nfrom numpy.core import *\nimport fftpack_lite as fftpack\nfrom helper import *\n\n_fft_cache = {}\n_real_fft_cache = {}\n\ndef _raw_fft(a, n=None, axis=-1, init_function=fftpack.cffti,\n work_function=fftpack.cfftf, fft_cache = _fft_cache ):\n a = asarray(a)\n\n if n == None: n = a.shape[axis]\n\n try:\n wsave = fft_cache[n]\n except(KeyError):\n wsave = init_function(n)\n fft_cache[n] = wsave\n\n if a.shape[axis] != n:\n s = list(a.shape)\n if s[axis] > n:\n index = [slice(None)]*len(s)\n index[axis] = slice(0,n)\n a = a[index]\n else:\n index = [slice(None)]*len(s)\n index[axis] = slice(0,s[axis])\n s[axis] = n\n z = zeros(s, a.dtype.char)\n z[index] = a\n a = z\n\n if axis != -1:\n a = swapaxes(a, axis, -1)\n r = work_function(a, wsave)\n if axis != -1:\n r = swapaxes(r, axis, -1)\n return r\n\n\ndef fft(a, n=None, axis=-1):\n \"\"\"fft(a, n=None, axis=-1)\n\n Will return the n point discrete Fourier transform of a. n defaults to the\n length of a. If n is larger than a, then a will be zero-padded to make up\n the difference. If n is smaller than a, the first n items in a will be\n used.\n\n The packing of the result is \"standard\": If A = fft(a, n), then A[0]\n contains the zero-frequency term, A[1:n/2+1] contains the\n positive-frequency terms, and A[n/2+1:] contains the negative-frequency\n terms, in order of decreasingly negative frequency. So for an 8-point\n transform, the frequencies of the result are [ 0, 1, 2, 3, 4, -3, -2, -1].\n\n This is most efficient for n a power of two. This also stores a cache of\n working memory for different sizes of fft's, so you could theoretically\n run into memory problems if you call this too many times with too many\n different n's.\"\"\"\n\n return _raw_fft(a, n, axis, fftpack.cffti, fftpack.cfftf, _fft_cache)\n\n\ndef inverse_fft(a, n=None, axis=-1):\n \"\"\"inverse_fft(a, n=None, axis=-1)\n\n Will return the n point inverse discrete Fourier transform of a. n\n defaults to the length of a. If n is larger than a, then a will be\n zero-padded to make up the difference. If n is smaller than a, then a will\n be truncated to reduce its size.\n\n The input array is expected to be packed the same way as the output of\n fft, as discussed in it's documentation.\n\n This is the inverse of fft: inverse_fft(fft(a)) == a within numerical\n accuracy.\n\n This is most efficient for n a power of two. This also stores a cache of\n working memory for different sizes of fft's, so you could theoretically\n run into memory problems if you call this too many times with too many\n different n's.\"\"\"\n\n a = asarray(a).astype(complex)\n if n == None:\n n = shape(a)[axis]\n return _raw_fft(a, n, axis, fftpack.cffti, fftpack.cfftb, _fft_cache) / n\n\n\ndef real_fft(a, n=None, axis=-1):\n \"\"\"real_fft(a, n=None, axis=-1)\n\n Will return the n point discrete Fourier transform of the real valued\n array a. n defaults to the length of a. n is the length of the input, not\n the output.\n\n The returned array will be the nonnegative frequency terms of the\n Hermite-symmetric, complex transform of the real array. So for an 8-point\n transform, the frequencies in the result are [ 0, 1, 2, 3, 4]. The first\n term will be real, as will the last if n is even. The negative frequency\n terms are not needed because they are the complex conjugates of the\n positive frequency terms. (This is what I mean when I say\n Hermite-symmetric.)\n\n This is most efficient for n a power of two.\"\"\"\n\n a = asarray(a).astype(float)\n return _raw_fft(a, n, axis, fftpack.rffti, fftpack.rfftf, _real_fft_cache)\n\n\ndef inverse_real_fft(a, n=None, axis=-1):\n \"\"\"inverse_real_fft(a, n=None, axis=-1)\n\n Will return the real valued n point inverse discrete Fourier transform of\n a, where a contains the nonnegative frequency terms of a Hermite-symmetric\n sequence. n is the length of the result, not the input. If n is not\n supplied, the default is 2*(len(a)-1). If you want the length of the\n result to be odd, you have to say so.\n\n If you specify an n such that a must be zero-padded or truncated, the\n extra/removed values will be added/removed at high frequencies. One can\n thus resample a series to m points via Fourier interpolation by: a_resamp\n = inverse_real_fft(real_fft(a), m).\n\n This is the inverse of real_fft:\n inverse_real_fft(real_fft(a), len(a)) == a\n within numerical accuracy.\"\"\"\n\n a = asarray(a).astype(complex)\n if n == None:\n n = (shape(a)[axis] - 1) * 2\n return _raw_fft(a, n, axis, fftpack.rffti, fftpack.rfftb,\n _real_fft_cache) / n\n\n\ndef hermite_fft(a, n=None, axis=-1):\n \"\"\"hermite_fft(a, n=None, axis=-1)\n inverse_hermite_fft(a, n=None, axis=-1)\n\n These are a pair analogous to real_fft/inverse_real_fft, but for the\n opposite case: here the signal is real in the frequency domain and has\n Hermite symmetry in the time domain. So here it's hermite_fft for which\n you must supply the length of the result if it is to be odd.\n\n inverse_hermite_fft(hermite_fft(a), len(a)) == a\n within numerical accuracy.\"\"\"\n\n a = asarray(a).astype(Complex)\n if n == None:\n n = (shape(a)[axis] - 1) * 2\n return inverse_real_fft(conjugate(a), n, axis) * n\n\n\ndef inverse_hermite_fft(a, n=None, axis=-1):\n \"\"\"hermite_fft(a, n=None, axis=-1)\n inverse_hermite_fft(a, n=None, axis=-1)\n\n These are a pair analogous to real_fft/inverse_real_fft, but for the\n opposite case: here the signal is real in the frequency domain and has\n Hermite symmetry in the time domain. So here it's hermite_fft for which\n you must supply the length of the result if it is to be odd.\n\n inverse_hermite_fft(hermite_fft(a), len(a)) == a\n within numerical accuracy.\"\"\"\n\n a = asarray(a).astype(Float)\n if n == None:\n n = shape(a)[axis]\n return conjugate(real_fft(a, n, axis))/n\n\n\ndef _cook_nd_args(a, s=None, axes=None, invreal=0):\n if s is None:\n shapeless = 1\n if axes == None:\n s = list(a.shape)\n else:\n s = take(a.shape, axes)\n else:\n shapeless = 0\n s = list(s)\n if axes == None:\n axes = range(-len(s), 0)\n if len(s) != len(axes):\n raise ValueError, \"Shape and axes have different lengths.\"\n if invreal and shapeless:\n s[axes[-1]] = (s[axes[-1]] - 1) * 2\n return s, axes\n\n\ndef _raw_fftnd(a, s=None, axes=None, function=fft):\n a = asarray(a)\n s, axes = _cook_nd_args(a, s, axes)\n itl = range(len(axes))\n itl.reverse()\n for ii in itl:\n a = function(a, n=s[ii], axis=axes[ii])\n return a\n\n\ndef fftnd(a, s=None, axes=None):\n \"\"\"fftnd(a, s=None, axes=None)\n\n The n-dimensional fft of a. s is a sequence giving the shape of the input\n an result along the transformed axes, as n for fft. Results are packed\n analogously to fft: the term for zero frequency in all axes is in the\n low-order corner, while the term for the Nyquist frequency in all axes is\n in the middle.\n\n If neither s nor axes is specified, the transform is taken along all\n axes. If s is specified and axes is not, the last len(s) axes are used.\n If axes are specified and s is not, the input shape along the specified\n axes is used. If s and axes are both specified and are not the same\n length, an exception is raised.\"\"\"\n\n return _raw_fftnd(a,s,axes,fft)\n\ndef inverse_fftnd(a, s=None, axes=None):\n \"\"\"inverse_fftnd(a, s=None, axes=None)\n\n The inverse of fftnd.\"\"\"\n\n return _raw_fftnd(a, s, axes, inverse_fft)\n\n\ndef fft2d(a, s=None, axes=(-2,-1)):\n \"\"\"fft2d(a, s=None, axes=(-2,-1))\n\n The 2d fft of a. This is really just fftnd with different default\n behavior.\"\"\"\n\n return _raw_fftnd(a,s,axes,fft)\n\n\ndef inverse_fft2d(a, s=None, axes=(-2,-1)):\n \"\"\"inverse_fft2d(a, s=None, axes=(-2, -1))\n\n The inverse of fft2d. This is really just inverse_fftnd with different\n default behavior.\"\"\"\n\n return _raw_fftnd(a, s, axes, inverse_fft)\n\n\ndef real_fftnd(a, s=None, axes=None):\n \"\"\"real_fftnd(a, s=None, axes=None)\n\n The n-dimensional discrete Fourier transform of a real array a. A real\n transform as real_fft is performed along the axis specified by the last\n element of axes, then complex transforms as fft are performed along the\n other axes.\"\"\"\n\n a = asarray(a).astype(Float)\n s, axes = _cook_nd_args(a, s, axes)\n a = real_fft(a, s[-1], axes[-1])\n for ii in range(len(axes)-1):\n a = fft(a, s[ii], axes[ii])\n return a\n\ndef real_fft2d(a, s=None, axes=(-2,-1)):\n \"\"\"real_fft2d(a, s=None, axes=(-2,-1))\n\n The 2d fft of the real valued array a. This is really just real_fftnd with\n different default behavior.\"\"\"\n\n return real_fftnd(a, s, axes)\n\n\ndef inverse_real_fftnd(a, s=None, axes=None):\n \"\"\"inverse_real_fftnd(a, s=None, axes=None)\n\n The inverse of real_fftnd. The transform implemented in inverse_fft is\n applied along all axes but the last, then the transform implemented in\n inverse_real_fft is performed along the last axis. As with\n inverse_real_fft, the length of the result along that axis must be\n specified if it is to be odd.\"\"\"\n\n a = asarray(a).astype(Complex)\n s, axes = _cook_nd_args(a, s, axes, invreal=1)\n for ii in range(len(axes)-1):\n a = inverse_fft(a, s[ii], axes[ii])\n a = inverse_real_fft(a, s[-1], axes[-1])\n return a\n\n\ndef inverse_real_fft2d(a, s=None, axes=(-2,-1)):\n \"\"\"inverse_real_fft2d(a, s=None, axes=(-2, -1))\n\n The inverse of real_fft2d. This is really just inverse_real_fftnd with\n different default behavior.\"\"\"\n\n return inverse_real_fftnd(a, s, axes)\n\nifft = inverse_fft\nrefft = real_fft\nirefft = inverse_real_fft\nhfft = hermite_fft\nihfft = inverse_hermite_fft\n\nfftn = fftnd\nifftn = inverse_fftnd\nrefftn = real_fftnd\nirefftn = inverse_real_fftnd\n\nfft2 = fft2d\nifft2 = inverse_fft2d\nrefft2 = real_fft2d\nirefft2 = inverse_real_fft2d\n", + "methods": [ + { + "name": "_raw_fft", + "long_name": "_raw_fft( a , n = None , axis = - 1 , init_function = fftpack . cffti , work_function = fftpack . cfftf , fft_cache = _fft_cache )", + "filename": "fftpack.py", + "nloc": 28, + "complexity": 7, + "token_count": 230, + "parameters": [ + "a", + "n", + "axis", + "init_function", + "work_function", + "fft_cache" + ], + "start_line": 37, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "fft", + "long_name": "fft( a , n = None , axis = - 1 )", + "filename": "fftpack.py", + "nloc": 2, + "complexity": 1, + "token_count": 34, + "parameters": [ + "a", + "n", + "axis" + ], + "start_line": 71, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "inverse_fft", + "long_name": "inverse_fft( a , n = None , axis = - 1 )", + "filename": "fftpack.py", + "nloc": 5, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n", + "axis" + ], + "start_line": 93, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "real_fft", + "long_name": "real_fft( a , n = None , axis = - 1 )", + "filename": "fftpack.py", + "nloc": 3, + "complexity": 1, + "token_count": 45, + "parameters": [ + "a", + "n", + "axis" + ], + "start_line": 118, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "inverse_real_fft", + "long_name": "inverse_real_fft( a , n = None , axis = - 1 )", + "filename": "fftpack.py", + "nloc": 6, + "complexity": 2, + "token_count": 67, + "parameters": [ + "a", + "n", + "axis" + ], + "start_line": 139, + "end_line": 161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "hermite_fft", + "long_name": "hermite_fft( a , n = None , axis = - 1 )", + "filename": "fftpack.py", + "nloc": 5, + "complexity": 2, + "token_count": 60, + "parameters": [ + "a", + "n", + "axis" + ], + "start_line": 164, + "end_line": 179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "inverse_hermite_fft", + "long_name": "inverse_hermite_fft( a , n = None , axis = - 1 )", + "filename": "fftpack.py", + "nloc": 5, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a", + "n", + "axis" + ], + "start_line": 182, + "end_line": 197, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_cook_nd_args", + "long_name": "_cook_nd_args( a , s = None , axes = None , invreal = 0 )", + "filename": "fftpack.py", + "nloc": 17, + "complexity": 7, + "token_count": 125, + "parameters": [ + "a", + "s", + "axes", + "invreal" + ], + "start_line": 200, + "end_line": 216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_raw_fftnd", + "long_name": "_raw_fftnd( a , s = None , axes = None , function = fft )", + "filename": "fftpack.py", + "nloc": 8, + "complexity": 2, + "token_count": 76, + "parameters": [ + "a", + "s", + "axes", + "function" + ], + "start_line": 219, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "fftnd", + "long_name": "fftnd( a , s = None , axes = None )", + "filename": "fftpack.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "s", + "axes" + ], + "start_line": 229, + "end_line": 244, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "inverse_fftnd", + "long_name": "inverse_fftnd( a , s = None , axes = None )", + "filename": "fftpack.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "s", + "axes" + ], + "start_line": 246, + "end_line": 251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "fft2d", + "long_name": "fft2d( a , s = None , axes = ( - 2 , - 1 )", + "filename": "fftpack.py", + "nloc": 6, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "s", + "axes", + "1" + ], + "start_line": 254, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "inverse_fft2d", + "long_name": "inverse_fft2d( a , s = None , axes = ( - 2 , - 1 )", + "filename": "fftpack.py", + "nloc": 6, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "s", + "axes", + "1" + ], + "start_line": 263, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "real_fftnd", + "long_name": "real_fftnd( a , s = None , axes = None )", + "filename": "fftpack.py", + "nloc": 7, + "complexity": 2, + "token_count": 86, + "parameters": [ + "a", + "s", + "axes" + ], + "start_line": 272, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "real_fft2d", + "long_name": "real_fft2d( a , s = None , axes = ( - 2 , - 1 )", + "filename": "fftpack.py", + "nloc": 6, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "s", + "axes", + "1" + ], + "start_line": 287, + "end_line": 293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "inverse_real_fftnd", + "long_name": "inverse_real_fftnd( a , s = None , axes = None )", + "filename": "fftpack.py", + "nloc": 7, + "complexity": 2, + "token_count": 90, + "parameters": [ + "a", + "s", + "axes" + ], + "start_line": 296, + "end_line": 310, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "inverse_real_fft2d", + "long_name": "inverse_real_fft2d( a , s = None , axes = ( - 2 , - 1 )", + "filename": "fftpack.py", + "nloc": 6, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "s", + "axes", + "1" + ], + "start_line": 313, + "end_line": 319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "_raw_fft", + "long_name": "_raw_fft( a , n = None , axis = - 1 , init_function = fftpack . cffti , work_function = fftpack . cfftf , fft_cache = _fft_cache )", + "filename": "fftpack.py", + "nloc": 28, + "complexity": 7, + "token_count": 230, + "parameters": [ + "a", + "n", + "axis", + "init_function", + "work_function", + "fft_cache" + ], + "start_line": 36, + "end_line": 67, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "fft", + "long_name": "fft( a , n = None , axis = - 1 )", + "filename": "fftpack.py", + "nloc": 2, + "complexity": 1, + "token_count": 34, + "parameters": [ + "a", + "n", + "axis" + ], + "start_line": 70, + "end_line": 89, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "inverse_fft", + "long_name": "inverse_fft( a , n = None , axis = - 1 )", + "filename": "fftpack.py", + "nloc": 5, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n", + "axis" + ], + "start_line": 92, + "end_line": 114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "real_fft", + "long_name": "real_fft( a , n = None , axis = - 1 )", + "filename": "fftpack.py", + "nloc": 3, + "complexity": 1, + "token_count": 45, + "parameters": [ + "a", + "n", + "axis" + ], + "start_line": 117, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "inverse_real_fft", + "long_name": "inverse_real_fft( a , n = None , axis = - 1 )", + "filename": "fftpack.py", + "nloc": 6, + "complexity": 2, + "token_count": 67, + "parameters": [ + "a", + "n", + "axis" + ], + "start_line": 138, + "end_line": 160, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "hermite_fft", + "long_name": "hermite_fft( a , n = None , axis = - 1 )", + "filename": "fftpack.py", + "nloc": 5, + "complexity": 2, + "token_count": 60, + "parameters": [ + "a", + "n", + "axis" + ], + "start_line": 163, + "end_line": 178, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "inverse_hermite_fft", + "long_name": "inverse_hermite_fft( a , n = None , axis = - 1 )", + "filename": "fftpack.py", + "nloc": 5, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a", + "n", + "axis" + ], + "start_line": 181, + "end_line": 196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_cook_nd_args", + "long_name": "_cook_nd_args( a , s = None , axes = None , invreal = 0 )", + "filename": "fftpack.py", + "nloc": 17, + "complexity": 7, + "token_count": 125, + "parameters": [ + "a", + "s", + "axes", + "invreal" + ], + "start_line": 199, + "end_line": 215, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_raw_fftnd", + "long_name": "_raw_fftnd( a , s = None , axes = None , function = fft )", + "filename": "fftpack.py", + "nloc": 8, + "complexity": 2, + "token_count": 76, + "parameters": [ + "a", + "s", + "axes", + "function" + ], + "start_line": 218, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "fftnd", + "long_name": "fftnd( a , s = None , axes = None )", + "filename": "fftpack.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "s", + "axes" + ], + "start_line": 228, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "inverse_fftnd", + "long_name": "inverse_fftnd( a , s = None , axes = None )", + "filename": "fftpack.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "s", + "axes" + ], + "start_line": 245, + "end_line": 250, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "fft2d", + "long_name": "fft2d( a , s = None , axes = ( - 2 , - 1 )", + "filename": "fftpack.py", + "nloc": 6, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "s", + "axes", + "1" + ], + "start_line": 253, + "end_line": 259, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "inverse_fft2d", + "long_name": "inverse_fft2d( a , s = None , axes = ( - 2 , - 1 )", + "filename": "fftpack.py", + "nloc": 6, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "s", + "axes", + "1" + ], + "start_line": 262, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "real_fftnd", + "long_name": "real_fftnd( a , s = None , axes = None )", + "filename": "fftpack.py", + "nloc": 7, + "complexity": 2, + "token_count": 86, + "parameters": [ + "a", + "s", + "axes" + ], + "start_line": 271, + "end_line": 284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "real_fft2d", + "long_name": "real_fft2d( a , s = None , axes = ( - 2 , - 1 )", + "filename": "fftpack.py", + "nloc": 6, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "s", + "axes", + "1" + ], + "start_line": 286, + "end_line": 292, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "inverse_real_fftnd", + "long_name": "inverse_real_fftnd( a , s = None , axes = None )", + "filename": "fftpack.py", + "nloc": 7, + "complexity": 2, + "token_count": 90, + "parameters": [ + "a", + "s", + "axes" + ], + "start_line": 295, + "end_line": 309, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "inverse_real_fft2d", + "long_name": "inverse_real_fft2d( a , s = None , axes = ( - 2 , - 1 )", + "filename": "fftpack.py", + "nloc": 6, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "s", + "axes", + "1" + ], + "start_line": 312, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 167, + "complexity": 36, + "token_count": 1249, + "diff_parsed": { + "added": [ + "from numpy.core import asarray, zeros, swapaxes, shape, Complex, conjugate, \\", + " Float, take" + ], + "deleted": [ + "from numpy.core import *" + ] + } + }, + { + "old_path": "numpy/lib/machar.py", + "new_path": "numpy/lib/machar.py", + "filename": "machar.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -7,7 +7,6 @@\n \n __all__ = ['MachAr']\n \n-from numpy.core.numeric import array\n from numpy.core.oldnumeric import any\n \n # Need to speed this up...especially for longfloat\n", + "added_lines": 0, + "deleted_lines": 1, + "source_code": "#\n# Machine arithmetics - determine the parameters of the\n# floating-point arithmetic system\n#\n# Author: Pearu Peterson, September 2003\n#\n\n__all__ = ['MachAr']\n\nfrom numpy.core.oldnumeric import any\n\n# Need to speed this up...especially for longfloat\n\nclass MachAr(object):\n \"\"\"Diagnosing machine parameters.\n\n The following attributes are available:\n\n ibeta - radix in which numbers are represented\n it - number of base-ibeta digits in the floating point mantissa M\n machep - exponent of the smallest (most negative) power of ibeta that,\n added to 1.0,\n gives something different from 1.0\n eps - floating-point number beta**machep (floating point precision)\n negep - exponent of the smallest power of ibeta that, substracted\n from 1.0, gives something different from 1.0\n epsneg - floating-point number beta**negep\n iexp - number of bits in the exponent (including its sign and bias)\n minexp - smallest (most negative) power of ibeta consistent with there\n being no leading zeros in the mantissa\n xmin - floating point number beta**minexp (the smallest (in\n magnitude) usable floating value)\n maxexp - smallest (positive) power of ibeta that causes overflow\n xmax - (1-epsneg)* beta**maxexp (the largest (in magnitude)\n usable floating value)\n irnd - in range(6), information on what kind of rounding is done\n in addition, and on how underflow is handled\n ngrd - number of 'guard digits' used when truncating the product\n of two mantissas to fit the representation\n\n epsilon - same as eps\n tiny - same as xmin\n huge - same as xmax\n precision - int(-log10(eps))\n resolution - 10**(-precision)\n\n Reference:\n Numerical Recipies.\n \"\"\"\n def __init__(self, float_conv=float,int_conv=int,\n float_to_float=float,\n float_to_str = lambda v:'%24.16e' % v,\n title = 'Python floating point number'):\n \"\"\"\n float_conv - convert integer to float (array)\n int_conv - convert float (array) to integer\n float_to_float - convert float array to float\n float_to_str - convert array float to str\n title - description of used floating point numbers\n \"\"\"\n one = float_conv(1)\n two = one + one\n zero = one - one\n\n # Do we really need to do this? Aren't they 2 and 2.0?\n # Determine ibeta and beta\n a = one\n while 1:\n a = a + a\n temp = a + one\n temp1 = temp - a\n if any(temp1 - one != zero):\n break\n b = one\n while 1:\n b = b + b\n temp = a + b\n itemp = int_conv(temp-a)\n if any(itemp != 0):\n break\n ibeta = itemp\n beta = float_conv(ibeta)\n\n # Determine it and irnd\n it = -1\n b = one\n while 1:\n it = it + 1\n b = b * beta\n temp = b + one\n temp1 = temp - b\n if any(temp1 - one != zero):\n break\n\n betah = beta / two\n a = one\n while 1:\n a = a + a\n temp = a + one\n temp1 = temp - a\n if any(temp1 - one != zero):\n break\n temp = a + betah\n irnd = 0\n if any(temp-a != zero):\n irnd = 1\n tempa = a + beta\n temp = tempa + betah\n if irnd==0 and any(temp-tempa != zero):\n irnd = 2\n\n # Determine negep and epsneg\n negep = it + 3\n betain = one / beta\n a = one\n for i in range(negep):\n a = a * betain\n b = a\n while 1:\n temp = one - a\n if any(temp-one != zero):\n break\n a = a * beta\n negep = negep - 1\n # Prevent infinite loop on PPC with gcc 4.0:\n if negep < 0:\n raise RuntimeError, \"could not determine machine tolerance \" \\\n \"for 'negep', locals() -> %s\" % (locals())\n negep = -negep\n epsneg = a\n\n # Determine machep and eps\n machep = - it - 3\n a = b\n\n while 1:\n temp = one + a\n if any(temp-one != zero):\n break\n a = a * beta\n machep = machep + 1\n eps = a\n\n # Determine ngrd\n ngrd = 0\n temp = one + eps\n if irnd==0 and any(temp*one - one != zero):\n ngrd = 1\n\n # Determine iexp\n i = 0\n k = 1\n z = betain\n t = one + eps\n nxres = 0\n while 1:\n y = z\n z = y*y\n a = z*one # Check here for underflow\n temp = z*t\n if any(a+a == zero) or any(abs(z)>=y):\n break\n temp1 = temp * betain\n if any(temp1*beta == z):\n break\n i = i + 1\n k = k + k\n if ibeta != 10:\n iexp = i + 1\n mx = k + k\n else:\n iexp = 2\n iz = ibeta\n while k >= iz:\n iz = iz * ibeta\n iexp = iexp + 1\n mx = iz + iz - 1\n\n # Determine minexp and xmin\n while 1:\n xmin = y\n y = y * betain\n a = y * one\n temp = y * t\n if any(a+a != zero) and any(abs(y) < xmin):\n k = k + 1\n temp1 = temp * betain\n if any(temp1*beta == y) and any(temp != y):\n nxres = 3\n xmin = y\n break\n else:\n break\n minexp = -k\n\n # Determine maxexp, xmax\n if mx <= k + k - 3 and ibeta != 10:\n mx = mx + mx\n iexp = iexp + 1\n maxexp = mx + minexp\n irnd = irnd + nxres\n if irnd >= 2:\n maxexp = maxexp - 2\n i = maxexp + minexp\n if ibeta == 2 and not i:\n maxexp = maxexp - 1\n if i > 20:\n maxexp = maxexp - 1\n if any(a != y):\n maxexp = maxexp - 2\n xmax = one - epsneg\n if any(xmax*one != xmax):\n xmax = one - beta*epsneg\n xmax = xmax / (xmin*beta*beta*beta)\n i = maxexp + minexp + 3\n for j in range(i):\n if ibeta==2:\n xmax = xmax + xmax\n else:\n xmax = xmax * beta\n\n self.ibeta = ibeta\n self.it = it\n self.negep = negep\n self.epsneg = float_to_float(epsneg)\n self._str_epsneg = float_to_str(epsneg)\n self.machep = machep\n self.eps = float_to_float(eps)\n self._str_eps = float_to_str(eps)\n self.ngrd = ngrd\n self.iexp = iexp\n self.minexp = minexp\n self.xmin = float_to_float(xmin)\n self._str_xmin = float_to_str(xmin)\n self.maxexp = maxexp\n self.xmax = float_to_float(xmax)\n self._str_xmax = float_to_str(xmax)\n self.irnd = irnd\n\n self.title = title\n # Commonly used parameters\n self.epsilon = self.eps\n self.tiny = self.xmin\n self.huge = self.xmax\n\n import math\n self.precision = int(-math.log10(float_to_float(self.eps)))\n ten = two + two + two + two + two\n resolution = ten ** (-self.precision)\n self.resolution = float_to_float(resolution)\n self._str_resolution = float_to_str(resolution)\n\n def __str__(self):\n return '''\\\nMachine parameters for %(title)s\n---------------------------------------------------------------------\nibeta=%(ibeta)s it=%(it)s iexp=%(iexp)s ngrd=%(ngrd)s irnd=%(irnd)s\nmachep=%(machep)s eps=%(_str_eps)s (beta**machep == epsilon)\nnegep =%(negep)s epsneg=%(_str_epsneg)s (beta**epsneg)\nminexp=%(minexp)s xmin=%(_str_xmin)s (beta**minexp == tiny)\nmaxexp=%(maxexp)s xmax=%(_str_xmax)s ((1-epsneg)*beta**maxexp == huge)\n---------------------------------------------------------------------\n''' % self.__dict__\n\n\nif __name__ == '__main__':\n print MachAr()\n", + "source_code_before": "#\n# Machine arithmetics - determine the parameters of the\n# floating-point arithmetic system\n#\n# Author: Pearu Peterson, September 2003\n#\n\n__all__ = ['MachAr']\n\nfrom numpy.core.numeric import array\nfrom numpy.core.oldnumeric import any\n\n# Need to speed this up...especially for longfloat\n\nclass MachAr(object):\n \"\"\"Diagnosing machine parameters.\n\n The following attributes are available:\n\n ibeta - radix in which numbers are represented\n it - number of base-ibeta digits in the floating point mantissa M\n machep - exponent of the smallest (most negative) power of ibeta that,\n added to 1.0,\n gives something different from 1.0\n eps - floating-point number beta**machep (floating point precision)\n negep - exponent of the smallest power of ibeta that, substracted\n from 1.0, gives something different from 1.0\n epsneg - floating-point number beta**negep\n iexp - number of bits in the exponent (including its sign and bias)\n minexp - smallest (most negative) power of ibeta consistent with there\n being no leading zeros in the mantissa\n xmin - floating point number beta**minexp (the smallest (in\n magnitude) usable floating value)\n maxexp - smallest (positive) power of ibeta that causes overflow\n xmax - (1-epsneg)* beta**maxexp (the largest (in magnitude)\n usable floating value)\n irnd - in range(6), information on what kind of rounding is done\n in addition, and on how underflow is handled\n ngrd - number of 'guard digits' used when truncating the product\n of two mantissas to fit the representation\n\n epsilon - same as eps\n tiny - same as xmin\n huge - same as xmax\n precision - int(-log10(eps))\n resolution - 10**(-precision)\n\n Reference:\n Numerical Recipies.\n \"\"\"\n def __init__(self, float_conv=float,int_conv=int,\n float_to_float=float,\n float_to_str = lambda v:'%24.16e' % v,\n title = 'Python floating point number'):\n \"\"\"\n float_conv - convert integer to float (array)\n int_conv - convert float (array) to integer\n float_to_float - convert float array to float\n float_to_str - convert array float to str\n title - description of used floating point numbers\n \"\"\"\n one = float_conv(1)\n two = one + one\n zero = one - one\n\n # Do we really need to do this? Aren't they 2 and 2.0?\n # Determine ibeta and beta\n a = one\n while 1:\n a = a + a\n temp = a + one\n temp1 = temp - a\n if any(temp1 - one != zero):\n break\n b = one\n while 1:\n b = b + b\n temp = a + b\n itemp = int_conv(temp-a)\n if any(itemp != 0):\n break\n ibeta = itemp\n beta = float_conv(ibeta)\n\n # Determine it and irnd\n it = -1\n b = one\n while 1:\n it = it + 1\n b = b * beta\n temp = b + one\n temp1 = temp - b\n if any(temp1 - one != zero):\n break\n\n betah = beta / two\n a = one\n while 1:\n a = a + a\n temp = a + one\n temp1 = temp - a\n if any(temp1 - one != zero):\n break\n temp = a + betah\n irnd = 0\n if any(temp-a != zero):\n irnd = 1\n tempa = a + beta\n temp = tempa + betah\n if irnd==0 and any(temp-tempa != zero):\n irnd = 2\n\n # Determine negep and epsneg\n negep = it + 3\n betain = one / beta\n a = one\n for i in range(negep):\n a = a * betain\n b = a\n while 1:\n temp = one - a\n if any(temp-one != zero):\n break\n a = a * beta\n negep = negep - 1\n # Prevent infinite loop on PPC with gcc 4.0:\n if negep < 0:\n raise RuntimeError, \"could not determine machine tolerance \" \\\n \"for 'negep', locals() -> %s\" % (locals())\n negep = -negep\n epsneg = a\n\n # Determine machep and eps\n machep = - it - 3\n a = b\n\n while 1:\n temp = one + a\n if any(temp-one != zero):\n break\n a = a * beta\n machep = machep + 1\n eps = a\n\n # Determine ngrd\n ngrd = 0\n temp = one + eps\n if irnd==0 and any(temp*one - one != zero):\n ngrd = 1\n\n # Determine iexp\n i = 0\n k = 1\n z = betain\n t = one + eps\n nxres = 0\n while 1:\n y = z\n z = y*y\n a = z*one # Check here for underflow\n temp = z*t\n if any(a+a == zero) or any(abs(z)>=y):\n break\n temp1 = temp * betain\n if any(temp1*beta == z):\n break\n i = i + 1\n k = k + k\n if ibeta != 10:\n iexp = i + 1\n mx = k + k\n else:\n iexp = 2\n iz = ibeta\n while k >= iz:\n iz = iz * ibeta\n iexp = iexp + 1\n mx = iz + iz - 1\n\n # Determine minexp and xmin\n while 1:\n xmin = y\n y = y * betain\n a = y * one\n temp = y * t\n if any(a+a != zero) and any(abs(y) < xmin):\n k = k + 1\n temp1 = temp * betain\n if any(temp1*beta == y) and any(temp != y):\n nxres = 3\n xmin = y\n break\n else:\n break\n minexp = -k\n\n # Determine maxexp, xmax\n if mx <= k + k - 3 and ibeta != 10:\n mx = mx + mx\n iexp = iexp + 1\n maxexp = mx + minexp\n irnd = irnd + nxres\n if irnd >= 2:\n maxexp = maxexp - 2\n i = maxexp + minexp\n if ibeta == 2 and not i:\n maxexp = maxexp - 1\n if i > 20:\n maxexp = maxexp - 1\n if any(a != y):\n maxexp = maxexp - 2\n xmax = one - epsneg\n if any(xmax*one != xmax):\n xmax = one - beta*epsneg\n xmax = xmax / (xmin*beta*beta*beta)\n i = maxexp + minexp + 3\n for j in range(i):\n if ibeta==2:\n xmax = xmax + xmax\n else:\n xmax = xmax * beta\n\n self.ibeta = ibeta\n self.it = it\n self.negep = negep\n self.epsneg = float_to_float(epsneg)\n self._str_epsneg = float_to_str(epsneg)\n self.machep = machep\n self.eps = float_to_float(eps)\n self._str_eps = float_to_str(eps)\n self.ngrd = ngrd\n self.iexp = iexp\n self.minexp = minexp\n self.xmin = float_to_float(xmin)\n self._str_xmin = float_to_str(xmin)\n self.maxexp = maxexp\n self.xmax = float_to_float(xmax)\n self._str_xmax = float_to_str(xmax)\n self.irnd = irnd\n\n self.title = title\n # Commonly used parameters\n self.epsilon = self.eps\n self.tiny = self.xmin\n self.huge = self.xmax\n\n import math\n self.precision = int(-math.log10(float_to_float(self.eps)))\n ten = two + two + two + two + two\n resolution = ten ** (-self.precision)\n self.resolution = float_to_float(resolution)\n self._str_resolution = float_to_str(resolution)\n\n def __str__(self):\n return '''\\\nMachine parameters for %(title)s\n---------------------------------------------------------------------\nibeta=%(ibeta)s it=%(it)s iexp=%(iexp)s ngrd=%(ngrd)s irnd=%(irnd)s\nmachep=%(machep)s eps=%(_str_eps)s (beta**machep == epsilon)\nnegep =%(negep)s epsneg=%(_str_epsneg)s (beta**epsneg)\nminexp=%(minexp)s xmin=%(_str_xmin)s (beta**minexp == tiny)\nmaxexp=%(maxexp)s xmax=%(_str_xmax)s ((1-epsneg)*beta**maxexp == huge)\n---------------------------------------------------------------------\n''' % self.__dict__\n\n\nif __name__ == '__main__':\n print MachAr()\n", + "methods": [ + { + "name": "__init__", + "long_name": "__init__( self , float_conv = float , int_conv = int , float_to_float = float , float_to_str = lambda v : '%24.16e' % v , title = 'Python floating point number' )", + "filename": "machar.py", + "nloc": 171, + "complexity": 41, + "token_count": 953, + "parameters": [ + "self", + "float_conv", + "int_conv", + "float_to_float", + "float_to_str", + "title" + ], + "start_line": 50, + "end_line": 251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 202, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "machar.py", + "nloc": 11, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 253, + "end_line": 263, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "__init__", + "long_name": "__init__( self , float_conv = float , int_conv = int , float_to_float = float , float_to_str = lambda v : '%24.16e' % v , title = 'Python floating point number' )", + "filename": "machar.py", + "nloc": 171, + "complexity": 41, + "token_count": 953, + "parameters": [ + "self", + "float_conv", + "int_conv", + "float_to_float", + "float_to_str", + "title" + ], + "start_line": 51, + "end_line": 252, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 202, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "machar.py", + "nloc": 11, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 254, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + } + ], + "changed_methods": [], + "nloc": 222, + "complexity": 42, + "token_count": 995, + "diff_parsed": { + "added": [], + "deleted": [ + "from numpy.core.numeric import array" + ] + } + }, + { + "old_path": "numpy/lib/scimath.py", + "new_path": "numpy/lib/scimath.py", + "filename": "scimath.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -7,21 +7,22 @@\n 'arcsin', 'arctanh']\n \n import numpy.core.numeric as nx\n-from numpy.core.numeric import *\n+import numpy.core.numerictypes as nt\n+from numpy.core.numeric import asarray, any\n+from numpy.lib.type_check import isreal, asscalar\n \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 \n-_ln2 = log(2.0)\n+_ln2 = nx.log(2.0)\n \n def _tocomplex(arr):\n- if isinstance(arr.dtype, (nx.single, nx.byte, nx.short, nx.ubyte,\n- nx.ushort)):\n- return arr.astype(nx.csingle)\n+ if isinstance(arr.dtype, (nt.single, nt.byte, nt.short, nt.ubyte,\n+ nt.ushort)):\n+ return arr.astype(nt.csingle)\n else:\n- return arr.astype(nx.cdouble)\n+ return arr.astype(nt.cdouble)\n \n def _fix_real_lt_zero(x):\n x = asarray(x)\n", + "added_lines": 8, + "deleted_lines": 7, + "source_code": "\"\"\"\nWrapper functions to more user-friendly calling of certain math functions\nwhose output data-type is different than the input data-type in certain domains of the input.\n\"\"\"\n\n__all__ = ['sqrt', 'log', 'log2', 'logn','log10', 'power', 'arccos',\n 'arcsin', 'arctanh']\n\nimport numpy.core.numeric as nx\nimport numpy.core.numerictypes as nt\nfrom numpy.core.numeric import asarray, any\nfrom numpy.lib.type_check import isreal, asscalar\n\n\n__all__.extend([key for key in dir(nx.umath)\n if key[0] != '_' and key not in __all__])\n\n_ln2 = nx.log(2.0)\n\ndef _tocomplex(arr):\n if isinstance(arr.dtype, (nt.single, nt.byte, nt.short, nt.ubyte,\n nt.ushort)):\n return arr.astype(nt.csingle)\n else:\n return arr.astype(nt.cdouble)\n\ndef _fix_real_lt_zero(x):\n x = asarray(x)\n if any(isreal(x) & (x<0)):\n x = _tocomplex(x)\n return 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\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": "\"\"\"\nWrapper functions to more user-friendly calling of certain math functions\nwhose output data-type is different than the input data-type in certain domains of the input.\n\"\"\"\n\n__all__ = ['sqrt', 'log', 'log2', 'logn','log10', 'power', 'arccos',\n 'arcsin', 'arctanh']\n\nimport numpy.core.numeric as nx\nfrom numpy.core.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 isinstance(arr.dtype, (nx.single, nx.byte, nx.short, nx.ubyte,\n nx.ushort)):\n return arr.astype(nx.csingle)\n else:\n return arr.astype(nx.cdouble)\n\ndef _fix_real_lt_zero(x):\n x = asarray(x)\n if any(isreal(x) & (x<0)):\n x = _tocomplex(x)\n return 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\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": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "arr" + ], + "start_line": 20, + "end_line": 25, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "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": 34, + "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": 68, + "end_line": 70, + "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": 72, + "end_line": 74, + "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": 76, + "end_line": 78, + "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": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "arr" + ], + "start_line": 19, + "end_line": 24, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "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": 34, + "parameters": [ + "x" + ], + "start_line": 26, + "end_line": 30, + "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": 32, + "end_line": 36, + "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": 38, + "end_line": 40, + "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": 42, + "end_line": 44, + "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": 46, + "end_line": 48, + "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": 50, + "end_line": 55, + "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": 57, + "end_line": 61, + "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": 63, + "end_line": 65, + "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": 67, + "end_line": 69, + "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": 71, + "end_line": 73, + "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": 75, + "end_line": 77, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "_tocomplex", + "long_name": "_tocomplex( arr )", + "filename": "scimath.py", + "nloc": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "arr" + ], + "start_line": 20, + "end_line": 25, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + } + ], + "nloc": 57, + "complexity": 15, + "token_count": 408, + "diff_parsed": { + "added": [ + "import numpy.core.numerictypes as nt", + "from numpy.core.numeric import asarray, any", + "from numpy.lib.type_check import isreal, asscalar", + "_ln2 = nx.log(2.0)", + " if isinstance(arr.dtype, (nt.single, nt.byte, nt.short, nt.ubyte,", + " nt.ushort)):", + " return arr.astype(nt.csingle)", + " return arr.astype(nt.cdouble)" + ], + "deleted": [ + "from numpy.core.numeric import *", + "from type_check import isreal, asscalar", + "_ln2 = log(2.0)", + " if isinstance(arr.dtype, (nx.single, nx.byte, nx.short, nx.ubyte,", + " nx.ushort)):", + " return arr.astype(nx.csingle)", + " return arr.astype(nx.cdouble)" + ] + } + }, + { + "old_path": "numpy/lib/shape_base.py", + "new_path": "numpy/lib/shape_base.py", + "filename": "shape_base.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -4,7 +4,8 @@\n 'apply_along_axis', 'repmat', 'kron']\n \n import numpy.core.numeric as _nx\n-from numpy.core.numeric import *\n+from numpy.core.numeric import asarray, zeros, newaxis, outerproduct, \\\n+ concatenate, isscalar, array\n from numpy.core.oldnumeric import product, reshape\n \n def apply_along_axis(func1d,axis,arr,*args):\n", + "added_lines": 2, + "deleted_lines": 1, + "source_code": "__all__ = ['atleast_1d','atleast_2d','atleast_3d','vstack','hstack',\n 'column_stack','dstack','array_split','split','hsplit',\n 'vsplit','dsplit','apply_over_axes','expand_dims',\n 'apply_along_axis', 'repmat', 'kron']\n\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import asarray, zeros, newaxis, outerproduct, \\\n concatenate, isscalar, array\nfrom numpy.core.oldnumeric import product, reshape\n\ndef apply_along_axis(func1d,axis,arr,*args):\n \"\"\" Execute func1d(arr[i],*args) where func1d takes 1-D arrays\n and arr is an N-d array. i varies so as to apply the function\n along the given axis for each 1-d subarray in arr.\n \"\"\"\n arr = asarray(arr)\n nd = arr.ndim\n if axis < 0:\n axis += nd\n if (axis >= nd):\n raise ValueError(\"axis must be less than arr.ndim; axis=%d, rank=%d.\"\n % (axis,nd))\n ind = [0]*(nd-1)\n i = zeros(nd,'O')\n indlist = range(nd)\n indlist.remove(axis)\n i[axis] = slice(None,None)\n outshape = asarray(arr.shape).take(indlist)\n i.put(ind, indlist)\n res = func1d(arr[tuple(i.tolist())],*args)\n # if res is a number, then we have a smaller output array\n if isscalar(res):\n outarr = zeros(outshape,asarray(res).dtype)\n outarr[ind] = res\n Ntot = product(outshape)\n k = 1\n while k < Ntot:\n # increment the index\n ind[-1] += 1\n n = -1\n while (ind[n] >= outshape[n]) and (n > (1-nd)):\n ind[n-1] += 1\n ind[n] = 0\n n -= 1\n i.put(ind,indlist)\n res = func1d(arr[tuple(i.tolist())],*args)\n outarr[ind] = res\n k += 1\n return outarr\n else:\n Ntot = product(outshape)\n holdshape = outshape\n outshape = list(arr.shape)\n outshape[axis] = len(res)\n outarr = zeros(outshape,asarray(res).dtype)\n outarr[tuple(i.tolist())] = res\n k = 1\n while k < Ntot:\n # increment the index\n ind[-1] += 1\n n = -1\n while (ind[n] >= holdshape[n]) and (n > (1-nd)):\n ind[n-1] += 1\n ind[n] = 0\n n -= 1\n i.put(ind, indlist)\n res = func1d(arr[tuple(i.tolist())],*args)\n outarr[tuple(i.tolist())] = res\n k += 1\n return outarr\n\n\ndef apply_over_axes(func, a, axes):\n \"\"\"Apply a function repeatedly over multiple axes, keeping the same shape\n for the resulting array.\n\n func is called as res = func(a, axis). The result is assumed\n to be either the same shape as a or have one less dimension.\n This call is repeated for each axis in the axes sequence.\n \"\"\"\n val = asarray(a)\n N = a.ndim\n if array(axes).ndim == 0:\n axes = (axes,)\n for axis in axes:\n if axis < 0: axis = N + axis\n args = (val, axis)\n res = func(*args)\n if res.ndim == val.ndim:\n val = res\n else:\n res = expand_dims(res,axis)\n if res.ndim == val.ndim:\n val = res\n else:\n raise ValueError, \"function is not returning\"\\\n \" an array of correct shape\"\n return val\n\ndef expand_dims(a, axis):\n \"\"\"Expand the shape of a by including newaxis before given axis.\n \"\"\"\n a = asarray(a)\n shape = a.shape\n if axis < 0:\n axis = axis + len(shape) + 1\n return a.reshape(shape[:axis] + (1,) + shape[axis:])\n\n\ndef atleast_1d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 1D.\n\n Description:\n Force an array to be at least 1D. If an array is 0D, the\n array is converted to a single row of values. Otherwise,\n the array is unaltered.\n Arguments:\n *arys -- arrays to be converted to 1 or more dimensional array.\n Returns:\n input array converted to at least 1D array.\n \"\"\"\n res = []\n for ary in arys:\n res.append(asarray(ary,ndmin=1))\n if len(res) == 1:\n return res[0]\n else:\n return res\n\ndef atleast_2d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 2D.\n\n Description:\n Force an array to each be at least 2D. If the array\n is 0D or 1D, the array is converted to a single\n row of values. Otherwise, the array is unaltered.\n Arguments:\n arys -- arrays to be converted to 2 or more dimensional array.\n Returns:\n input array converted to at least 2D array.\n \"\"\"\n res = []\n for ary in arys:\n res.append(asarray(ary,ndmin=2))\n if len(res) == 1:\n return res[0]\n else:\n return res\n\ndef atleast_3d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 3D.\n\n Description:\n Force an array each be at least 3D. If the array is 0D or 1D,\n the array is converted to a single 1xNx1 array of values where\n N is the orginal length of the array. If the array is 2D, the\n array is converted to a single MxNx1 array of values where MxN\n is the orginal shape of the array. Otherwise, the array is\n unaltered.\n Arguments:\n arys -- arrays to be converted to 3 or more dimensional array.\n Returns:\n input array converted to at least 3D array.\n \"\"\"\n res = []\n for ary in arys:\n ary = asarray(ary)\n if len(ary.shape) == 0:\n result = ary.reshape(1,1,1)\n elif len(ary.shape) == 1:\n result = ary[newaxis,:,newaxis]\n elif len(ary.shape) == 2:\n result = ary[:,:,newaxis]\n else:\n result = ary\n res.append(result)\n if len(res) == 1:\n return res[0]\n else:\n return res\n\n\ndef vstack(tup):\n \"\"\" Stack arrays in sequence vertically (row wise)\n\n Description:\n Take a sequence of arrays and stack them veritcally\n to make a single array. All arrays in the sequence\n must have the same shape along all but the first axis.\n vstack will rebuild arrays divided by vsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same\n shape.\n Examples:\n >>> import numpy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> numpy.vstack((a,b))\n array([[1, 2, 3],\n [2, 3, 4]])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> numpy.vstack((a,b))\n array([[1],\n [2],\n [3],\n [2],\n [3],\n [4]])\n\n \"\"\"\n return _nx.concatenate(map(atleast_2d,tup),0)\n\ndef hstack(tup):\n \"\"\" Stack arrays in sequence horizontally (column wise)\n\n Description:\n Take a sequence of arrays and stack them horizontally\n to make a single array. All arrays in the sequence\n must have the same shape along all but the second axis.\n hstack will rebuild arrays divided by hsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same\n shape.\n Examples:\n >>> import numpy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> numpy.hstack((a,b))\n array([1, 2, 3, 2, 3, 4])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> numpy.hstack((a,b))\n array([[1, 2],\n [2, 3],\n [3, 4]])\n\n \"\"\"\n return _nx.concatenate(map(atleast_1d,tup),1)\n\ndef column_stack(tup):\n \"\"\" Stack 1D arrays as columns into a 2D array\n\n Description:\n Take a sequence of 1D arrays and stack them as columns\n to make a single 2D array. All arrays in the sequence\n must have the same length.\n Arguments:\n tup -- sequence of 1D arrays. All arrays must have the same\n length.\n Examples:\n >>> import numpy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> numpy.column_stack((a,b))\n array([[1, 2],\n [2, 3],\n [3, 4]])\n\n \"\"\"\n arrays = map(_nx.transpose,map(atleast_2d,tup))\n return _nx.concatenate(arrays,1)\n\ndef dstack(tup):\n \"\"\" Stack arrays in sequence depth wise (along third dimension)\n\n Description:\n Take a sequence of arrays and stack them along the third axis.\n All arrays in the sequence must have the same shape along all\n but the third axis. This is a simple way to stack 2D arrays\n (images) into a single 3D array for processing.\n dstack will rebuild arrays divided by dsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same\n shape.\n Examples:\n >>> import numpy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> numpy.dstack((a,b))\n array([ [[1, 2],\n [2, 3],\n [3, 4]]])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> numpy.dstack((a,b))\n array([[ [1, 2]],\n [ [2, 3]],\n [ [3, 4]]])\n \"\"\"\n return _nx.concatenate(map(atleast_3d,tup),2)\n\ndef _replace_zero_by_x_arrays(sub_arys):\n for i in range(len(sub_arys)):\n if len(_nx.shape(sub_arys[i])) == 0:\n sub_arys[i] = _nx.array([])\n elif _nx.sometrue(_nx.equal(_nx.shape(sub_arys[i]),0)):\n sub_arys[i] = _nx.array([])\n return sub_arys\n\ndef array_split(ary,indices_or_sections,axis = 0):\n \"\"\" Divide an array into a list of sub-arrays.\n\n Description:\n Divide ary into a list of sub-arrays along the\n specified axis. If indices_or_sections is an integer,\n ary is divided into that many equally sized arrays.\n If it is impossible to make an equal split, each of the\n leading arrays in the list have one additional member. If\n indices_or_sections is a list of sorted integers, its\n entries define the indexes where ary is split.\n\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n axis -- integer. default=0.\n Specifies the axis along which to split ary.\n Caveats:\n Currently, the default for axis is 0. This\n means a 2D array is divided into multiple groups\n of rows. This seems like the appropriate default, but\n we've agreed most other functions should default to\n axis=-1. Perhaps we should use axis=-1 for consistency.\n However, we could also make the argument that NumPy\n works on \"rows\" by default. sum() sums up rows of\n values. split() will split data into rows. Opinions?\n \"\"\"\n try:\n Ntotal = ary.shape[axis]\n except AttributeError:\n Ntotal = len(ary)\n try: # handle scalar case.\n Nsections = len(indices_or_sections) + 1\n div_points = [0] + list(indices_or_sections) + [Ntotal]\n except TypeError: #indices_or_sections is a scalar, not an array.\n Nsections = int(indices_or_sections)\n if Nsections <= 0:\n raise ValueError, 'number sections must be larger than 0.'\n Neach_section,extras = divmod(Ntotal,Nsections)\n section_sizes = [0] + \\\n extras * [Neach_section+1] + \\\n (Nsections-extras) * [Neach_section]\n div_points = _nx.array(section_sizes).cumsum()\n\n sub_arys = []\n sary = _nx.swapaxes(ary,axis,0)\n for i in range(Nsections):\n st = div_points[i]; end = div_points[i+1]\n sub_arys.append(_nx.swapaxes(sary[st:end],axis,0))\n\n # there is a wierd issue with array slicing that allows\n # 0x10 arrays and other such things. The following cluge is needed\n # to get around this issue.\n sub_arys = _replace_zero_by_x_arrays(sub_arys)\n # end cluge.\n\n return sub_arys\n\ndef split(ary,indices_or_sections,axis=0):\n \"\"\" Divide an array into a list of sub-arrays.\n\n Description:\n Divide ary into a list of sub-arrays along the\n specified axis. If indices_or_sections is an integer,\n ary is divided into that many equally sized arrays.\n If it is impossible to make an equal split, an error is\n raised. This is the only way this function differs from\n the array_split() function. If indices_or_sections is a\n list of sorted integers, its entries define the indexes\n where ary is split.\n\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n axis -- integer. default=0.\n Specifies the axis along which to split ary.\n Caveats:\n Currently, the default for axis is 0. This\n means a 2D array is divided into multiple groups\n of rows. This seems like the appropriate default, but\n we've agreed most other functions should default to\n axis=-1. Perhaps we should use axis=-1 for consistency.\n However, we could also make the argument that NumPy\n works on \"rows\" by default. sum() sums up rows of\n values. split() will split data into rows. Opinions?\n \"\"\"\n try: len(indices_or_sections)\n except TypeError:\n sections = indices_or_sections\n N = ary.shape[axis]\n if N % sections:\n raise ValueError, 'array split does not result in an equal division'\n res = array_split(ary,indices_or_sections,axis)\n return res\n\ndef hsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple columns of sub-arrays\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups of columns. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections.\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same\n number of dimensions as the input array.\n Related:\n hstack, split, array_split, vsplit, dsplit.\n Examples:\n >>> import numpy\n >>> a= array((1,2,3,4))\n >>> numpy.hsplit(a,2)\n [array([1, 2]), array([3, 4])]\n >>> a = array([[1,2,3,4],[1,2,3,4]])\n [array([[1, 2],\n [1, 2]]), array([[3, 4],\n [3, 4]])]\n\n \"\"\"\n if len(_nx.shape(ary)) == 0:\n raise ValueError, 'hsplit only works on arrays of 1 or more dimensions'\n if len(ary.shape) > 1:\n return split(ary,indices_or_sections,1)\n else:\n return split(ary,indices_or_sections,0)\n\ndef vsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple rows of sub-arrays\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups of rows. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections.\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same\n number of dimensions as the input array.\n Caveats:\n How should we handle 1D arrays here? I am currently raising\n an error when I encounter them. Any better approach?\n\n Should we reduce the returned array to their minium dimensions\n by getting rid of any dimensions that are 1?\n Related:\n vstack, split, array_split, hsplit, dsplit.\n Examples:\n import numpy\n >>> a = array([[1,2,3,4],\n ... [1,2,3,4]])\n >>> numpy.vsplit(a)\n [array([ [1, 2, 3, 4]]), array([ [1, 2, 3, 4]])]\n\n \"\"\"\n if len(_nx.shape(ary)) < 2:\n raise ValueError, 'vsplit only works on arrays of 2 or more dimensions'\n return split(ary,indices_or_sections,0)\n\ndef dsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple sub-arrays along the 3rd axis (depth)\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups along the 3rd axis. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections.\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same\n number of dimensions as the input array.\n Caveats:\n See vsplit caveats.\n Related:\n dstack, split, array_split, hsplit, vsplit.\n Examples:\n >>> a = array([[[1,2,3,4],[1,2,3,4]]])\n [array([ [[1, 2],\n [1, 2]]]), array([ [[3, 4],\n [3, 4]]])]\n\n \"\"\"\n if len(_nx.shape(ary)) < 3:\n raise ValueError, 'vsplit only works on arrays of 3 or more dimensions'\n return split(ary,indices_or_sections,2)\n\n# should figure out how to generalize this one.\ndef repmat(a, m, n):\n \"\"\"Repeat a 0-d to 2-d array mxn times\n \"\"\"\n a = asarray(a)\n ndim = a.ndim\n if ndim == 0:\n origrows, origcols = (1,1)\n elif ndim == 1:\n origrows, origcols = (1, a.shape[0])\n else:\n origrows, origcols = a.shape\n rows = origrows * m\n cols = origcols * n\n c = a.reshape(1,a.size).repeat(m, 0).reshape(rows, origcols).repeat(n,0)\n return c.reshape(rows, cols)\n\n\ndef kron(a,b):\n \"\"\"kronecker product of a and b\n\n Kronecker product of two matrices is block matrix\n [[ a[ 0 ,0]*b, a[ 0 ,1]*b, ... , a[ 0 ,n-1]*b ],\n [ ... ... ],\n [ a[m-1,0]*b, a[m-1,1]*b, ... , a[m-1,n-1]*b ]]\n \"\"\"\n if not a.flags.contiguous:\n a = reshape(a, a.shape)\n if not b.flags.contiguous:\n b = reshape(b, b.shape)\n o = outerproduct(a,b)\n o=o.reshape(a.shape + b.shape)\n return concatenate(concatenate(o, axis=1), axis=1)\n", + "source_code_before": "__all__ = ['atleast_1d','atleast_2d','atleast_3d','vstack','hstack',\n 'column_stack','dstack','array_split','split','hsplit',\n 'vsplit','dsplit','apply_over_axes','expand_dims',\n 'apply_along_axis', 'repmat', 'kron']\n\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import *\nfrom numpy.core.oldnumeric import product, reshape\n\ndef apply_along_axis(func1d,axis,arr,*args):\n \"\"\" Execute func1d(arr[i],*args) where func1d takes 1-D arrays\n and arr is an N-d array. i varies so as to apply the function\n along the given axis for each 1-d subarray in arr.\n \"\"\"\n arr = asarray(arr)\n nd = arr.ndim\n if axis < 0:\n axis += nd\n if (axis >= nd):\n raise ValueError(\"axis must be less than arr.ndim; axis=%d, rank=%d.\"\n % (axis,nd))\n ind = [0]*(nd-1)\n i = zeros(nd,'O')\n indlist = range(nd)\n indlist.remove(axis)\n i[axis] = slice(None,None)\n outshape = asarray(arr.shape).take(indlist)\n i.put(ind, indlist)\n res = func1d(arr[tuple(i.tolist())],*args)\n # if res is a number, then we have a smaller output array\n if isscalar(res):\n outarr = zeros(outshape,asarray(res).dtype)\n outarr[ind] = res\n Ntot = product(outshape)\n k = 1\n while k < Ntot:\n # increment the index\n ind[-1] += 1\n n = -1\n while (ind[n] >= outshape[n]) and (n > (1-nd)):\n ind[n-1] += 1\n ind[n] = 0\n n -= 1\n i.put(ind,indlist)\n res = func1d(arr[tuple(i.tolist())],*args)\n outarr[ind] = res\n k += 1\n return outarr\n else:\n Ntot = product(outshape)\n holdshape = outshape\n outshape = list(arr.shape)\n outshape[axis] = len(res)\n outarr = zeros(outshape,asarray(res).dtype)\n outarr[tuple(i.tolist())] = res\n k = 1\n while k < Ntot:\n # increment the index\n ind[-1] += 1\n n = -1\n while (ind[n] >= holdshape[n]) and (n > (1-nd)):\n ind[n-1] += 1\n ind[n] = 0\n n -= 1\n i.put(ind, indlist)\n res = func1d(arr[tuple(i.tolist())],*args)\n outarr[tuple(i.tolist())] = res\n k += 1\n return outarr\n\n\ndef apply_over_axes(func, a, axes):\n \"\"\"Apply a function repeatedly over multiple axes, keeping the same shape\n for the resulting array.\n\n func is called as res = func(a, axis). The result is assumed\n to be either the same shape as a or have one less dimension.\n This call is repeated for each axis in the axes sequence.\n \"\"\"\n val = asarray(a)\n N = a.ndim\n if array(axes).ndim == 0:\n axes = (axes,)\n for axis in axes:\n if axis < 0: axis = N + axis\n args = (val, axis)\n res = func(*args)\n if res.ndim == val.ndim:\n val = res\n else:\n res = expand_dims(res,axis)\n if res.ndim == val.ndim:\n val = res\n else:\n raise ValueError, \"function is not returning\"\\\n \" an array of correct shape\"\n return val\n\ndef expand_dims(a, axis):\n \"\"\"Expand the shape of a by including newaxis before given axis.\n \"\"\"\n a = asarray(a)\n shape = a.shape\n if axis < 0:\n axis = axis + len(shape) + 1\n return a.reshape(shape[:axis] + (1,) + shape[axis:])\n\n\ndef atleast_1d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 1D.\n\n Description:\n Force an array to be at least 1D. If an array is 0D, the\n array is converted to a single row of values. Otherwise,\n the array is unaltered.\n Arguments:\n *arys -- arrays to be converted to 1 or more dimensional array.\n Returns:\n input array converted to at least 1D array.\n \"\"\"\n res = []\n for ary in arys:\n res.append(asarray(ary,ndmin=1))\n if len(res) == 1:\n return res[0]\n else:\n return res\n\ndef atleast_2d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 2D.\n\n Description:\n Force an array to each be at least 2D. If the array\n is 0D or 1D, the array is converted to a single\n row of values. Otherwise, the array is unaltered.\n Arguments:\n arys -- arrays to be converted to 2 or more dimensional array.\n Returns:\n input array converted to at least 2D array.\n \"\"\"\n res = []\n for ary in arys:\n res.append(asarray(ary,ndmin=2))\n if len(res) == 1:\n return res[0]\n else:\n return res\n\ndef atleast_3d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 3D.\n\n Description:\n Force an array each be at least 3D. If the array is 0D or 1D,\n the array is converted to a single 1xNx1 array of values where\n N is the orginal length of the array. If the array is 2D, the\n array is converted to a single MxNx1 array of values where MxN\n is the orginal shape of the array. Otherwise, the array is\n unaltered.\n Arguments:\n arys -- arrays to be converted to 3 or more dimensional array.\n Returns:\n input array converted to at least 3D array.\n \"\"\"\n res = []\n for ary in arys:\n ary = asarray(ary)\n if len(ary.shape) == 0:\n result = ary.reshape(1,1,1)\n elif len(ary.shape) == 1:\n result = ary[newaxis,:,newaxis]\n elif len(ary.shape) == 2:\n result = ary[:,:,newaxis]\n else:\n result = ary\n res.append(result)\n if len(res) == 1:\n return res[0]\n else:\n return res\n\n\ndef vstack(tup):\n \"\"\" Stack arrays in sequence vertically (row wise)\n\n Description:\n Take a sequence of arrays and stack them veritcally\n to make a single array. All arrays in the sequence\n must have the same shape along all but the first axis.\n vstack will rebuild arrays divided by vsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same\n shape.\n Examples:\n >>> import numpy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> numpy.vstack((a,b))\n array([[1, 2, 3],\n [2, 3, 4]])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> numpy.vstack((a,b))\n array([[1],\n [2],\n [3],\n [2],\n [3],\n [4]])\n\n \"\"\"\n return _nx.concatenate(map(atleast_2d,tup),0)\n\ndef hstack(tup):\n \"\"\" Stack arrays in sequence horizontally (column wise)\n\n Description:\n Take a sequence of arrays and stack them horizontally\n to make a single array. All arrays in the sequence\n must have the same shape along all but the second axis.\n hstack will rebuild arrays divided by hsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same\n shape.\n Examples:\n >>> import numpy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> numpy.hstack((a,b))\n array([1, 2, 3, 2, 3, 4])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> numpy.hstack((a,b))\n array([[1, 2],\n [2, 3],\n [3, 4]])\n\n \"\"\"\n return _nx.concatenate(map(atleast_1d,tup),1)\n\ndef column_stack(tup):\n \"\"\" Stack 1D arrays as columns into a 2D array\n\n Description:\n Take a sequence of 1D arrays and stack them as columns\n to make a single 2D array. All arrays in the sequence\n must have the same length.\n Arguments:\n tup -- sequence of 1D arrays. All arrays must have the same\n length.\n Examples:\n >>> import numpy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> numpy.column_stack((a,b))\n array([[1, 2],\n [2, 3],\n [3, 4]])\n\n \"\"\"\n arrays = map(_nx.transpose,map(atleast_2d,tup))\n return _nx.concatenate(arrays,1)\n\ndef dstack(tup):\n \"\"\" Stack arrays in sequence depth wise (along third dimension)\n\n Description:\n Take a sequence of arrays and stack them along the third axis.\n All arrays in the sequence must have the same shape along all\n but the third axis. This is a simple way to stack 2D arrays\n (images) into a single 3D array for processing.\n dstack will rebuild arrays divided by dsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same\n shape.\n Examples:\n >>> import numpy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> numpy.dstack((a,b))\n array([ [[1, 2],\n [2, 3],\n [3, 4]]])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> numpy.dstack((a,b))\n array([[ [1, 2]],\n [ [2, 3]],\n [ [3, 4]]])\n \"\"\"\n return _nx.concatenate(map(atleast_3d,tup),2)\n\ndef _replace_zero_by_x_arrays(sub_arys):\n for i in range(len(sub_arys)):\n if len(_nx.shape(sub_arys[i])) == 0:\n sub_arys[i] = _nx.array([])\n elif _nx.sometrue(_nx.equal(_nx.shape(sub_arys[i]),0)):\n sub_arys[i] = _nx.array([])\n return sub_arys\n\ndef array_split(ary,indices_or_sections,axis = 0):\n \"\"\" Divide an array into a list of sub-arrays.\n\n Description:\n Divide ary into a list of sub-arrays along the\n specified axis. If indices_or_sections is an integer,\n ary is divided into that many equally sized arrays.\n If it is impossible to make an equal split, each of the\n leading arrays in the list have one additional member. If\n indices_or_sections is a list of sorted integers, its\n entries define the indexes where ary is split.\n\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n axis -- integer. default=0.\n Specifies the axis along which to split ary.\n Caveats:\n Currently, the default for axis is 0. This\n means a 2D array is divided into multiple groups\n of rows. This seems like the appropriate default, but\n we've agreed most other functions should default to\n axis=-1. Perhaps we should use axis=-1 for consistency.\n However, we could also make the argument that NumPy\n works on \"rows\" by default. sum() sums up rows of\n values. split() will split data into rows. Opinions?\n \"\"\"\n try:\n Ntotal = ary.shape[axis]\n except AttributeError:\n Ntotal = len(ary)\n try: # handle scalar case.\n Nsections = len(indices_or_sections) + 1\n div_points = [0] + list(indices_or_sections) + [Ntotal]\n except TypeError: #indices_or_sections is a scalar, not an array.\n Nsections = int(indices_or_sections)\n if Nsections <= 0:\n raise ValueError, 'number sections must be larger than 0.'\n Neach_section,extras = divmod(Ntotal,Nsections)\n section_sizes = [0] + \\\n extras * [Neach_section+1] + \\\n (Nsections-extras) * [Neach_section]\n div_points = _nx.array(section_sizes).cumsum()\n\n sub_arys = []\n sary = _nx.swapaxes(ary,axis,0)\n for i in range(Nsections):\n st = div_points[i]; end = div_points[i+1]\n sub_arys.append(_nx.swapaxes(sary[st:end],axis,0))\n\n # there is a wierd issue with array slicing that allows\n # 0x10 arrays and other such things. The following cluge is needed\n # to get around this issue.\n sub_arys = _replace_zero_by_x_arrays(sub_arys)\n # end cluge.\n\n return sub_arys\n\ndef split(ary,indices_or_sections,axis=0):\n \"\"\" Divide an array into a list of sub-arrays.\n\n Description:\n Divide ary into a list of sub-arrays along the\n specified axis. If indices_or_sections is an integer,\n ary is divided into that many equally sized arrays.\n If it is impossible to make an equal split, an error is\n raised. This is the only way this function differs from\n the array_split() function. If indices_or_sections is a\n list of sorted integers, its entries define the indexes\n where ary is split.\n\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n axis -- integer. default=0.\n Specifies the axis along which to split ary.\n Caveats:\n Currently, the default for axis is 0. This\n means a 2D array is divided into multiple groups\n of rows. This seems like the appropriate default, but\n we've agreed most other functions should default to\n axis=-1. Perhaps we should use axis=-1 for consistency.\n However, we could also make the argument that NumPy\n works on \"rows\" by default. sum() sums up rows of\n values. split() will split data into rows. Opinions?\n \"\"\"\n try: len(indices_or_sections)\n except TypeError:\n sections = indices_or_sections\n N = ary.shape[axis]\n if N % sections:\n raise ValueError, 'array split does not result in an equal division'\n res = array_split(ary,indices_or_sections,axis)\n return res\n\ndef hsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple columns of sub-arrays\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups of columns. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections.\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same\n number of dimensions as the input array.\n Related:\n hstack, split, array_split, vsplit, dsplit.\n Examples:\n >>> import numpy\n >>> a= array((1,2,3,4))\n >>> numpy.hsplit(a,2)\n [array([1, 2]), array([3, 4])]\n >>> a = array([[1,2,3,4],[1,2,3,4]])\n [array([[1, 2],\n [1, 2]]), array([[3, 4],\n [3, 4]])]\n\n \"\"\"\n if len(_nx.shape(ary)) == 0:\n raise ValueError, 'hsplit only works on arrays of 1 or more dimensions'\n if len(ary.shape) > 1:\n return split(ary,indices_or_sections,1)\n else:\n return split(ary,indices_or_sections,0)\n\ndef vsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple rows of sub-arrays\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups of rows. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections.\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same\n number of dimensions as the input array.\n Caveats:\n How should we handle 1D arrays here? I am currently raising\n an error when I encounter them. Any better approach?\n\n Should we reduce the returned array to their minium dimensions\n by getting rid of any dimensions that are 1?\n Related:\n vstack, split, array_split, hsplit, dsplit.\n Examples:\n import numpy\n >>> a = array([[1,2,3,4],\n ... [1,2,3,4]])\n >>> numpy.vsplit(a)\n [array([ [1, 2, 3, 4]]), array([ [1, 2, 3, 4]])]\n\n \"\"\"\n if len(_nx.shape(ary)) < 2:\n raise ValueError, 'vsplit only works on arrays of 2 or more dimensions'\n return split(ary,indices_or_sections,0)\n\ndef dsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple sub-arrays along the 3rd axis (depth)\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups along the 3rd axis. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections.\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same\n number of dimensions as the input array.\n Caveats:\n See vsplit caveats.\n Related:\n dstack, split, array_split, hsplit, vsplit.\n Examples:\n >>> a = array([[[1,2,3,4],[1,2,3,4]]])\n [array([ [[1, 2],\n [1, 2]]]), array([ [[3, 4],\n [3, 4]]])]\n\n \"\"\"\n if len(_nx.shape(ary)) < 3:\n raise ValueError, 'vsplit only works on arrays of 3 or more dimensions'\n return split(ary,indices_or_sections,2)\n\n# should figure out how to generalize this one.\ndef repmat(a, m, n):\n \"\"\"Repeat a 0-d to 2-d array mxn times\n \"\"\"\n a = asarray(a)\n ndim = a.ndim\n if ndim == 0:\n origrows, origcols = (1,1)\n elif ndim == 1:\n origrows, origcols = (1, a.shape[0])\n else:\n origrows, origcols = a.shape\n rows = origrows * m\n cols = origcols * n\n c = a.reshape(1,a.size).repeat(m, 0).reshape(rows, origcols).repeat(n,0)\n return c.reshape(rows, cols)\n\n\ndef kron(a,b):\n \"\"\"kronecker product of a and b\n\n Kronecker product of two matrices is block matrix\n [[ a[ 0 ,0]*b, a[ 0 ,1]*b, ... , a[ 0 ,n-1]*b ],\n [ ... ... ],\n [ a[m-1,0]*b, a[m-1,1]*b, ... , a[m-1,n-1]*b ]]\n \"\"\"\n if not a.flags.contiguous:\n a = reshape(a, a.shape)\n if not b.flags.contiguous:\n b = reshape(b, b.shape)\n o = outerproduct(a,b)\n o=o.reshape(a.shape + b.shape)\n return concatenate(concatenate(o, axis=1), axis=1)\n", + "methods": [ + { + "name": "apply_along_axis", + "long_name": "apply_along_axis( func1d , axis , arr , * args )", + "filename": "shape_base.py", + "nloc": 53, + "complexity": 10, + "token_count": 418, + "parameters": [ + "func1d", + "axis", + "arr", + "args" + ], + "start_line": 11, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "apply_over_axes", + "long_name": "apply_over_axes( func , a , axes )", + "filename": "shape_base.py", + "nloc": 19, + "complexity": 6, + "token_count": 110, + "parameters": [ + "func", + "a", + "axes" + ], + "start_line": 73, + "end_line": 98, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "expand_dims", + "long_name": "expand_dims( a , axis )", + "filename": "shape_base.py", + "nloc": 6, + "complexity": 2, + "token_count": 56, + "parameters": [ + "a", + "axis" + ], + "start_line": 100, + "end_line": 107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "atleast_1d", + "long_name": "atleast_1d( * arys )", + "filename": "shape_base.py", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "arys" + ], + "start_line": 110, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "atleast_2d", + "long_name": "atleast_2d( * arys )", + "filename": "shape_base.py", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "arys" + ], + "start_line": 130, + "end_line": 148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "atleast_3d", + "long_name": "atleast_3d( * arys )", + "filename": "shape_base.py", + "nloc": 17, + "complexity": 6, + "token_count": 112, + "parameters": [ + "arys" + ], + "start_line": 150, + "end_line": 180, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "vstack", + "long_name": "vstack( tup )", + "filename": "shape_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "tup" + ], + "start_line": 183, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "hstack", + "long_name": "hstack( tup )", + "filename": "shape_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "tup" + ], + "start_line": 214, + "end_line": 239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "column_stack", + "long_name": "column_stack( tup )", + "filename": "shape_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 30, + "parameters": [ + "tup" + ], + "start_line": 241, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dstack", + "long_name": "dstack( tup )", + "filename": "shape_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "tup" + ], + "start_line": 264, + "end_line": 291, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "_replace_zero_by_x_arrays", + "long_name": "_replace_zero_by_x_arrays( sub_arys )", + "filename": "shape_base.py", + "nloc": 7, + "complexity": 4, + "token_count": 81, + "parameters": [ + "sub_arys" + ], + "start_line": 293, + "end_line": 299, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_split", + "long_name": "array_split( ary , indices_or_sections , axis = 0 )", + "filename": "shape_base.py", + "nloc": 24, + "complexity": 5, + "token_count": 187, + "parameters": [ + "ary", + "indices_or_sections", + "axis" + ], + "start_line": 301, + "end_line": 363, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "split", + "long_name": "split( ary , indices_or_sections , axis = 0 )", + "filename": "shape_base.py", + "nloc": 9, + "complexity": 3, + "token_count": 53, + "parameters": [ + "ary", + "indices_or_sections", + "axis" + ], + "start_line": 365, + "end_line": 406, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "hsplit", + "long_name": "hsplit( ary , indices_or_sections )", + "filename": "shape_base.py", + "nloc": 7, + "complexity": 3, + "token_count": 55, + "parameters": [ + "ary", + "indices_or_sections" + ], + "start_line": 408, + "end_line": 448, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "vsplit", + "long_name": "vsplit( ary , indices_or_sections )", + "filename": "shape_base.py", + "nloc": 4, + "complexity": 2, + "token_count": 34, + "parameters": [ + "ary", + "indices_or_sections" + ], + "start_line": 450, + "end_line": 490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "dsplit", + "long_name": "dsplit( ary , indices_or_sections )", + "filename": "shape_base.py", + "nloc": 4, + "complexity": 2, + "token_count": 34, + "parameters": [ + "ary", + "indices_or_sections" + ], + "start_line": 492, + "end_line": 527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "repmat", + "long_name": "repmat( a , m , n )", + "filename": "shape_base.py", + "nloc": 13, + "complexity": 3, + "token_count": 115, + "parameters": [ + "a", + "m", + "n" + ], + "start_line": 530, + "end_line": 544, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "kron", + "long_name": "kron( a , b )", + "filename": "shape_base.py", + "nloc": 8, + "complexity": 3, + "token_count": 82, + "parameters": [ + "a", + "b" + ], + "start_line": 547, + "end_line": 561, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "apply_along_axis", + "long_name": "apply_along_axis( func1d , axis , arr , * args )", + "filename": "shape_base.py", + "nloc": 53, + "complexity": 10, + "token_count": 418, + "parameters": [ + "func1d", + "axis", + "arr", + "args" + ], + "start_line": 10, + "end_line": 69, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "apply_over_axes", + "long_name": "apply_over_axes( func , a , axes )", + "filename": "shape_base.py", + "nloc": 19, + "complexity": 6, + "token_count": 110, + "parameters": [ + "func", + "a", + "axes" + ], + "start_line": 72, + "end_line": 97, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "expand_dims", + "long_name": "expand_dims( a , axis )", + "filename": "shape_base.py", + "nloc": 6, + "complexity": 2, + "token_count": 56, + "parameters": [ + "a", + "axis" + ], + "start_line": 99, + "end_line": 106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "atleast_1d", + "long_name": "atleast_1d( * arys )", + "filename": "shape_base.py", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "arys" + ], + "start_line": 109, + "end_line": 127, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "atleast_2d", + "long_name": "atleast_2d( * arys )", + "filename": "shape_base.py", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "arys" + ], + "start_line": 129, + "end_line": 147, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "atleast_3d", + "long_name": "atleast_3d( * arys )", + "filename": "shape_base.py", + "nloc": 17, + "complexity": 6, + "token_count": 112, + "parameters": [ + "arys" + ], + "start_line": 149, + "end_line": 179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "vstack", + "long_name": "vstack( tup )", + "filename": "shape_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "tup" + ], + "start_line": 182, + "end_line": 211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "hstack", + "long_name": "hstack( tup )", + "filename": "shape_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "tup" + ], + "start_line": 213, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "column_stack", + "long_name": "column_stack( tup )", + "filename": "shape_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 30, + "parameters": [ + "tup" + ], + "start_line": 240, + "end_line": 261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dstack", + "long_name": "dstack( tup )", + "filename": "shape_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "tup" + ], + "start_line": 263, + "end_line": 290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "_replace_zero_by_x_arrays", + "long_name": "_replace_zero_by_x_arrays( sub_arys )", + "filename": "shape_base.py", + "nloc": 7, + "complexity": 4, + "token_count": 81, + "parameters": [ + "sub_arys" + ], + "start_line": 292, + "end_line": 298, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_split", + "long_name": "array_split( ary , indices_or_sections , axis = 0 )", + "filename": "shape_base.py", + "nloc": 24, + "complexity": 5, + "token_count": 187, + "parameters": [ + "ary", + "indices_or_sections", + "axis" + ], + "start_line": 300, + "end_line": 362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "split", + "long_name": "split( ary , indices_or_sections , axis = 0 )", + "filename": "shape_base.py", + "nloc": 9, + "complexity": 3, + "token_count": 53, + "parameters": [ + "ary", + "indices_or_sections", + "axis" + ], + "start_line": 364, + "end_line": 405, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "hsplit", + "long_name": "hsplit( ary , indices_or_sections )", + "filename": "shape_base.py", + "nloc": 7, + "complexity": 3, + "token_count": 55, + "parameters": [ + "ary", + "indices_or_sections" + ], + "start_line": 407, + "end_line": 447, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "vsplit", + "long_name": "vsplit( ary , indices_or_sections )", + "filename": "shape_base.py", + "nloc": 4, + "complexity": 2, + "token_count": 34, + "parameters": [ + "ary", + "indices_or_sections" + ], + "start_line": 449, + "end_line": 489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "dsplit", + "long_name": "dsplit( ary , indices_or_sections )", + "filename": "shape_base.py", + "nloc": 4, + "complexity": 2, + "token_count": 34, + "parameters": [ + "ary", + "indices_or_sections" + ], + "start_line": 491, + "end_line": 526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "repmat", + "long_name": "repmat( a , m , n )", + "filename": "shape_base.py", + "nloc": 13, + "complexity": 3, + "token_count": 115, + "parameters": [ + "a", + "m", + "n" + ], + "start_line": 529, + "end_line": 543, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "kron", + "long_name": "kron( a , b )", + "filename": "shape_base.py", + "nloc": 8, + "complexity": 3, + "token_count": 82, + "parameters": [ + "a", + "b" + ], + "start_line": 546, + "end_line": 560, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 204, + "complexity": 59, + "token_count": 1613, + "diff_parsed": { + "added": [ + "from numpy.core.numeric import asarray, zeros, newaxis, outerproduct, \\", + " concatenate, isscalar, array" + ], + "deleted": [ + "from numpy.core.numeric import *" + ] + } + }, + { + "old_path": "numpy/lib/twodim_base.py", + "new_path": "numpy/lib/twodim_base.py", + "filename": "twodim_base.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -5,7 +5,8 @@\n __all__ = ['diag','eye','fliplr','flipud','rot90','tri','triu','tril',\n 'vander']\n \n-from numpy.core.numeric import *\n+from numpy.core.numeric import asanyarray, int_, equal, subtract, arange, \\\n+ zeros, arange, greater_equal, multiply, ones, asarray\n import sys\n \n def fliplr(m):\n", + "added_lines": 2, + "deleted_lines": 1, + "source_code": "\"\"\" Basic functions for manipulating 2d arrays\n\n\"\"\"\n\n__all__ = ['diag','eye','fliplr','flipud','rot90','tri','triu','tril',\n 'vander']\n\nfrom numpy.core.numeric import asanyarray, int_, equal, subtract, arange, \\\n zeros, arange, greater_equal, multiply, ones, asarray\nimport sys\n\ndef fliplr(m):\n \"\"\" returns an array m with the rows preserved and columns flipped\n in the left/right direction. Works on the first two dimensions of m.\n \"\"\"\n m = asanyarray(m)\n if m.ndim < 2:\n raise ValueError, \"Input must be >= 2-d.\"\n return m[:, ::-1]\n\ndef flipud(m):\n \"\"\" returns an array with the columns preserved and rows flipped in\n the up/down direction. Works on the first dimension of m.\n \"\"\"\n m = asanyarray(m)\n if m.ndim < 1:\n raise ValueError, \"Input must be >= 1-d.\"\n return m[::-1,...]\n\ndef rot90(m, k=1):\n \"\"\" returns the array found by rotating m by k*90\n degrees in the counterclockwise direction. Works on the first two\n dimensions of m.\n \"\"\"\n m = asanyarray(m)\n if m.ndim < 2:\n raise ValueError, \"Input must >= 2-d.\"\n k = k % 4\n if k == 0: return m\n elif k == 1: return fliplr(m).transpose()\n elif k == 2: return fliplr(flipud(m))\n else: return fliplr(m.transpose()) # k==3\n\ndef eye(N, M=None, k=0, dtype=int_):\n \"\"\" eye returns a N-by-M 2-d array where the k-th diagonal is all ones,\n and everything else is zeros.\n \"\"\"\n if M is None: M = N\n m = equal(subtract.outer(arange(N), arange(M)),-k)\n return m.astype(dtype)\n\ndef diag(v, k=0):\n \"\"\" returns the k-th diagonal if v is a array or returns a array\n with v as the k-th diagonal if v is a vector.\n \"\"\"\n v = asarray(v)\n s = v.shape\n if len(s)==1:\n n = s[0]+abs(k)\n res = zeros((n,n), v.dtype)\n if (k>=0):\n i = arange(0,n-k)\n fi = i+k+i*n\n else:\n i = arange(0,n+k)\n fi = i+(i-k)*n\n res.flat[fi] = v\n return res\n elif len(s)==2:\n N1,N2 = s\n if k >= 0:\n M = min(N1,N2-k)\n i = arange(0,M)\n fi = i+k+i*N2\n else:\n M = min(N1+k,N2)\n i = arange(0,M)\n fi = i + (i-k)*N2\n return v.flat[fi]\n else:\n raise ValueError, \"Input must be 1- or 2-d.\"\n\n\ndef tri(N, M=None, k=0, dtype=int_):\n \"\"\" returns a N-by-M array where all the diagonals starting from\n lower left corner up to the k-th are all ones.\n \"\"\"\n if M is None: M = N\n m = greater_equal(subtract.outer(arange(N), arange(M)),-k)\n return m.astype(dtype)\n\ndef tril(m, k=0):\n \"\"\" returns the elements on and below the k-th diagonal of m. k=0 is the\n main diagonal, k > 0 is above and k < 0 is below the main diagonal.\n \"\"\"\n m = asanyarray(m)\n out = multiply(tri(m.shape[0], m.shape[1], k=k, dtype=m.dtype),m)\n return out\n\ndef triu(m, k=0):\n \"\"\" returns the elements on and above the k-th diagonal of m. k=0 is the\n main diagonal, k > 0 is above and k < 0 is below the main diagonal.\n \"\"\"\n m = asanyarray(m)\n out = multiply((1-tri(m.shape[0], m.shape[1], k-1, m.dtype)),m)\n return out\n\n# borrowed from John Hunter and matplotlib\ndef vander(x, N=None):\n \"\"\"\n X = vander(x,N=None)\n\n The Vandermonde matrix of vector x. The i-th column of X is the\n the i-th power of x. N is the maximum power to compute; if N is\n None it defaults to len(x).\n\n \"\"\"\n x = asarray(x)\n if N is None: N=len(x)\n X = ones( (len(x),N), x.dtype)\n for i in range(N-1):\n X[:,i] = x**(N-i-1)\n return X\n", + "source_code_before": "\"\"\" Basic functions for manipulating 2d arrays\n\n\"\"\"\n\n__all__ = ['diag','eye','fliplr','flipud','rot90','tri','triu','tril',\n 'vander']\n\nfrom numpy.core.numeric import *\nimport sys\n\ndef fliplr(m):\n \"\"\" returns an array m with the rows preserved and columns flipped\n in the left/right direction. Works on the first two dimensions of m.\n \"\"\"\n m = asanyarray(m)\n if m.ndim < 2:\n raise ValueError, \"Input must be >= 2-d.\"\n return m[:, ::-1]\n\ndef flipud(m):\n \"\"\" returns an array with the columns preserved and rows flipped in\n the up/down direction. Works on the first dimension of m.\n \"\"\"\n m = asanyarray(m)\n if m.ndim < 1:\n raise ValueError, \"Input must be >= 1-d.\"\n return m[::-1,...]\n\ndef rot90(m, k=1):\n \"\"\" returns the array found by rotating m by k*90\n degrees in the counterclockwise direction. Works on the first two\n dimensions of m.\n \"\"\"\n m = asanyarray(m)\n if m.ndim < 2:\n raise ValueError, \"Input must >= 2-d.\"\n k = k % 4\n if k == 0: return m\n elif k == 1: return fliplr(m).transpose()\n elif k == 2: return fliplr(flipud(m))\n else: return fliplr(m.transpose()) # k==3\n\ndef eye(N, M=None, k=0, dtype=int_):\n \"\"\" eye returns a N-by-M 2-d array where the k-th diagonal is all ones,\n and everything else is zeros.\n \"\"\"\n if M is None: M = N\n m = equal(subtract.outer(arange(N), arange(M)),-k)\n return m.astype(dtype)\n\ndef diag(v, k=0):\n \"\"\" returns the k-th diagonal if v is a array or returns a array\n with v as the k-th diagonal if v is a vector.\n \"\"\"\n v = asarray(v)\n s = v.shape\n if len(s)==1:\n n = s[0]+abs(k)\n res = zeros((n,n), v.dtype)\n if (k>=0):\n i = arange(0,n-k)\n fi = i+k+i*n\n else:\n i = arange(0,n+k)\n fi = i+(i-k)*n\n res.flat[fi] = v\n return res\n elif len(s)==2:\n N1,N2 = s\n if k >= 0:\n M = min(N1,N2-k)\n i = arange(0,M)\n fi = i+k+i*N2\n else:\n M = min(N1+k,N2)\n i = arange(0,M)\n fi = i + (i-k)*N2\n return v.flat[fi]\n else:\n raise ValueError, \"Input must be 1- or 2-d.\"\n\n\ndef tri(N, M=None, k=0, dtype=int_):\n \"\"\" returns a N-by-M array where all the diagonals starting from\n lower left corner up to the k-th are all ones.\n \"\"\"\n if M is None: M = N\n m = greater_equal(subtract.outer(arange(N), arange(M)),-k)\n return m.astype(dtype)\n\ndef tril(m, k=0):\n \"\"\" returns the elements on and below the k-th diagonal of m. k=0 is the\n main diagonal, k > 0 is above and k < 0 is below the main diagonal.\n \"\"\"\n m = asanyarray(m)\n out = multiply(tri(m.shape[0], m.shape[1], k=k, dtype=m.dtype),m)\n return out\n\ndef triu(m, k=0):\n \"\"\" returns the elements on and above the k-th diagonal of m. k=0 is the\n main diagonal, k > 0 is above and k < 0 is below the main diagonal.\n \"\"\"\n m = asanyarray(m)\n out = multiply((1-tri(m.shape[0], m.shape[1], k-1, m.dtype)),m)\n return out\n\n# borrowed from John Hunter and matplotlib\ndef vander(x, N=None):\n \"\"\"\n X = vander(x,N=None)\n\n The Vandermonde matrix of vector x. The i-th column of X is the\n the i-th power of x. N is the maximum power to compute; if N is\n None it defaults to len(x).\n\n \"\"\"\n x = asarray(x)\n if N is None: N=len(x)\n X = ones( (len(x),N), x.dtype)\n for i in range(N-1):\n X[:,i] = x**(N-i-1)\n return X\n", + "methods": [ + { + "name": "fliplr", + "long_name": "fliplr( m )", + "filename": "twodim_base.py", + "nloc": 5, + "complexity": 2, + "token_count": 32, + "parameters": [ + "m" + ], + "start_line": 12, + "end_line": 19, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "flipud", + "long_name": "flipud( m )", + "filename": "twodim_base.py", + "nloc": 5, + "complexity": 2, + "token_count": 32, + "parameters": [ + "m" + ], + "start_line": 21, + "end_line": 28, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "rot90", + "long_name": "rot90( m , k = 1 )", + "filename": "twodim_base.py", + "nloc": 9, + "complexity": 5, + "token_count": 77, + "parameters": [ + "m", + "k" + ], + "start_line": 30, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "eye", + "long_name": "eye( N , M = None , k = 0 , dtype = int_ )", + "filename": "twodim_base.py", + "nloc": 4, + "complexity": 2, + "token_count": 55, + "parameters": [ + "N", + "M", + "k", + "dtype" + ], + "start_line": 44, + "end_line": 50, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "diag", + "long_name": "diag( v , k = 0 )", + "filename": "twodim_base.py", + "nloc": 27, + "complexity": 5, + "token_count": 202, + "parameters": [ + "v", + "k" + ], + "start_line": 52, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "tri", + "long_name": "tri( N , M = None , k = 0 , dtype = int_ )", + "filename": "twodim_base.py", + "nloc": 4, + "complexity": 2, + "token_count": 55, + "parameters": [ + "N", + "M", + "k", + "dtype" + ], + "start_line": 84, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "tril", + "long_name": "tril( m , k = 0 )", + "filename": "twodim_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 51, + "parameters": [ + "m", + "k" + ], + "start_line": 92, + "end_line": 98, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "triu", + "long_name": "triu( m , k = 0 )", + "filename": "twodim_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 53, + "parameters": [ + "m", + "k" + ], + "start_line": 100, + "end_line": 106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "vander", + "long_name": "vander( x , N = None )", + "filename": "twodim_base.py", + "nloc": 7, + "complexity": 3, + "token_count": 72, + "parameters": [ + "x", + "N" + ], + "start_line": 109, + "end_line": 123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "fliplr", + "long_name": "fliplr( m )", + "filename": "twodim_base.py", + "nloc": 5, + "complexity": 2, + "token_count": 32, + "parameters": [ + "m" + ], + "start_line": 11, + "end_line": 18, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "flipud", + "long_name": "flipud( m )", + "filename": "twodim_base.py", + "nloc": 5, + "complexity": 2, + "token_count": 32, + "parameters": [ + "m" + ], + "start_line": 20, + "end_line": 27, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "rot90", + "long_name": "rot90( m , k = 1 )", + "filename": "twodim_base.py", + "nloc": 9, + "complexity": 5, + "token_count": 77, + "parameters": [ + "m", + "k" + ], + "start_line": 29, + "end_line": 41, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "eye", + "long_name": "eye( N , M = None , k = 0 , dtype = int_ )", + "filename": "twodim_base.py", + "nloc": 4, + "complexity": 2, + "token_count": 55, + "parameters": [ + "N", + "M", + "k", + "dtype" + ], + "start_line": 43, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "diag", + "long_name": "diag( v , k = 0 )", + "filename": "twodim_base.py", + "nloc": 27, + "complexity": 5, + "token_count": 202, + "parameters": [ + "v", + "k" + ], + "start_line": 51, + "end_line": 80, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "tri", + "long_name": "tri( N , M = None , k = 0 , dtype = int_ )", + "filename": "twodim_base.py", + "nloc": 4, + "complexity": 2, + "token_count": 55, + "parameters": [ + "N", + "M", + "k", + "dtype" + ], + "start_line": 83, + "end_line": 89, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "tril", + "long_name": "tril( m , k = 0 )", + "filename": "twodim_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 51, + "parameters": [ + "m", + "k" + ], + "start_line": 91, + "end_line": 97, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "triu", + "long_name": "triu( m , k = 0 )", + "filename": "twodim_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 53, + "parameters": [ + "m", + "k" + ], + "start_line": 99, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "vander", + "long_name": "vander( x , N = None )", + "filename": "twodim_base.py", + "nloc": 7, + "complexity": 3, + "token_count": 72, + "parameters": [ + "x", + "N" + ], + "start_line": 108, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 77, + "complexity": 23, + "token_count": 691, + "diff_parsed": { + "added": [ + "from numpy.core.numeric import asanyarray, int_, equal, subtract, arange, \\", + " zeros, arange, greater_equal, multiply, ones, asarray" + ], + "deleted": [ + "from numpy.core.numeric import *" + ] + } + } + ] + }, + { + "hash": "4506c519cd88710615cb83810b7ddc96773985a4", + "msg": "Expose arrayscalar structure to make scalarmath and other extensions easier to write. Move bool scalar C-API to arrayscalars.h", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-16T16:16:18+00:00", + "author_timezone": 0, + "committer_date": "2006-03-16T16:16:18+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "8c9cf9ac2a07e9ebb8dae51a264f708229770624" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 61, + "insertions": 313, + "lines": 374, + "files": 6, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/code_generators/generate_array_api.py", + "new_path": "numpy/core/code_generators/generate_array_api.py", + "filename": "generate_array_api.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -4,7 +4,7 @@\n types = ['Generic','Number','Integer','SignedInteger','UnsignedInteger',\n 'Inexact',\n 'Floating', 'ComplexFloating', 'Flexible', 'Character',\n- 'Bool','Byte','Short','Int', 'Long', 'LongLong', 'UByte', 'UShort',\n+ 'Byte','Short','Int', 'Long', 'LongLong', 'UByte', 'UShort',\n 'UInt', 'ULong', 'ULongLong', 'Float', 'Double', 'LongDouble',\n 'CFloat', 'CDouble', 'CLongDouble', 'Object', 'String', 'Unicode',\n 'Void']\n@@ -12,6 +12,11 @@\n h_template = r\"\"\"\n #ifdef _MULTIARRAYMODULE\n \n+typedef struct {\n+\tPyObject_HEAD\n+\tBool obval;\n+} PyBoolScalarObject;\n+\n static PyTypeObject PyBigArray_Type;\n static PyTypeObject PyArray_Type;\n static PyTypeObject PyArrayDescr_Type;\n@@ -20,6 +25,8 @@\n static PyTypeObject PyArrayMapIter_Type;\n static PyTypeObject PyArrayMultiIter_Type;\n static int PyArray_NUMUSERTYPES=0;\n+static PyTypeObject PyBoolArrType_Type;\n+static PyBoolScalarObject _PyArrayScalar_BoolValues[2];\n \n %s\n \n@@ -46,6 +53,8 @@\n #define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[4])\n #define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[5])\n #define PyArray_NUMUSERTYPES (*(int *)PyArray_API[6])\n+#define PyBoolArrType_Type (*(PyTypeObject *)PyArray_API[7])\n+#define _PyArrayScalar_BoolValues (*(PyObject **)PyArray_API[8])\n \n %s\n \n@@ -92,6 +101,8 @@\n (void *) &PyArrayIter_Type,\n (void *) &PyArrayMultiIter_Type,\n (int *) &PyArray_NUMUSERTYPES,\n+ (void *) &PyBoolArrType_Type,\n+ (void *) &_PyArrayScalar_BoolValues,\n %s\n };\n \"\"\"\n@@ -103,7 +114,7 @@ def generate_api(output_dir):\n 'multiarray_api_order.txt')\n # API fixes for __arrayobject_api.h\n \n- fixed = 7\n+ fixed = 9\n numtypes = len(types) + fixed\n numobject = len(objectapi_list) + numtypes\n nummulti = len(multiapi_list)\n", + "added_lines": 13, + "deleted_lines": 2, + "source_code": "import os\nimport genapi\n\ntypes = ['Generic','Number','Integer','SignedInteger','UnsignedInteger',\n 'Inexact',\n 'Floating', 'ComplexFloating', 'Flexible', 'Character',\n 'Byte','Short','Int', 'Long', 'LongLong', 'UByte', 'UShort',\n 'UInt', 'ULong', 'ULongLong', 'Float', 'Double', 'LongDouble',\n 'CFloat', 'CDouble', 'CLongDouble', 'Object', 'String', 'Unicode',\n 'Void']\n\nh_template = r\"\"\"\n#ifdef _MULTIARRAYMODULE\n\ntypedef struct {\n\tPyObject_HEAD\n\tBool obval;\n} PyBoolScalarObject;\n\nstatic PyTypeObject PyBigArray_Type;\nstatic PyTypeObject PyArray_Type;\nstatic PyTypeObject PyArrayDescr_Type;\nstatic PyTypeObject PyArrayFlags_Type;\nstatic PyTypeObject PyArrayIter_Type;\nstatic PyTypeObject PyArrayMapIter_Type;\nstatic PyTypeObject PyArrayMultiIter_Type;\nstatic int PyArray_NUMUSERTYPES=0;\nstatic PyTypeObject PyBoolArrType_Type;\nstatic PyBoolScalarObject _PyArrayScalar_BoolValues[2];\n\n%s\n\n#else\n\n#if defined(PY_ARRAY_UNIQUE_SYMBOL)\n#define PyArray_API PY_ARRAY_UNIQUE_SYMBOL\n#endif\n\n#if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)\nextern void **PyArray_API;\n#else\n#if defined(PY_ARRAY_UNIQUE_SYMBOL)\nvoid **PyArray_API;\n#else\nstatic void **PyArray_API=NULL;\n#endif\n#endif\n\n#define PyBigArray_Type (*(PyTypeObject *)PyArray_API[0])\n#define PyArray_Type (*(PyTypeObject *)PyArray_API[1])\n#define PyArrayDescr_Type (*(PyTypeObject *)PyArray_API[2])\n#define PyArrayFlags_Type (*(PyTypeObject *)PyArray_API[3])\n#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[4])\n#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[5])\n#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[6])\n#define PyBoolArrType_Type (*(PyTypeObject *)PyArray_API[7])\n#define _PyArrayScalar_BoolValues (*(PyObject **)PyArray_API[8])\n\n%s\n\n#if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)\nstatic int\nimport_array(void)\n{\n PyObject *numpy = PyImport_ImportModule(\"numpy.core.multiarray\");\n PyObject *c_api = NULL;\n if (numpy == NULL) return -1;\n c_api = PyObject_GetAttrString(numpy, \"_ARRAY_API\");\n if (c_api == NULL) {Py_DECREF(numpy); return -1;}\n if (PyCObject_Check(c_api)) {\n PyArray_API = (void **)PyCObject_AsVoidPtr(c_api);\n }\n Py_DECREF(c_api);\n Py_DECREF(numpy);\n if (PyArray_API == NULL) return -1;\n /* Perform runtime check of C API version */\n if (NDARRAY_VERSION != PyArray_GetNDArrayCVersion()) {\n PyErr_Format(PyExc_RuntimeError, \"module compiled against \"\\\n \"version %%x of C-API but this version of numpy is %%x\", \\\n (int) NDARRAY_VERSION, (int) PyArray_GetNDArrayCVersion());\n return -1;\n }\n return 0;\n}\n#endif\n\n#endif\n\"\"\"\n\n\nc_template = r\"\"\"\n/* These pointers will be stored in the C-object for use in other\n extension modules\n*/\n\nvoid *PyArray_API[] = {\n (void *) &PyBigArray_Type,\n (void *) &PyArray_Type,\n (void *) &PyArrayDescr_Type,\n (void *) &PyArrayFlags_Type,\n (void *) &PyArrayIter_Type,\n (void *) &PyArrayMultiIter_Type,\n (int *) &PyArray_NUMUSERTYPES,\n (void *) &PyBoolArrType_Type,\n (void *) &_PyArrayScalar_BoolValues,\n%s\n};\n\"\"\"\n\ndef generate_api(output_dir):\n objectapi_list = genapi.get_api_functions('OBJECT_API',\n 'array_api_order.txt')\n multiapi_list = genapi.get_api_functions('MULTIARRAY_API',\n 'multiarray_api_order.txt')\n # API fixes for __arrayobject_api.h\n\n fixed = 9\n numtypes = len(types) + fixed\n numobject = len(objectapi_list) + numtypes\n nummulti = len(multiapi_list)\n numtotal = numobject + nummulti\n\n module_list = []\n extension_list = []\n init_list = []\n\n # setup types\n for k, atype in enumerate(types):\n num = fixed + k\n astr = \" (void *) &Py%sArrType_Type,\" % types[k]\n init_list.append(astr)\n astr = \"static PyTypeObject Py%sArrType_Type;\" % types[k]\n module_list.append(astr)\n astr = \"#define Py%sArrType_Type (*(PyTypeObject *)PyArray_API[%d])\" % \\\n (types[k], num)\n extension_list.append(astr)\n\n #setup object API\n genapi.add_api_list(numtypes, 'PyArray_API', objectapi_list,\n module_list, extension_list, init_list)\n\n # setup multiarray module API\n genapi.add_api_list(numobject, 'PyArray_API', multiapi_list,\n module_list, extension_list, init_list)\n\n\n # Write to header\n fid = open(os.path.join(output_dir, '__multiarray_api.h'),'w')\n s = h_template % ('\\n'.join(module_list), '\\n'.join(extension_list))\n fid.write(s)\n fid.close()\n\n # Write to c-code\n fid = open(os.path.join(output_dir,'__multiarray_api.c'),'w')\n s = c_template % '\\n'.join(init_list)\n fid.write(s)\n fid.close()\n", + "source_code_before": "import os\nimport genapi\n\ntypes = ['Generic','Number','Integer','SignedInteger','UnsignedInteger',\n 'Inexact',\n 'Floating', 'ComplexFloating', 'Flexible', 'Character',\n '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\nh_template = r\"\"\"\n#ifdef _MULTIARRAYMODULE\n\nstatic PyTypeObject PyBigArray_Type;\nstatic PyTypeObject PyArray_Type;\nstatic PyTypeObject PyArrayDescr_Type;\nstatic PyTypeObject PyArrayFlags_Type;\nstatic PyTypeObject PyArrayIter_Type;\nstatic PyTypeObject PyArrayMapIter_Type;\nstatic PyTypeObject PyArrayMultiIter_Type;\nstatic int PyArray_NUMUSERTYPES=0;\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 PyArrayDescr_Type (*(PyTypeObject *)PyArray_API[2])\n#define PyArrayFlags_Type (*(PyTypeObject *)PyArray_API[3])\n#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[4])\n#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[5])\n#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[6])\n\n%s\n\n#if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)\nstatic int\nimport_array(void)\n{\n PyObject *numpy = PyImport_ImportModule(\"numpy.core.multiarray\");\n PyObject *c_api = NULL;\n if (numpy == NULL) return -1;\n c_api = PyObject_GetAttrString(numpy, \"_ARRAY_API\");\n if (c_api == NULL) {Py_DECREF(numpy); return -1;}\n if (PyCObject_Check(c_api)) {\n PyArray_API = (void **)PyCObject_AsVoidPtr(c_api);\n }\n Py_DECREF(c_api);\n Py_DECREF(numpy);\n if (PyArray_API == NULL) return -1;\n /* Perform runtime check of C API version */\n if (NDARRAY_VERSION != PyArray_GetNDArrayCVersion()) {\n PyErr_Format(PyExc_RuntimeError, \"module compiled against \"\\\n \"version %%x of C-API but this version of numpy is %%x\", \\\n (int) NDARRAY_VERSION, (int) PyArray_GetNDArrayCVersion());\n return -1;\n }\n return 0;\n}\n#endif\n\n#endif\n\"\"\"\n\n\nc_template = r\"\"\"\n/* These pointers will be stored in the C-object for use in other\n extension modules\n*/\n\nvoid *PyArray_API[] = {\n (void *) &PyBigArray_Type,\n (void *) &PyArray_Type,\n (void *) &PyArrayDescr_Type,\n (void *) &PyArrayFlags_Type,\n (void *) &PyArrayIter_Type,\n (void *) &PyArrayMultiIter_Type,\n (int *) &PyArray_NUMUSERTYPES,\n%s\n};\n\"\"\"\n\ndef generate_api(output_dir):\n objectapi_list = genapi.get_api_functions('OBJECT_API',\n 'array_api_order.txt')\n multiapi_list = genapi.get_api_functions('MULTIARRAY_API',\n 'multiarray_api_order.txt')\n # API fixes for __arrayobject_api.h\n\n fixed = 7\n numtypes = len(types) + fixed\n numobject = len(objectapi_list) + numtypes\n nummulti = len(multiapi_list)\n numtotal = numobject + nummulti\n\n module_list = []\n extension_list = []\n init_list = []\n\n # setup types\n for k, atype in enumerate(types):\n num = fixed + k\n astr = \" (void *) &Py%sArrType_Type,\" % types[k]\n init_list.append(astr)\n astr = \"static PyTypeObject Py%sArrType_Type;\" % types[k]\n module_list.append(astr)\n astr = \"#define Py%sArrType_Type (*(PyTypeObject *)PyArray_API[%d])\" % \\\n (types[k], num)\n extension_list.append(astr)\n\n #setup object API\n genapi.add_api_list(numtypes, 'PyArray_API', objectapi_list,\n module_list, extension_list, init_list)\n\n # setup multiarray module API\n genapi.add_api_list(numobject, 'PyArray_API', multiapi_list,\n module_list, extension_list, init_list)\n\n\n # Write to header\n fid = open(os.path.join(output_dir, '__multiarray_api.h'),'w')\n s = h_template % ('\\n'.join(module_list), '\\n'.join(extension_list))\n fid.write(s)\n fid.close()\n\n # Write to c-code\n fid = open(os.path.join(output_dir,'__multiarray_api.c'),'w')\n s = c_template % '\\n'.join(init_list)\n fid.write(s)\n fid.close()\n", + "methods": [ + { + "name": "generate_api", + "long_name": "generate_api( output_dir )", + "filename": "generate_array_api.py", + "nloc": 34, + "complexity": 2, + "token_count": 246, + "parameters": [ + "output_dir" + ], + "start_line": 110, + "end_line": 157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "generate_api", + "long_name": "generate_api( output_dir )", + "filename": "generate_array_api.py", + "nloc": 34, + "complexity": 2, + "token_count": 246, + "parameters": [ + "output_dir" + ], + "start_line": 99, + "end_line": 146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "generate_api", + "long_name": "generate_api( output_dir )", + "filename": "generate_array_api.py", + "nloc": 34, + "complexity": 2, + "token_count": 246, + "parameters": [ + "output_dir" + ], + "start_line": 110, + "end_line": 157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + } + ], + "nloc": 138, + "complexity": 2, + "token_count": 322, + "diff_parsed": { + "added": [ + " 'Byte','Short','Int', 'Long', 'LongLong', 'UByte', 'UShort',", + "typedef struct {", + "\tPyObject_HEAD", + "\tBool obval;", + "} PyBoolScalarObject;", + "", + "static PyTypeObject PyBoolArrType_Type;", + "static PyBoolScalarObject _PyArrayScalar_BoolValues[2];", + "#define PyBoolArrType_Type (*(PyTypeObject *)PyArray_API[7])", + "#define _PyArrayScalar_BoolValues (*(PyObject **)PyArray_API[8])", + " (void *) &PyBoolArrType_Type,", + " (void *) &_PyArrayScalar_BoolValues,", + " fixed = 9" + ], + "deleted": [ + " 'Bool','Byte','Short','Int', 'Long', 'LongLong', 'UByte', 'UShort',", + " fixed = 7" + ] + } + }, + { + "old_path": "numpy/core/include/numpy/arrayobject.h", + "new_path": "numpy/core/include/numpy/arrayobject.h", + "filename": "arrayobject.h", + "extension": "h", + "change_type": "MODIFY", + "diff": "@@ -79,7 +79,7 @@ extern \"C\" CONFUSE_EMACS\n #define PY_SUCCEED 1\n \n /* Helpful to distinguish what is installed */\n-#define NDARRAY_VERSION 0x00090701\n+#define NDARRAY_VERSION 0x00090702\n \n \t/* Some platforms don't define bool, long long, or long double.\n \t Handle that here.\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "\n/* This expects the following variables to be defined (besides\n the usual ones from pyconfig.h\n\n SIZEOF_LONG_DOUBLE -- sizeof(long double) or sizeof(double) if no\n long double is present on platform.\n CHAR_BIT -- number of bits in a char (usually 8)\n (should be in limits.h)\n*/\n\n#ifndef Py_ARRAYOBJECT_H\n#define Py_ARRAYOBJECT_H\n#ifdef __cplusplus\n#define CONFUSE_EMACS {\n#define CONFUSE_EMACS2 }\nextern \"C\" CONFUSE_EMACS\n#undef CONFUSE_EMACS\n#undef CONFUSE_EMACS2\n/* ... otherwise a semi-smart idententer (like emacs) tries to indent\n everything when you're typing */\n#endif\n#include \"config.h\"\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# define CAT2(x,y) x ## y\n# define CAT(x,y) CAT2(x,y)\n# define NS(name) CAT(PY_ARRAY_TYPES_PREFIX, name)\n# define longlong NS(longlong)\n# define ulonglong NS(ulonglong)\n# define Bool NS(Bool)\n# define longdouble NS(longdouble)\n# define byte NS(byte)\n# define ubyte NS(ubyte)\n# define ushort NS(ushort)\n# define uint NS(uint)\n# define ulong NS(ulong)\n# define cfloat NS(cfloat)\n# define cdouble NS(cdouble)\n# define clongdouble NS(clongdouble)\n# define Int8 NS(Int8)\n# define UInt8 NS(UInt8)\n# define Int16 NS(Int16)\n# define UInt16 NS(UInt16)\n# define Int32 NS(Int32)\n# define UInt32 NS(UInt32)\n# define Int64 NS(Int64)\n# define UInt64 NS(UInt64)\n# define Int128 NS(Int128)\n# define UInt128 NS(UInt128)\n# define Int256 NS(Int256)\n# define UInt256 NS(UInt256)\n# define Float16 NS(Float16)\n# define Complex32 NS(Complex32)\n# define Float32 NS(Float32)\n# define Complex64 NS(Complex64)\n# define Float64 NS(Float64)\n# define Complex128 NS(Complex128)\n# define Float80 NS(Float80)\n# define Complex160 NS(Complex160)\n# define Float96 NS(Float96)\n# define Complex192 NS(Complex192)\n# define Float128 NS(Float128)\n# define Complex256 NS(Complex256)\n# define intp NS(intp)\n# define uintp NS(uintp)\n#endif\n\n/* There are several places in the code where an array of dimensions is */\n/* allocated statically. This is the size of that static allocation. */\n/* The array creation itself could have arbitrary dimensions but\n * all the places where static allocation is used would need to\n * be changed to dynamic (including inside of structures)\n */\n\n#define MAX_DIMS 32\n\n/* Used for Converter Functions \"O&\" code in ParseTuple */\n#define PY_FAIL 0\n#define PY_SUCCEED 1\n\n /* Helpful to distinguish what is installed */\n#define NDARRAY_VERSION 0x00090702\n\n\t/* Some platforms don't define bool, long long, or long double.\n\t Handle that here.\n\t */\n\n#ifdef PY_LONG_LONG\ntypedef PY_LONG_LONG longlong;\ntypedef unsigned PY_LONG_LONG ulonglong;\n# ifdef _MSC_VER\n# define LONGLONG_FMT \"I64d\"\n# define ULONGLONG_FMT \"I64u\"\n# define LONGLONG_SUFFIX(x) (x##i64)\n# define ULONGLONG_SUFFIX(x) (x##Ui64)\n# else\n\t/* #define LONGLONG_FMT \"lld\" Another possible variant\n #define ULONGLONG_FMT \"llu\"\n\n\t #define LONGLONG_FMT \"qd\" -- BSD perhaps?\n\t #define ULONGLONG_FMT \"qu\"\n\t*/\n# define LONGLONG_FMT \"Ld\"\n# define ULONGLONG_FMT \"Lu\"\n# define LONGLONG_SUFFIX(x) (x##LL)\n# define ULONGLONG_SUFFIX(x) (x##ULL)\n# endif\n#else\ntypedef long longlong;\ntypedef unsigned long ulonglong;\n# define LONGLONG_SUFFIX(x) (x##L)\n# define ULONGLONG_SUFFIX(x) (x##UL)\n#endif\n\ntypedef unsigned char Bool;\n#ifndef FALSE\n#define FALSE 0\n#endif\n#ifndef TRUE\n#define TRUE 1\n#endif\n\n#if SIZEOF_LONG_DOUBLE==SIZEOF_DOUBLE\n\ttypedef double longdouble;\n #define LONGDOUBLE_FMT \"g\"\n#else\n\ttypedef long double longdouble;\n #define LONGDOUBLE_FMT \"Lg\"\n#endif\n\n#ifndef Py_USING_UNICODE\n#error Must use Python with unicode enabled. \n#endif\n\n\ntypedef signed char byte;\ntypedef unsigned char ubyte;\n#ifndef _BSD_SOURCE\ntypedef unsigned short ushort;\ntypedef unsigned int uint;\ntypedef unsigned long ulong;\n#endif\n\ntypedef struct { float real, imag; } cfloat;\ntypedef struct { double real, imag; } cdouble;\ntypedef struct {longdouble real, imag;} clongdouble;\n\nenum PyArray_TYPES { PyArray_BOOL=0,\n PyArray_BYTE, PyArray_UBYTE,\n\t\t PyArray_SHORT, PyArray_USHORT,\n\t\t PyArray_INT, PyArray_UINT,\n\t\t\tPyArray_LONG, PyArray_ULONG,\n PyArray_LONGLONG, PyArray_ULONGLONG,\n\t\t\tPyArray_FLOAT, PyArray_DOUBLE, PyArray_LONGDOUBLE,\n\t\t\tPyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CLONGDOUBLE,\n\t\t\tPyArray_OBJECT=17,\n PyArray_STRING, PyArray_UNICODE,\n\t\t\tPyArray_VOID,\n\t\t\tPyArray_NTYPES,\n\t\t\tPyArray_NOTYPE,\n\t\t\tPyArray_USERDEF=256 /* leave room for characters */\n};\n\n\t/* basetype array priority */\n#define PyArray_PRIORITY 0.0\n#define PyArray_BIG_PRIORITY 0.1\n\t/* default subtype priority */\n#define PyArray_SUBTYPE_PRIORITY 1.0\n\n\t/* How many floating point types are there */\n#define PyArray_NUM_FLOATTYPE 3\n\n\n\t/* We need to match intp to a signed integer of the same size as\n\t a pointer variable. uintp to the equivalent unsigned integer\n\t*/\n\n\n\t/* These characters correspond to the array type and the\n\t struct module */\n\n\t/* except 'p' -- signed integer for pointer type */\n\nenum PyArray_TYPECHAR { PyArray_BOOLLTR = '?',\n\t\t\tPyArray_BYTELTR = 'b',\n\t\t\tPyArray_UBYTELTR = 'B',\n\t\t\tPyArray_SHORTLTR = 'h',\n\t\t\tPyArray_USHORTLTR = 'H',\n\t\t\tPyArray_INTLTR = 'i',\n\t\t\tPyArray_UINTLTR = 'I',\n\t\t\tPyArray_LONGLTR = 'l',\n\t\t\tPyArray_ULONGLTR = 'L',\n\t\t\tPyArray_LONGLONGLTR = 'q',\n\t\t\tPyArray_ULONGLONGLTR = 'Q',\n\t\t\tPyArray_FLOATLTR = 'f',\n\t\t\tPyArray_DOUBLELTR = 'd',\n\t\t\tPyArray_LONGDOUBLELTR = 'g',\n\t\t\tPyArray_CFLOATLTR = 'F',\n\t\t\tPyArray_CDOUBLELTR = 'D',\n\t\t\tPyArray_CLONGDOUBLELTR = 'G',\n\t\t\tPyArray_OBJECTLTR = 'O',\n\t\t\tPyArray_STRINGLTR = 'S',\n\t\t\tPyArray_STRINGLTR2 = 'a',\n\t\t\tPyArray_UNICODELTR = 'U',\n\t\t PyArray_VOIDLTR = 'V',\n\n\t\t\t/* No Descriptor, just a define -- this let's\n\t\t\t Python users specify an array of integers\n\t\t\t large enough to hold a pointer on the platform*/\n\t\t\tPyArray_INTPLTR = 'p',\n\t\t\tPyArray_UINTPLTR = 'P',\n\n\t\t\tPyArray_GENBOOLLTR ='b',\n\t\t\tPyArray_SIGNEDLTR = 'i',\n\t\t\tPyArray_UNSIGNEDLTR = 'u',\n\t\t\tPyArray_FLOATINGLTR = 'f',\n\t\t\tPyArray_COMPLEXLTR = 'c'\n};\n\ntypedef enum {\n\tPyArray_QUICKSORT=0,\n\tPyArray_HEAPSORT=1,\n\tPyArray_MERGESORT=2,\n\tPyArray_TIMSORT=3 /* the sort Python uses -- specialized */\n} PyArray_SORTKIND;\n#define PyArray_NSORTS PyArray_TIMSORT + 1\n\n\ntypedef enum {\n\tPyArray_NOSCALAR=0,\n\tPyArray_BOOL_SCALAR=1,\n\tPyArray_INTPOS_SCALAR=2,\n\tPyArray_INTNEG_SCALAR=3,\n\tPyArray_FLOAT_SCALAR=4,\n\tPyArray_COMPLEX_SCALAR=5,\n\tPyArray_OBJECT_SCALAR=6,\n} PyArray_SCALARKIND;\n\n\t/* Define bit-width array types and typedefs */\n\n#define MAX_INT8 127\n#define MIN_INT8 -128\n#define MAX_UINT8 255\n#define MAX_INT16 32767\n#define MIN_INT16 -32768\n#define MAX_UINT16 65535\n#define MAX_INT32 2147483647\n#define MIN_INT32 (-MAX_INT32 - 1)\n#define MAX_UINT32 4294967295U\n#define MAX_INT64 LONGLONG_SUFFIX(9223372036854775807)\n#define MIN_INT64 (-MAX_INT64 - LONGLONG_SUFFIX(1))\n#define MAX_UINT64 ULONGLONG_SUFFIX(18446744073709551615)\n#define MAX_INT128 LONGLONG_SUFFIX(85070591730234615865843651857942052864)\n#define MIN_INT128 (-MAX_INT128 - LONGLONG_SUFFIX(1))\n#define MAX_UINT128 ULONGLONG_SUFFIX(170141183460469231731687303715884105728)\n#define MAX_INT256 LONGLONG_SUFFIX(57896044618658097711785492504343953926634992332820282019728792003956564819967)\n#define MIN_INT256 (-MAX_INT256 - LONGLONG_SUFFIX(1))\n#define MAX_UINT256 ULONGLONG_SUFFIX(115792089237316195423570985008687907853269984665640564039457584007913129639935)\n\n\t/* Need to find the number of bits for each type and\n\t make definitions accordingly.\n\n\t C states that sizeof(char) == 1 by definition\n\n\t So, just using the sizeof keyword won't help.\n\n\t It also looks like Python itself uses sizeof(char) quite a\n\t bit, which by definition should be 1 all the time.\n\n\t Idea: Make Use of CHAR_BIT which should tell us how many\n\t BITS per CHARACTER\n\t*/\n\n\t/* Include platform definitions -- These are in the C89/90 standard */\n#include \n#define MAX_BYTE SCHAR_MAX\n#define MIN_BYTE SCHAR_MIN\n#define MAX_UBYTE UCHAR_MAX\n#define MAX_SHORT SHRT_MAX\n#define MIN_SHORT SHRT_MIN\n#define MAX_USHORT USHRT_MAX\n#define MAX_INT INT_MAX\n#ifndef INT_MIN\n#define INT_MIN (-INT_MAX - 1)\n#endif\n#define MIN_INT INT_MIN\n#define MAX_UINT UINT_MAX\n#define MAX_LONG LONG_MAX\n#define MIN_LONG LONG_MIN\n#define MAX_ULONG ULONG_MAX\n\n#define SIZEOF_LONGDOUBLE SIZEOF_LONG_DOUBLE\n#define SIZEOF_LONGLONG SIZEOF_LONG_LONG\n#define BITSOF_BOOL sizeof(Bool)*CHAR_BIT\n#define BITSOF_CHAR CHAR_BIT\n#define BITSOF_SHORT (SIZEOF_SHORT*CHAR_BIT)\n#define BITSOF_INT (SIZEOF_INT*CHAR_BIT)\n#define BITSOF_LONG (SIZEOF_LONG*CHAR_BIT)\n#define BITSOF_LONGLONG (SIZEOF_LONGLONG*CHAR_BIT)\n#define BITSOF_FLOAT (SIZEOF_FLOAT*CHAR_BIT)\n#define BITSOF_DOUBLE (SIZEOF_DOUBLE*CHAR_BIT)\n#define BITSOF_LONGDOUBLE (SIZEOF_LONGDOUBLE*CHAR_BIT)\n\n\n#if BITSOF_LONG == 8\n#define PyArray_INT8 PyArray_LONG\n#define PyArray_UINT8 PyArray_ULONG\n\ttypedef long Int8;\n\ttypedef unsigned long UInt8;\n#define STRBITSOF_LONG \"8\"\n#elif BITSOF_LONG == 16\n#define PyArray_INT16 PyArray_LONG\n#define PyArray_UINT16 PyArray_ULONG\n\ttypedef long Int16;\n\ttypedef unsigned long UInt16;\n#define STRBITSOF_LONG \"16\"\n#elif BITSOF_LONG == 32\n#define PyArray_INT32 PyArray_LONG\n#define PyArray_UINT32 PyArray_ULONG\n\ttypedef long Int32;\n\ttypedef unsigned long UInt32;\n\ttypedef unsigned long PyArray_UCS4;\n#define STRBITSOF_LONG \"32\"\n#elif BITSOF_LONG == 64\n#define PyArray_INT64 PyArray_LONG\n#define PyArray_UINT64 PyArray_ULONG\n\ttypedef long Int64;\n\ttypedef unsigned long UInt64;\n#define STRBITSOF_LONG \"64\"\n#elif BITSOF_LONG == 128\n#define PyArray_INT128 PyArray_LONG\n#define PyArray_UINT128 PyArray_ULONG\n\ttypedef long Int128;\n\ttypedef unsigned long UInt128;\n#define STRBITSOF_LONG \"128\"\n#endif\n\n#if BITSOF_LONGLONG == 8\n# ifndef PyArray_INT8\n# define PyArray_INT8 PyArray_LONGLONG\n# define PyArray_UINT8 PyArray_ULONGLONG\n\ttypedef longlong Int8;\n\ttypedef ulonglong UInt8;\n# endif\n# define MAX_LONGLONG MAX_INT8\n# define MIN_LONGLONG MIN_INT8\n# define MAX_ULONGLONG MAX_UINT8\n#define STRBITSOF_LONGLONG \"8\"\n#elif BITSOF_LONGLONG == 16\n# ifndef PyArray_INT16\n# define PyArray_INT16 PyArray_LONGLONG\n# define PyArray_UINT16 PyArray_ULONGLONG\n\ttypedef longlong Int16;\n\ttypedef ulonglong UInt16;\n# endif\n# define MAX_LONGLONG MAX_INT16\n# define MIN_LONGLONG MIN_INT16\n# define MAX_ULONGLONG MAX_UINT16\n#define STRBITSOF_LONGLONG \"16\"\n#elif BITSOF_LONGLONG == 32\n# ifndef PyArray_INT32\n# define PyArray_INT32 PyArray_LONGLONG\n# define PyArray_UINT32 PyArray_ULONGLONG\n\ttypedef longlong Int32;\n\ttypedef ulonglong UInt32;\n\ttypedef ulonglong PyArray_UCS4;\n# endif\n# define MAX_LONGLONG MAX_INT32\n# define MIN_LONGLONG MIN_INT32\n# define MAX_ULONGLONG MAX_UINT32\n#define STRBITSOF_LONGLONG \"32\"\n#elif BITSOF_LONGLONG == 64\n# ifndef PyArray_INT64\n# define PyArray_INT64 PyArray_LONGLONG\n# define PyArray_UINT64 PyArray_ULONGLONG\n\ttypedef longlong Int64;\n\ttypedef ulonglong UInt64;\n# endif\n# define MAX_LONGLONG MAX_INT64\n# define MIN_LONGLONG MIN_INT64\n# define MAX_ULONGLONG MAX_UINT64\n#define STRBITSOF_LONGLONG \"64\"\n#elif BITSOF_LONGLONG == 128\n# ifndef PyArray_INT128\n# define PyArray_INT128 PyArray_LONGLONG\n# define PyArray_UINT128 PyArray_ULONGLONG\n\ttypedef longlong Int128;\n\ttypedef ulonglong UInt128;\n# endif\n# define MAX_LONGLONG MAX_INT128\n# define MIN_LONGLONG MIN_INT128\n# define MAX_ULONGLONG MAX_UINT128\n#define STRBITSOF_LONGLONG \"128\"\n#elif BITSOF_LONGLONG == 256\n# define PyArray_INT256 PyArray_LONGLONG\n# define PyArray_UINT256 PyArray_ULONGLONG\n\ttypedef longlong Int256;\n\ttypedef ulonglong UInt256;\n# define MAX_LONGLONG MAX_INT256\n# define MIN_LONGLONG MIN_INT256\n# define MAX_ULONGLONG MAX_UINT256\n#define STRBITSOF_LONGLONG \"256\"\n#endif\n\n#if BITSOF_INT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_INT\n#define PyArray_UINT8 PyArray_UINT\n\ttypedef int Int8;\n\ttypedef unsigned int UInt8;\n#endif\n#define STRBITSOF_INT \"8\"\n#elif BITSOF_INT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_INT\n#define PyArray_UINT16 PyArray_UINT\n\ttypedef int Int16;\n\ttypedef unsigned int UInt16;\n#endif\n#define STRBITSOF_INT \"16\"\n#elif BITSOF_INT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_INT\n#define PyArray_UINT32 PyArray_UINT\n\ttypedef int Int32;\n\ttypedef unsigned int UInt32;\n\ttypedef unsigned int PyArray_UCS4;\n#endif\n#define STRBITSOF_INT \"32\"\n#elif BITSOF_INT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_INT\n#define PyArray_UINT64 PyArray_UINT\n\ttypedef int Int64;\n\ttypedef unsigned int UInt64;\n#endif\n#define STRBITSOF_INT \"64\"\n#elif BITSOF_INT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_INT\n#define PyArray_UINT128 PyArray_UINT\n\ttypedef int Int128;\n\ttypedef unsigned int UInt128;\n#endif\n#define STRBITSOF_INT \"128\"\n#endif\n\n#if BITSOF_SHORT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_SHORT\n#define PyArray_UINT8 PyArray_USHORT\n\ttypedef short Int8;\n\ttypedef unsigned short UInt8;\n#endif\n#define STRBITSOF_SHORT \"8\"\n#elif BITSOF_SHORT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_SHORT\n#define PyArray_UINT16 PyArray_USHORT\n\ttypedef short Int16;\n\ttypedef unsigned short UInt16;\n#endif\n#define STRBITSOF_SHORT \"16\"\n#elif BITSOF_SHORT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_SHORT\n#define PyArray_UINT32 PyArray_USHORT\n\ttypedef short Int32;\n\ttypedef unsigned short UInt32;\n\ttypedef unsigned short PyArray_UCS4;\n#endif\n#define STRBITSOF_SHORT \"32\"\n#elif BITSOF_SHORT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_SHORT\n#define PyArray_UINT64 PyArray_USHORT\n\ttypedef short Int64;\n\ttypedef unsigned short UInt64;\n#endif\n#define STRBITSOF_SHORT \"64\"\n#elif BITSOF_SHORT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_SHORT\n#define PyArray_UINT128 PyArray_USHORT\n\ttypedef short Int128;\n\ttypedef unsigned short UInt128;\n#endif\n#define STRBITSOF_SHORT \"128\"\n#endif\n\n\n#if BITSOF_CHAR == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_BYTE\n#define PyArray_UINT8 PyArray_UBYTE\n\ttypedef signed char Int8;\n\ttypedef unsigned char UInt8;\n#endif\n#define STRBITSOF_CHAR \"8\"\n#elif BITSOF_CHAR == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_BYTE\n#define PyArray_UINT16 PyArray_UBYTE\n\ttypedef signed char Int16;\n\ttypedef unsigned char UInt16;\n#endif\n#define STRBITSOF_CHAR \"16\"\n#elif BITSOF_CHAR == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_BYTE\n#define PyArray_UINT32 PyArray_UBYTE\n\ttypedef signed char Int32;\n\ttypedef unsigned char UInt32;\n\ttypedef unsigned char PyArray_UCS4;\n#endif\n#define STRBITSOF_CHAR \"32\"\n#elif BITSOF_CHAR == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_BYTE\n#define PyArray_UINT64 PyArray_UBYTE\n\ttypedef signed char Int64;\n\ttypedef unsigned char UInt64;\n#endif\n#define STRBITSOF_CHAR \"64\"\n#elif BITSOF_CHAR == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_BYTE\n#define PyArray_UINT128 PyArray_UBYTE\n\ttypedef signed char Int128;\n\ttypedef unsigned char UInt128;\n#endif\n#define STRBITSOF_CHAR \"128\"\n#endif\n\n\n\n#if BITSOF_DOUBLE == 16\n#define STRBITSOF_DOUBLE \"16\"\n#define STRBITSOF_CDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_DOUBLE\n#define PyArray_COMPLEX32 PyArray_CDOUBLE\n\ttypedef double Float16;\n\ttypedef cdouble Complex32;\n#endif\n#elif BITSOF_DOUBLE == 32\n#define STRBITSOF_DOUBLE \"32\"\n#define STRBITSOF_CDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_DOUBLE\n#define PyArray_COMPLEX64 PyArray_CDOUBLE\n\ttypedef double Float32;\n\ttypedef cdouble Complex64;\n#endif\n#elif BITSOF_DOUBLE == 64\n#define STRBITSOF_DOUBLE \"64\"\n#define STRBITSOF_CDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_DOUBLE\n#define PyArray_COMPLEX128 PyArray_CDOUBLE\n\ttypedef double Float64;\n\ttypedef cdouble Complex128;\n#endif\n#elif BITSOF_DOUBLE == 80\n#define STRBITSOF_DOUBLE \"80\"\n#define STRBITSOF_CDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_DOUBLE\n#define PyArray_COMPLEX160 PyArray_CDOUBLE\n\ttypedef double Float80;\n\ttypedef cdouble Complex160;\n#endif\n#elif BITSOF_DOUBLE == 96\n#define STRBITSOF_DOUBLE \"96\"\n#define STRBITSOF_CDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_DOUBLE\n#define PyArray_COMPLEX192 PyArray_CDOUBLE\n\ttypedef double Float96;\n\ttypedef cdouble Complex192;\n#endif\n#elif BITSOF_DOUBLE == 128\n#define STRBITSOF_DOUBLE \"128\"\n#define STRBITSOF_CDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_DOUBLE\n#define PyArray_COMPLEX256 PyArray_CDOUBLE\n\ttypedef double Float128;\n\ttypedef cdouble Complex256;\n#endif\n#endif\n\n\n\n#if BITSOF_FLOAT == 16\n#define STRBITSOF_FLOAT \"16\"\n#define STRBITSOF_CFLOAT \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_FLOAT\n#define PyArray_COMPLEX32 PyArray_CFLOAT\n\ttypedef float Float16;\n\ttypedef cfloat Complex32;\n#endif\n#elif BITSOF_FLOAT == 32\n#define STRBITSOF_FLOAT \"32\"\n#define STRBITSOF_CFLOAT \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_FLOAT\n#define PyArray_COMPLEX64 PyArray_CFLOAT\n\ttypedef float Float32;\n\ttypedef cfloat Complex64;\n#endif\n#elif BITSOF_FLOAT == 64\n#define STRBITSOF_FLOAT \"64\"\n#define STRBITSOF_CFLOAT \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_FLOAT\n#define PyArray_COMPLEX128 PyArray_CFLOAT\n\ttypedef float Float64;\n\ttypedef cfloat Complex128;\n#endif\n#elif BITSOF_FLOAT == 80\n#define STRBITSOF_FLOAT \"80\"\n#define STRBITSOF_CFLOAT \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_FLOAT\n#define PyArray_COMPLEX160 PyArray_CFLOAT\n\ttypedef float Float80;\n\ttypedef cfloat Complex160;\n#endif\n#elif BITSOF_FLOAT == 96\n#define STRBITSOF_FLOAT \"96\"\n#define STRBITSOF_CFLOAT \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_FLOAT\n#define PyArray_COMPLEX192 PyArray_CFLOAT\n\ttypedef float Float96;\n\ttypedef cfloat Complex192;\n#endif\n#elif BITSOF_FLOAT == 128\n#define STRBITSOF_FLOAT \"128\"\n#define STRBITSOF_CFLOAT \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_FLOAT\n#define PyArray_COMPLEX256 PyArray_CFLOAT\n\ttypedef float Float128;\n\ttypedef cfloat Complex256;\n#endif\n#endif\n\n\n#if BITSOF_LONGDOUBLE == 16\n#define STRBITSOF_LONGDOUBLE \"16\"\n#define STRBITSOF_CLONGDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX32 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float16;\n\ttypedef clongdouble Complex32;\n#endif\n#elif BITSOF_LONGDOUBLE == 32\n#define STRBITSOF_LONGDOUBLE \"32\"\n#define STRBITSOF_CLONGDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX64 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float32;\n\ttypedef clongdouble Complex64;\n#endif\n#elif BITSOF_LONGDOUBLE == 64\n#define STRBITSOF_LONGDOUBLE \"64\"\n#define STRBITSOF_CLONGDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX128 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float64;\n\ttypedef clongdouble Complex128;\n#endif\n#elif BITSOF_LONGDOUBLE == 80\n#define STRBITSOF_LONGDOUBLE \"80\"\n#define STRBITSOF_CLONGDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX160 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float80;\n\ttypedef clongdouble Complex160;\n#endif\n#elif BITSOF_LONGDOUBLE == 96\n#define STRBITSOF_LONGDOUBLE \"96\"\n#define STRBITSOF_CLONGDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX192 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float96;\n\ttypedef clongdouble Complex192;\n#endif\n#elif BITSOF_LONGDOUBLE == 128\n#define STRBITSOF_LONGDOUBLE \"128\"\n#define STRBITSOF_CLONGDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX256 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float128;\n\ttypedef clongdouble Complex256;\n#endif\n#elif BITSOF_LONGDOUBLE == 256\n#define STRBITSOF_LONGDOUBLE \"256\"\n#define STRBITSOF_CLONGDOUBLE \"512\"\n#define PyArray_FLOAT256 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX512 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float256;\n\ttypedef clongdouble Complex512;\n#endif\n\n\t/* End of typedefs for numarray style bit-width names */\n\n/* This is to typedef Intp to the appropriate pointer size for this platform.\n * Py_intptr_t, Py_uintptr_t are defined in pyport.h. */\ntypedef Py_intptr_t intp;\ntypedef Py_uintptr_t uintp;\n#define SIZEOF_INTP SIZEOF_PY_INTPTR_T\n#define SIZEOF_UINTP SIZEOF_PY_INTPTR_T\n\n#if PY_VERSION_HEX >= 0x02050000\n#define _int_or_ssize_t Py_ssize_t\n#else\n#define _int_or_ssize_t int\n#endif\n\n#define INTP_FMT \"d\"\n\n#if SIZEOF_PY_INTPTR_T == SIZEOF_INT\n\t#define PyArray_INTP PyArray_INT\n\t#define PyArray_UINTP PyArray_UINT\n #define PyIntpArrType_Type PyIntArrType_Type\n #define PyUIntpArrType_Type PyUIntArrType_Type\n\t#define MAX_INTP MAX_INT\n\t#define MIN_INTP MIN_INT\n\t#define MAX_UINTP MAX_UINT\n#elif SIZEOF_PY_INTPTR_T == SIZEOF_LONG\n\t#define PyArray_INTP PyArray_LONG\n\t#define PyArray_UINTP PyArray_ULONG\n #define PyIntpArrType_Type PyLongArrType_Type\n #define PyUIntpArrType_Type PyULongArrType_Type\n\t#define MAX_INTP MAX_LONG\n\t#define MIN_INTP MIN_LONG\n\t#define MAX_UINTP MAX_ULONG\n #undef INTP_FMT\n #define INTP_FMT \"ld\"\n#elif defined(PY_LONG_LONG) && (SIZEOF_PY_INTPTR_T == SIZEOF_LONG_LONG)\n\t#define PyArray_INTP PyArray_LONGLONG\n\t#define PyArray_UINTP PyArray_ULONGLONG\n #define PyIntpArrType_Type PyLongLongArrType_Type\n #define PyUIntpArrType_Type PyULongLongArrType_Type\n\t#define MAX_INTP MAX_LONGLONG\n\t#define MIN_INTP MIN_LONGLONG\n\t#define MAX_UINTP MAX_ULONGLONG\n #undef INTP_FMT\n #define INTP_FMT \"Ld\"\n#endif\n\n#define ERR(str) fprintf(stderr, #str); fflush(stderr);\n#define ERR2(str) fprintf(stderr, str); fflush(stderr);\n\n /* Macros to define how array, and dimension/strides data is\n allocated.\n */\n\n /* Data buffer */\n#define PyDataMem_NEW(size) ((char *)malloc(size))\n /* #define PyArrayMem_NEW(size) PyMem_NEW(char, size)*/\n#define PyDataMem_FREE(ptr) free(ptr)\n /* #define PyArrayMem_FREE(ptr) PyMem_Free(ptr) */\n#define PyDataMem_RENEW(ptr,size) ((char *)realloc(ptr,size))\n\n#define PyArray_USE_PYMEM 0\n\n#if PyArray_USE_PYMEM == 1\n#define _pya_malloc PyObject_Malloc\n#define _pya_free PyObject_Free\n#define _pya_realloc PyObject_Realloc\n#else\n#define _pya_malloc malloc\n#define _pya_free free\n#define _pya_realloc realloc\n#endif\n\n/* Dimensions and strides */\n#define PyDimMem_NEW(size) ((intp *)_pya_malloc(size*sizeof(intp)))\n#define PyDimMem_FREE(ptr) _pya_free(ptr)\n#define PyDimMem_RENEW(ptr,size) ((intp *)_pya_realloc(ptr,size*sizeof(intp)))\n\n\n /* These must deal with unaligned and swapped data if necessary */\ntypedef PyObject * (PyArray_GetItemFunc) (void *, void *);\ntypedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);\n\ntypedef void (PyArray_CopySwapNFunc)(void *, void *, intp, int, int);\ntypedef void (PyArray_CopySwapFunc)(void *, void *, int, int);\ntypedef Bool (PyArray_NonzeroFunc)(void *, void *);\n\n\n /* These assume aligned and notswapped data -- a buffer will be\n used before or contiguous data will be obtained\n */\ntypedef int (PyArray_CompareFunc)(const void *, const void *, void *);\ntypedef int (PyArray_ArgFunc)(void*, intp, intp*, void *);\ntypedef void (PyArray_DotFunc)(void *, intp, void *, intp, void *, intp,\n\t\t\t void *);\ntypedef void (PyArray_VectorUnaryFunc)(void *, void *, intp, void *, void *);\ntypedef int (PyArray_ScanFunc)(FILE *, void *, void *, void *);\ntypedef int (PyArray_FromStrFunc)(char *, void *, char **, void *);\n\ntypedef int (PyArray_FillFunc)(void *, intp, void *);\n\ntypedef int (PyArray_SortFunc)(void *, intp, void *);\ntypedef int (PyArray_ArgSortFunc)(void *, intp *, intp, void *);\n\ntypedef int (PyArray_FillWithScalarFunc)(void *, intp, void *, void *);\n\ntypedef struct {\n intp *ptr;\n int len;\n} PyArray_Dims;\n\ntypedef struct {\n\t/* Functions to cast to all other standard types*/\n\tPyArray_VectorUnaryFunc *cast[PyArray_NTYPES];\n\n\t/* Functions to get and set items with standard\n\t Python types -- not array scalars */\n\tPyArray_GetItemFunc *getitem;\n\tPyArray_SetItemFunc *setitem;\n\n\t/* Copy and/or swap data. Memory areas may not overlap */\n\t/* Use memmove first if they might */\n\tPyArray_CopySwapNFunc *copyswapn;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Function to compare items */\n\tPyArray_CompareFunc *compare;\n\n\t/* Function to select largest */\n\tPyArray_ArgFunc *argmax;\n\n\t/* Function to compute dot product */\n\tPyArray_DotFunc\t*dotfunc;\n\n\t/* Function to scan an ASCII file and\n\t place a single value plus possible separator */\n\tPyArray_ScanFunc *scanfunc;\n\n\t/* Function to read a single value from a string */\n\t/* and adjust the pointer */\n\tPyArray_FromStrFunc *fromstr;\n\n\t/* Function to determine if data is zero or not */\n\tPyArray_NonzeroFunc *nonzero;\n\n\t/* Used for arange */\n\tPyArray_FillFunc *fill;\n\n\t/* Function to fill arrays with scalar values */\n\tPyArray_FillWithScalarFunc *fillwithscalar;\n\n\t/* Sorting functions */\n\tPyArray_SortFunc *sort[PyArray_NSORTS];\n\tPyArray_ArgSortFunc *argsort[PyArray_NSORTS];\n\n} PyArray_ArrFuncs;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tPyTypeObject *typeobj; /* the type object representing an\n\t\t\t\t intance of this type */\n\tchar kind; /* kind for this type */\n\tchar type; /* unique-character representing this type */\n\tchar byteorder; /* '>' (big), '<' (little), '|'\n\t\t\t\t (not-applicable), or '=' (native). */\n char hasobject; /* non-zero if it has object arrays in fields */\n\tint type_num; /* number representing this type */\n\tint elsize; /* element size for this type */\n\tint alignment; /* alignment needed for this type */\n\tstruct _arr_descr\t\t\t\t\t\\\n\t*subarray; /* Non-NULL if this type is\n\t\t\t\t is an array (C-contiguous)\n\t\t\t\t of some other type\n\t\t\t\t*/\n\tPyObject *fields; /* The fields dictionary for this type */\n\t /* For statically defined descr this\n\t\t\t\t is always Py_None */\n\n\tPyArray_ArrFuncs *f; /* a table of functions specific for each\n\t\t\t\t basic data descriptor */\n} PyArray_Descr;\n\ntypedef struct _arr_descr {\n\tPyArray_Descr *base;\n\tPyObject *shape; /* a tuple */\n} PyArray_ArrayDescr;\n\n\n/*\n The main array object structure. It is recommended to use the macros\n defined below (PyArray_DATA and friends) access fields here, instead\n of the members themselves.\n */\n\ntypedef struct PyArrayObject {\n\tPyObject_HEAD\n\tchar *data; /* pointer to raw data buffer */\n\tint nd; /* number of dimensions, also called ndim */\n\tintp *dimensions; /* size in each dimension */\n intp *strides; /* bytes to jump to get to the\n\t\t\t\t next element in each dimension */\n\tPyObject *base; /* This object should be decref'd\n\t\t\t\t upon deletion of array */\n\t /* For views it points to the original array */\n\t /* For creation from buffer object it points\n\t\t\t\t to an object that shold be decref'd on\n\t\t\t\t deletion */\n\t /* For UPDATEIFCOPY flag this is an array\n\t\t\t\t to-be-updated upon deletion of this one */\n\tPyArray_Descr *descr; /* Pointer to type structure */\n\tint flags; /* Flags describing array -- see below*/\n\tPyObject *weakreflist; /* For weakreferences */\n} PyArrayObject;\n\n\n#define fortran fortran_ /* For some compilers */\n\n/* Mirrors buffer object to ptr */\n\ntypedef struct {\n PyObject_HEAD\n PyObject *base;\n void *ptr;\n intp len;\n int flags;\n} PyArray_Chunk;\n\n/* Array flags */\n\n/* Means c-style contiguous (last index varies the fastest). The\n data elements right after each other. */\n#define CONTIGUOUS 0x0001\n/* set if array is a contiguous Fortran array: the first index\n varies the fastest in memory (strides array is reverse of\n C-contiguous array)*/\n#define FORTRAN 0x0002\n\n/*\n Note: all 0-d arrays are CONTIGUOUS and FORTRAN contiguous. If a\n 1-d array is CONTIGUOUS it is also FORTRAN contiguous\n*/\n\n/* If set, the array owns the data: it will be free'd when the array\n is deleted. */\n#define OWNDATA 0x0004\n#define OWN_DATA OWNDATA\n\n/* An array never has these three set; they're only used as parameter\n flags to the the various FromAny functions */\n/* Cause a cast to occur regardless of whether or not it is safe. */\n#define FORCECAST 0x0010\n/* Always copy the array. Returned arrays are always CONTIGUOUS, ALIGNED,\n and WRITEABLE. */\n#define ENSURECOPY 0x0020\n/* Make sure the returned array is an ndarray or a bigndarray */\n#define ENSUREARRAY 0x0040\n\n/* Array data is aligned on the appropiate memory address for the\n type stored (e.g., an array of doubles (8 bytes each) starts on\n a memory address that's a multiple of 8) */\n#define ALIGNED 0x0100\n/* Array data has the native endianness */\n#define NOTSWAPPED 0x0200\n/* Array data is writeable */\n#define WRITEABLE 0x0400\n/* If this flag is set, then base contains a pointer to an array of\n the same size that should be updated with the current contents of\n this array when this array is deallocated\n*/\n#define UPDATEIFCOPY 0x1000\n\n\n#define BEHAVED_FLAGS ALIGNED | WRITEABLE\n#define BEHAVED_NS_FLAGS ALIGNED | WRITEABLE | NOTSWAPPED\n#define CARRAY_FLAGS CONTIGUOUS | BEHAVED_FLAGS\n#define CARRAY_FLAGS_RO CONTIGUOUS | ALIGNED\n#define FARRAY_FLAGS FORTRAN | BEHAVED_FLAGS\n#define FARRAY_FLAGS_RO FORTRAN | ALIGNED\n#define DEFAULT_FLAGS CARRAY_FLAGS\n\n#define UPDATE_ALL_FLAGS CONTIGUOUS | FORTRAN | ALIGNED\n\n\n/* Size of internal buffers used for alignment */\n#define PyArray_BUFSIZE 10000\n#define PyArray_MIN_BUFSIZE 5\n#define PyArray_MAX_BUFSIZE 100000000\n\n/*\n * C API: consists of Macros and functions. The MACROS are defined here.\n */\n\n\n#define PyArray_CHKFLAGS(m, FLAGS) \\\n\t((((PyArrayObject *)(m))->flags & (FLAGS)) == (FLAGS))\n#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, CONTIGUOUS)\n#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, WRITEABLE)\n#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, ALIGNED)\n\n#ifndef MAX\n#define MAX(a,b) (((a)>(b))?(a):(b))\n#endif\n#ifndef MIN\n#define MIN(a,b) (((a)<(b))?(a):(b))\n#endif\n\n/* Useful if a and b have to be evaluated. */\n\n#define tMAX(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_>_y_ ? _x_ : _y_}\n#define tMIN(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_<_y_ ? _x_ : _y_}\n\n#if defined(ALLOW_THREADS)\n#define BEGIN_THREADS_DEF PyThreadState *_save;\n#define BEGIN_THREADS _save = PyEval_SaveThread();\n#define END_THREADS PyEval_RestoreThread(_save);\n#define ALLOW_C_API_DEF PyGILState_STATE __save__;\n#define ALLOW_C_API __save__ = PyGILState_Ensure();\n#define DISABLE_C_API PyGILState_Release(__save__);\n#else\n#define BEGIN_THREADS_DEF\n#define BEGIN_THREADS\n#define END_THREADS\n#define ALLOW_C_API_DEF\n#define\tALLOW_C_API\n#define\tDISABLE_C_API\n#endif\n\n\n\n\ntypedef struct {\n PyObject_HEAD\n\tint nd_m1; /* number of dimensions - 1 */\n intp\t\t index, size;\n\tintp coordinates[MAX_DIMS];/* N-dimensional loop */\n intp dims_m1[MAX_DIMS]; /* ao->dimensions - 1 */\n\tintp strides[MAX_DIMS]; /* ao->strides or fake */\n\tintp backstrides[MAX_DIMS];/* how far to jump back */\n\tintp factors[MAX_DIMS]; /* shape factors */\n\tPyArrayObject *ao;\n\tchar *dataptr; /* pointer to current item*/\n Bool contiguous;\n} PyArrayIterObject;\n\n\n/* Iterator API */\n#define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type)\n\n#define PyArray_ITER_RESET(it) {\t\t\t\t\t\\\n\tit->index = 0;\t\t\t\t\t\t \\\n\tit->dataptr = it->ao->data;\t\t\t\t\t\\\n\tmemset(it->coordinates, 0, (it->nd_m1+1)*sizeof(intp));\t\t\\\n}\n\n#define _PyArray_ITER_NEXT1(it) {\t\t\\\n\t\tit->dataptr += it->strides[0];\t\\\n\t\tit->coordinates[0]++;\t\t\\\n\t}\n\n#define _PyArray_ITER_NEXT2(it) {\t\t\t\t\t\\\n\t\tif (it->coordinates[1] < it->dims_m1[1]) {\t\t\\\n\t\t\tit->coordinates[1]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->coordinates[1] = 0;\t\t\t\t\\\n\t\t\tit->coordinates[0]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[0] -\t\t\t\\\n\t\t\t\tit->backstrides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_NEXT(it) {\t\t\t\t\t\t\\\n\tit->index++;\t\t\t\t\t\t \\\n if (it->nd_m1 == 0) {\t\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT1(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse if (it->contiguous) it->dataptr += it->ao->descr->elsize; \\\n\telse if (it->nd_m1 == 1) {\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT2(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse {\t\t\t\t\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_ >= 0; _i_--) {\t\t\\\n\t\t\tif (it->coordinates[_i_] <\t\t\t\\\n\t\t\t it->dims_m1[_i_]) {\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_]++;\t\t\t\\\n\t\t\t\tit->dataptr += it->strides[_i_];\t\\\n\t\t\t\tbreak;\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t\telse {\t\t\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_] = 0;\t\t\\\n\t\t\t\tit->dataptr -= it->backstrides[_i_];\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_GOTO(it, destination) {\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tit->index = 0;\t\t\t\t\t\t\\\n\t\tit->dataptr = it->ao->data;\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_>=0; _i_--) {\t\t\t\\\n\t\t\tit->dataptr += destination[_i_] *\t\t\\\n\t\t\t\tit->strides[_i_];\t\t\t\\\n\t\t\tit->coordinates[_i_] = destination[_i_];\t\\\n\t\t\tit->index += destination[_i_] *\t\t\t\\\n\t\t\t\t( _i_==it->nd_m1 ? 1 :\t\t\t\\\n\t\t\t\t it->dims_m1[i+1]+1) ;\t\t \\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_GOTO1D(it, ind) { \\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tintp _lind_ = (intp) (ind);\t\t\t\t\\\n\t\tit->index = _lind_;\t\t\t\t\t\\\n if (it->nd_m1 == 0) { \\\n it->dataptr = it->ao->data + (ind) * \\\n it->strides[0]; \\\n } \\\n else if (it->contiguous) \\\n\t\t\tit->dataptr = it->ao->data + (ind) *\t\t\\\n\t\t\t\tit->ao->descr->elsize;\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->dataptr = it->ao->data;\t\t\t\\\n\t\t\tfor (_i_ = 0; _i_<=it->nd_m1; _i_++) {\t\t\\\n\t\t\t\tit->dataptr += (_lind_ / it->factors[_i_]) \\\n\t\t\t\t\t* it->strides[_i_];\t\t\\\n\t\t\t\t_lind_ %= it->factors[_i_];\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_DATA(it) ((PyArrayIterObject *)it)->dataptr\n\n\n/*\n Any object passed to PyArray_Broadcast must be binary compatible with\n this structure.\n*/\n\ntypedef struct {\n\tPyObject_HEAD\n\n\tint numiter; /* number of iters */\n\tintp size; /* broadcasted size */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* iterators */\n} PyArrayMultiIterObject;\n\n#define PyArray_MultiIter_RESET(multi) {\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index = 0;\t\t\t\t \\\n\t\tfor (_mi_ = 0; _mi_ < _mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_RESET(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_NEXT(multi) {\t\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index += 1;\t\t\t\t \\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_NEXT(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_GOTO(multi, dest) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO(_mul_->iters[_mi_], dest);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_GOTO1D(multi, ind) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO1D(_mul_->iters[_mi_], ind);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_DATA(multi, i) \\\n\t((PyArrayMultiIterObject *)multi)->iters[i]->dataptr\n\n#define PyArray_MultiIter_SIZE(multi) \\\n\t((PyArrayMultiIterObject *)multi)->size;\n\n\n/* Store the information needed for fancy-indexing over an array */\n\ntypedef struct {\n\tPyObject_HEAD\n\t/* Multi-iterator portion --- needs to be present in this order to\n\t work with PyArray_Broadcast */\n\n\tint numiter; /* number of index-array\n\t\t\t\t\t\t\t iterators */\n\tintp size; /* size of broadcasted\n\t\t\t\t\t\t\t result */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* index object\n\t\t\t\t\t\t\t iterators */\n\tPyArrayIterObject *ait; /* flat Iterator for\n\t\t\t\t\t\t\t underlying array */\n\n\t/* flat iterator for subspace (when numiter < nd) */\n\tPyArrayIterObject *subspace;\n\n\t/* if subspace iteration, then this is the array of\n\t axes in the underlying array represented by the\n\t index objects */\n\tint iteraxes[MAX_DIMS];\n\t/* if subspace iteration, the these are the coordinates\n\t to the start of the subspace.\n\t*/\n\tintp bscoord[MAX_DIMS];\n\n\tPyObject *indexobj; /* reference to\n\t\t\t\t\t\t\t creating obj */\n\tint view;\n\tint consec;\n\tchar *dataptr;\n\n} PyArrayMapIterObject;\n\n/* All sorts of useful ways to look into a PyArrayObject.\n These are the recommended over casting to PyArrayObject and accessing\n the members directly.\n */\n\n#define PyArray_NDIM(obj) (((PyArrayObject *)(obj))->nd)\n#define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || PyArray_CHKFLAGS(m, CONTIGUOUS) || \\\n\t\t\t\t PyArray_CHKFLAGS(m, FORTRAN))\n#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, FORTRAN) && (PyArray_NDIM(m) > 1))\n#define FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, FORTRAN) ? FORTRAN : 0))\n#define PyArray_DATA(obj) ((void *)(((PyArrayObject *)(obj))->data))\n#define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data)\n#define PyArray_DIMS(obj) (((PyArrayObject *)(obj))->dimensions)\n#define PyArray_STRIDES(obj) (((PyArrayObject *)(obj))->strides)\n#define PyArray_DIM(obj,n) (((PyArrayObject *)(obj))->dimensions[n])\n#define PyArray_STRIDE(obj,n) (((PyArrayObject *)(obj))->strides[n])\n#define PyArray_BASE(obj) (((PyArrayObject *)(obj))->base)\n#define PyArray_DESCR(obj) (((PyArrayObject *)(obj))->descr)\n#define PyArray_FLAGS(obj) (((PyArrayObject *)(obj))->flags)\n#define PyArray_ITEMSIZE(obj) (((PyArrayObject *)(obj))->descr->elsize)\n#define PyArray_TYPE(obj) (((PyArrayObject *)(obj))->descr->type_num)\n#define PyArray_GETITEM(obj,itemptr)\t\t\t\\\n\t((PyArrayObject *)(obj))->descr->f->getitem((char *)itemptr,\t\\\n\t\t\t\t\t\t (PyArrayObject *)obj);\n#define PyArray_SETITEM(obj,itemptr,v)\t\t\t\t\t\\\n\t(obj)->descr->f->setitem((PyObject *)v,(char *)(itemptr),\t\t\\\n\t\t\t (PyArrayObject *)(obj));\n\n\n#define PyTypeNum_ISBOOL(type) (type == PyArray_BOOL)\n#define PyTypeNum_ISUNSIGNED(type) ((type == PyArray_UBYTE) || \\\n\t\t\t\t (type == PyArray_USHORT) || \\\n\t\t\t\t (type == PyArray_UINT) ||\t\\\n\t\t\t\t (type == PyArray_ULONG) || \\\n\t\t\t\t (type == PyArray_ULONGLONG))\n\n#define PyTypeNum_ISSIGNED(type) ((type == PyArray_BYTE) ||\t\\\n\t\t\t (type == PyArray_SHORT) ||\t\\\n\t\t\t (type == PyArray_INT) ||\t\\\n\t\t\t (type == PyArray_LONG) ||\t\\\n\t\t\t (type == PyArray_LONGLONG))\n\n#define PyTypeNum_ISINTEGER(type) ((type >= PyArray_BYTE) &&\t\\\n\t\t\t\t(type <= PyArray_ULONGLONG))\n\n#define PyTypeNum_ISFLOAT(type) ((type >= PyArray_FLOAT) && \\\n\t\t\t (type <= PyArray_LONGDOUBLE))\n\n#define PyTypeNum_ISNUMBER(type) (type <= PyArray_CLONGDOUBLE)\n\n#define PyTypeNum_ISSTRING(type) ((type == PyArray_UCHAR) || \\\n\t\t\t (type == PyArray_UNICODE))\n\n#define PyTypeNum_ISCOMPLEX(type) ((type >= PyArray_CFLOAT) && \\\n\t\t\t\t(type <= PyArray_CLONGDOUBLE))\n\n#define PyTypeNum_ISPYTHON(type) ((type == PyArray_LONG) || \\\n\t\t\t\t (type == PyArray_DOUBLE) ||\t\\\n\t\t\t\t (type == PyArray_CDOUBLE) ||\t\\\n\t\t (type == PyArray_BOOL) || \\\n\t\t\t\t (type == PyArray_OBJECT ))\n\n#define PyTypeNum_ISFLEXIBLE(type) ((type>=PyArray_STRING) && \\\n\t\t\t\t (type<=PyArray_VOID))\n\n#define PyTypeNum_ISUSERDEF(type) ((type >= PyArray_USERDEF) && \\\n\t\t\t\t (type < PyArray_USERDEF+\\\n\t\t\t\t PyArray_NUMUSERTYPES))\n\n#define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \\\n PyTypeNum_ISUSERDEF(type))\n\n#define PyTypeNum_ISOBJECT(type) ((type) == PyArray_OBJECT)\n\n#define _PyADt(o) ((PyArray_Descr *)o)->type_num\n#define PyDescr_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj))\n#define PyDescr_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(_PyADt(obj))\n#define PyDescr_ISSIGNED(obj) PyTypeNum_ISSIGNED(_PyADt(obj))\n#define PyDescr_ISINTEGER(obj) PyTypeNum_ISINTEGER(_PyADt(obj))\n#define PyDescr_ISFLOAT(obj) PyTypeNum_ISFLOAT(_PyADt(obj))\n#define PyDescr_ISNUMBER(obj) PyTypeNum_ISNUMBER(_PyADt(obj))\n#define PyDescr_ISSTRING(obj) PyTypeNum_ISSTRING(_PyADt(obj))\n#define PyDescr_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(_PyADt(obj))\n#define PyDescr_ISPYTHON(obj) PyTypeNum_ISPYTHON(_PyADt(obj))\n#define PyDescr_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(_PyADt(obj))\n#define PyDescr_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(_PyADt(obj))\n#define PyDescr_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(_PyADt(obj))\n#define PyDescr_ISOBJECT(obj) PyTypeNum_ISOBJECT(_PyADt(obj))\n#undef _PyAD\n\n#define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))\n#define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))\n#define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))\n#define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))\n#define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))\n#define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))\n#define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj))\n#define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))\n#define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))\n#define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))\n#define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))\n\n#define PyArray_LITTLE '<'\n#define PyArray_BIG '>'\n#define PyArray_NATIVE '='\n#define PyArray_SWAP 's'\n#define PyArray_IGNORE '|'\n\n#ifdef WORDS_BIGENDIAN\n#define PyArray_NATBYTE PyArray_BIG\n#define PyArray_OPPBYTE PyArray_LITTLE\n#else\n#define PyArray_NATBYTE PyArray_LITTLE\n#define PyArray_OPPBYTE PyArray_BIG\n#endif\n\n#define PyArray_ISNBO(arg) ((arg) != PyArray_OPPBYTE)\n#define PyArray_IsNativeByteOrder PyArray_ISNBO\n#define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)\n\n#define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) &&\t\\\n\t\t\t\t PyArray_ISNOTSWAPPED(m))\n#define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS)\n#define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS_RO)\n#define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS)\n#define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS_RO)\n#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, BEHAVED_FLAGS)\n#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, ALIGNED)\n\n\n\n/* This is the form of the struct that's returned pointed by the\n PyCObject attribute of an array __array_struct__. See\n http://numeric.scipy.org/array_interface.html for the full\n documentation. */\ntypedef struct {\n int version; /* contains the integer 2 as a sanity check */\n int nd; /* number of dimensions */\n char typekind; /* kind in array --- character code of typestr */\n int itemsize; /* size of each element */\n int flags; /* how should be data interpreted. Valid\n flags are CONTIGUOUS (1), FORTRAN (2),\n ALIGNED (0x100), NOTSWAPPED (0x200), and\n WRITEABLE (0x400)*/\n intp *shape; /* A length-nd array of shape information */\n intp *strides; /* A length-nd array of stride information */\n void *data; /* A pointer to the first element of the array */\n} PyArrayInterface;\n\n/* Includes the \"function\" C-API -- these are all stored in a\n list of pointers --- one for each file\n The two lists are concatenated into one in multiarray.\n\n They are available as import_array()\n*/\n\n\n#include \"__multiarray_api.h\"\n\n\n/* C-API that requries previous API to be defined */\n\n#define PyArray_DescrCheck(op) ((op)->ob_type == &PyArrayDescr_Type)\n\n#define PyArray_Check(op) ((op)->ob_type == &PyArray_Type ||\t\t\\\n\t\t\t PyObject_TypeCheck((op), &PyArray_Type))\n#define PyArray_CheckExact(op) ((op)->ob_type == &PyArray_Type)\n\n#define PyArray_IsZeroDim(op) (PyArray_Check(op) && (PyArray_NDIM(op) == 0))\n#define PyArray_IsScalar(obj, cls)\t\t\t\t\\\n\t(PyObject_TypeCheck((obj), &Py##cls##ArrType_Type))\n#define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \\\n PyArray_IsZeroDim(m))\n#define PyArray_IsPythonScalar(obj) \\\n\t(PyInt_Check(obj) || PyFloat_Check(obj) || PyComplex_Check(obj) || \\\n\t PyLong_Check(obj) || PyBool_Check(obj) || PyString_Check(obj) || \\\n\t PyUnicode_Check(obj))\n#define PyArray_IsAnyScalar(obj)\t\t\t\t\t\\\n\t(PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))\n#define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \\\n\t\t\t\t PyArray_CheckScalar(obj))\n\n#define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? Py_INCREF(m), m : \\\n (PyArrayObject *)(PyArray_Copy(m)))\n\n#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))\n#define PyArray_NBYTES(m) (PyArray_ITEMSIZE(m) * PyArray_SIZE(m))\n#define PyArray_FROM_O(m) PyArray_FromAny(m, NULL, 0, 0, 0, NULL)\n#define PyArray_FROM_OF(m,flags) PyArray_CheckFromAny(m, NULL, 0, 0, flags, NULL)\n#define PyArray_FROM_OT(m,type) PyArray_FromAny(m, PyArray_DescrFromType(type), \\\n 0, 0, 0, NULL);\n#define PyArray_FROM_OTF(m, type, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \\\n (((flags) & ENSURECOPY) ? \\\n ((flags) | DEFAULT_FLAGS) : (flags)), NULL)\n#define PyArray_FROMANY(m, type, min, max, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \\\n (((flags) & ENSURECOPY) ? \\\n (flags) | DEFAULT_FLAGS : (flags)), NULL)\n\n#define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), (val), PyArray_NBYTES(obj))\n\n#define REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)\n#define MAX_ELSIZE 2*SIZEOF_LONGDOUBLE\n\n#define PyArray_ContiguousFromAny(op, type, min_depth, max_depth) \\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, DEFAULT_FLAGS, NULL)\n\n#define PyArray_EquivArrTypes(a1, a2)\t\t\t\t\t\\\n\tPyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))\n#define PyArray_EquivTypenums(typenum1, typenum2)\t\t\\\n\tPyArray_EquivTypes(PyArray_DescrFromType(typenum1),\t\\\n\t\t\t PyArray_DescrFromType(typenum2))\n\n#define PyArray_EquivByteorders(b1, b2) \\\n\t((b1 == b2) || (PyArray_ISNBO(b1) == PyArray_ISNBO(b2)))\n\n#define PyArray_SimpleNew(nd, dims, typenum) \\\n\tPyArray_New(&PyArray_Type, nd, dims, typenum, NULL, NULL, 0, 0, NULL)\n#define PyArray_SimpleNewFromData(nd, dims, typenum, data) \\\n PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, data, 0, CARRAY_FLAGS, NULL)\n#define PyArray_SimpleNewFromDescr(nd, dims, descr) \\\n\tPyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, NULL, NULL, 0, NULL)\n#define PyArray_EnsureAnyArray(obj) \\\n\t(PyArray_Check(obj) ? obj : PyArray_EnsureArray(obj))\n\n\n/* These might be faster without the dereferencing of obj\n going on inside -- of course an optimizing compiler should\n inline the constants inside a for loop making it a moot point\n*/\n\n#define PyArray_GETPTR1(obj, i) (void *)(PyArray_BYTES(obj) +\t\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0))\n\n#define PyArray_GETPTR2(obj, i, j) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1))\n\n#define PyArray_GETPTR3(obj, i, j, k) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\\n\t\t\t\t\t k*PyArray_STRIDE(obj, 2)) \\\n\n#define PyArray_GETPTR4(obj, i, j, k, l) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\\n\t\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\\n\t\t\t\t\t\t k*PyArray_STRIDE(obj, 2) + \\\n\t\t\t\t\t\t l*PyArray_STRIDE(obj, 3))\n\n#define PyArray_DESCR_REPLACE(descr) do {\t\\\n\t\tPyArray_Descr *_new_;\t\t\t\\\n\t\t_new_ = PyArray_DescrNew(descr);\t\\\n\t\tPy_XDECREF(descr);\t\t\t\\\n\t\tdescr = _new_;\t\t\t\t\\\n\t} while(0)\n\n/* Copy should always return contiguous array */\n#define PyArray_Copy(obj) PyArray_NewCopy(obj, 0)\n\n#define PyArray_FromObject(op, type, min_depth, max_depth)\t\t\\\n\tPyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, BEHAVED_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_ContiguousFromObject(op, type, min_depth, max_depth)\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_CopyFromObject(op, type, min_depth, max_depth)\t\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, ENSURECOPY | DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_Cast(mp, type_num) \\\n\tPyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)\n\n/* Compatibility with old Numeric stuff -- don't use in new code */\n\n#define PyArray_FromDimsAndData(nd, d, type, data) \\\n\tPyArray_FromDimsAndDataAndDescr(nd, d, PyArray_DescrFromType(type), \\\n\t\t\t\t\tdata)\n\n#define PyArray_UNSIGNED_TYPES\n#define PyArray_SBYTE PyArray_BYTE\n#define PyArray_CHAR PyArray_BYTE\n#define PyArray_CopyArray PyArray_CopyInto\n#define _PyArray_multiply_list PyArray_MultiplyIntList\n#define PyArray_ISSPACESAVER(m) FALSE\n#define PyScalarArray_Check PyArray_CheckScalar\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# undef CAT\n# undef CAT2\n# undef NS\n# undef longlong\n# undef ulonglong\n# undef Bool\n# undef longdouble\n# undef byte\n# undef ubyte\n# undef ushort\n# undef uint\n# undef ulong\n# undef cfloat\n# undef cdouble\n# undef clongdouble\n# undef Int8\n# undef UInt8\n# undef Int16\n# undef UInt16\n# undef Int32\n# undef UInt32\n# undef Int64\n# undef UInt64\n# undef Int128\n# undef UInt128\n# undef Int256\n# undef UInt256\n# undef Float16\n# undef Complex32\n# undef Float32\n# undef Complex64\n# undef Float64\n# undef Complex128\n# undef Float80\n# undef Complex160\n# undef Float96\n# undef Complex192\n# undef Float128\n# undef Complex256\n# undef intp\n# undef uintp\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* !Py_ARRAYOBJECT_H */\n", + "source_code_before": "\n/* This expects the following variables to be defined (besides\n the usual ones from pyconfig.h\n\n SIZEOF_LONG_DOUBLE -- sizeof(long double) or sizeof(double) if no\n long double is present on platform.\n CHAR_BIT -- number of bits in a char (usually 8)\n (should be in limits.h)\n*/\n\n#ifndef Py_ARRAYOBJECT_H\n#define Py_ARRAYOBJECT_H\n#ifdef __cplusplus\n#define CONFUSE_EMACS {\n#define CONFUSE_EMACS2 }\nextern \"C\" CONFUSE_EMACS\n#undef CONFUSE_EMACS\n#undef CONFUSE_EMACS2\n/* ... otherwise a semi-smart idententer (like emacs) tries to indent\n everything when you're typing */\n#endif\n#include \"config.h\"\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# define CAT2(x,y) x ## y\n# define CAT(x,y) CAT2(x,y)\n# define NS(name) CAT(PY_ARRAY_TYPES_PREFIX, name)\n# define longlong NS(longlong)\n# define ulonglong NS(ulonglong)\n# define Bool NS(Bool)\n# define longdouble NS(longdouble)\n# define byte NS(byte)\n# define ubyte NS(ubyte)\n# define ushort NS(ushort)\n# define uint NS(uint)\n# define ulong NS(ulong)\n# define cfloat NS(cfloat)\n# define cdouble NS(cdouble)\n# define clongdouble NS(clongdouble)\n# define Int8 NS(Int8)\n# define UInt8 NS(UInt8)\n# define Int16 NS(Int16)\n# define UInt16 NS(UInt16)\n# define Int32 NS(Int32)\n# define UInt32 NS(UInt32)\n# define Int64 NS(Int64)\n# define UInt64 NS(UInt64)\n# define Int128 NS(Int128)\n# define UInt128 NS(UInt128)\n# define Int256 NS(Int256)\n# define UInt256 NS(UInt256)\n# define Float16 NS(Float16)\n# define Complex32 NS(Complex32)\n# define Float32 NS(Float32)\n# define Complex64 NS(Complex64)\n# define Float64 NS(Float64)\n# define Complex128 NS(Complex128)\n# define Float80 NS(Float80)\n# define Complex160 NS(Complex160)\n# define Float96 NS(Float96)\n# define Complex192 NS(Complex192)\n# define Float128 NS(Float128)\n# define Complex256 NS(Complex256)\n# define intp NS(intp)\n# define uintp NS(uintp)\n#endif\n\n/* There are several places in the code where an array of dimensions is */\n/* allocated statically. This is the size of that static allocation. */\n/* The array creation itself could have arbitrary dimensions but\n * all the places where static allocation is used would need to\n * be changed to dynamic (including inside of structures)\n */\n\n#define MAX_DIMS 32\n\n/* Used for Converter Functions \"O&\" code in ParseTuple */\n#define PY_FAIL 0\n#define PY_SUCCEED 1\n\n /* Helpful to distinguish what is installed */\n#define NDARRAY_VERSION 0x00090701\n\n\t/* Some platforms don't define bool, long long, or long double.\n\t Handle that here.\n\t */\n\n#ifdef PY_LONG_LONG\ntypedef PY_LONG_LONG longlong;\ntypedef unsigned PY_LONG_LONG ulonglong;\n# ifdef _MSC_VER\n# define LONGLONG_FMT \"I64d\"\n# define ULONGLONG_FMT \"I64u\"\n# define LONGLONG_SUFFIX(x) (x##i64)\n# define ULONGLONG_SUFFIX(x) (x##Ui64)\n# else\n\t/* #define LONGLONG_FMT \"lld\" Another possible variant\n #define ULONGLONG_FMT \"llu\"\n\n\t #define LONGLONG_FMT \"qd\" -- BSD perhaps?\n\t #define ULONGLONG_FMT \"qu\"\n\t*/\n# define LONGLONG_FMT \"Ld\"\n# define ULONGLONG_FMT \"Lu\"\n# define LONGLONG_SUFFIX(x) (x##LL)\n# define ULONGLONG_SUFFIX(x) (x##ULL)\n# endif\n#else\ntypedef long longlong;\ntypedef unsigned long ulonglong;\n# define LONGLONG_SUFFIX(x) (x##L)\n# define ULONGLONG_SUFFIX(x) (x##UL)\n#endif\n\ntypedef unsigned char Bool;\n#ifndef FALSE\n#define FALSE 0\n#endif\n#ifndef TRUE\n#define TRUE 1\n#endif\n\n#if SIZEOF_LONG_DOUBLE==SIZEOF_DOUBLE\n\ttypedef double longdouble;\n #define LONGDOUBLE_FMT \"g\"\n#else\n\ttypedef long double longdouble;\n #define LONGDOUBLE_FMT \"Lg\"\n#endif\n\n#ifndef Py_USING_UNICODE\n#error Must use Python with unicode enabled. \n#endif\n\n\ntypedef signed char byte;\ntypedef unsigned char ubyte;\n#ifndef _BSD_SOURCE\ntypedef unsigned short ushort;\ntypedef unsigned int uint;\ntypedef unsigned long ulong;\n#endif\n\ntypedef struct { float real, imag; } cfloat;\ntypedef struct { double real, imag; } cdouble;\ntypedef struct {longdouble real, imag;} clongdouble;\n\nenum PyArray_TYPES { PyArray_BOOL=0,\n PyArray_BYTE, PyArray_UBYTE,\n\t\t PyArray_SHORT, PyArray_USHORT,\n\t\t PyArray_INT, PyArray_UINT,\n\t\t\tPyArray_LONG, PyArray_ULONG,\n PyArray_LONGLONG, PyArray_ULONGLONG,\n\t\t\tPyArray_FLOAT, PyArray_DOUBLE, PyArray_LONGDOUBLE,\n\t\t\tPyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CLONGDOUBLE,\n\t\t\tPyArray_OBJECT=17,\n PyArray_STRING, PyArray_UNICODE,\n\t\t\tPyArray_VOID,\n\t\t\tPyArray_NTYPES,\n\t\t\tPyArray_NOTYPE,\n\t\t\tPyArray_USERDEF=256 /* leave room for characters */\n};\n\n\t/* basetype array priority */\n#define PyArray_PRIORITY 0.0\n#define PyArray_BIG_PRIORITY 0.1\n\t/* default subtype priority */\n#define PyArray_SUBTYPE_PRIORITY 1.0\n\n\t/* How many floating point types are there */\n#define PyArray_NUM_FLOATTYPE 3\n\n\n\t/* We need to match intp to a signed integer of the same size as\n\t a pointer variable. uintp to the equivalent unsigned integer\n\t*/\n\n\n\t/* These characters correspond to the array type and the\n\t struct module */\n\n\t/* except 'p' -- signed integer for pointer type */\n\nenum PyArray_TYPECHAR { PyArray_BOOLLTR = '?',\n\t\t\tPyArray_BYTELTR = 'b',\n\t\t\tPyArray_UBYTELTR = 'B',\n\t\t\tPyArray_SHORTLTR = 'h',\n\t\t\tPyArray_USHORTLTR = 'H',\n\t\t\tPyArray_INTLTR = 'i',\n\t\t\tPyArray_UINTLTR = 'I',\n\t\t\tPyArray_LONGLTR = 'l',\n\t\t\tPyArray_ULONGLTR = 'L',\n\t\t\tPyArray_LONGLONGLTR = 'q',\n\t\t\tPyArray_ULONGLONGLTR = 'Q',\n\t\t\tPyArray_FLOATLTR = 'f',\n\t\t\tPyArray_DOUBLELTR = 'd',\n\t\t\tPyArray_LONGDOUBLELTR = 'g',\n\t\t\tPyArray_CFLOATLTR = 'F',\n\t\t\tPyArray_CDOUBLELTR = 'D',\n\t\t\tPyArray_CLONGDOUBLELTR = 'G',\n\t\t\tPyArray_OBJECTLTR = 'O',\n\t\t\tPyArray_STRINGLTR = 'S',\n\t\t\tPyArray_STRINGLTR2 = 'a',\n\t\t\tPyArray_UNICODELTR = 'U',\n\t\t PyArray_VOIDLTR = 'V',\n\n\t\t\t/* No Descriptor, just a define -- this let's\n\t\t\t Python users specify an array of integers\n\t\t\t large enough to hold a pointer on the platform*/\n\t\t\tPyArray_INTPLTR = 'p',\n\t\t\tPyArray_UINTPLTR = 'P',\n\n\t\t\tPyArray_GENBOOLLTR ='b',\n\t\t\tPyArray_SIGNEDLTR = 'i',\n\t\t\tPyArray_UNSIGNEDLTR = 'u',\n\t\t\tPyArray_FLOATINGLTR = 'f',\n\t\t\tPyArray_COMPLEXLTR = 'c'\n};\n\ntypedef enum {\n\tPyArray_QUICKSORT=0,\n\tPyArray_HEAPSORT=1,\n\tPyArray_MERGESORT=2,\n\tPyArray_TIMSORT=3 /* the sort Python uses -- specialized */\n} PyArray_SORTKIND;\n#define PyArray_NSORTS PyArray_TIMSORT + 1\n\n\ntypedef enum {\n\tPyArray_NOSCALAR=0,\n\tPyArray_BOOL_SCALAR=1,\n\tPyArray_INTPOS_SCALAR=2,\n\tPyArray_INTNEG_SCALAR=3,\n\tPyArray_FLOAT_SCALAR=4,\n\tPyArray_COMPLEX_SCALAR=5,\n\tPyArray_OBJECT_SCALAR=6,\n} PyArray_SCALARKIND;\n\n\t/* Define bit-width array types and typedefs */\n\n#define MAX_INT8 127\n#define MIN_INT8 -128\n#define MAX_UINT8 255\n#define MAX_INT16 32767\n#define MIN_INT16 -32768\n#define MAX_UINT16 65535\n#define MAX_INT32 2147483647\n#define MIN_INT32 (-MAX_INT32 - 1)\n#define MAX_UINT32 4294967295U\n#define MAX_INT64 LONGLONG_SUFFIX(9223372036854775807)\n#define MIN_INT64 (-MAX_INT64 - LONGLONG_SUFFIX(1))\n#define MAX_UINT64 ULONGLONG_SUFFIX(18446744073709551615)\n#define MAX_INT128 LONGLONG_SUFFIX(85070591730234615865843651857942052864)\n#define MIN_INT128 (-MAX_INT128 - LONGLONG_SUFFIX(1))\n#define MAX_UINT128 ULONGLONG_SUFFIX(170141183460469231731687303715884105728)\n#define MAX_INT256 LONGLONG_SUFFIX(57896044618658097711785492504343953926634992332820282019728792003956564819967)\n#define MIN_INT256 (-MAX_INT256 - LONGLONG_SUFFIX(1))\n#define MAX_UINT256 ULONGLONG_SUFFIX(115792089237316195423570985008687907853269984665640564039457584007913129639935)\n\n\t/* Need to find the number of bits for each type and\n\t make definitions accordingly.\n\n\t C states that sizeof(char) == 1 by definition\n\n\t So, just using the sizeof keyword won't help.\n\n\t It also looks like Python itself uses sizeof(char) quite a\n\t bit, which by definition should be 1 all the time.\n\n\t Idea: Make Use of CHAR_BIT which should tell us how many\n\t BITS per CHARACTER\n\t*/\n\n\t/* Include platform definitions -- These are in the C89/90 standard */\n#include \n#define MAX_BYTE SCHAR_MAX\n#define MIN_BYTE SCHAR_MIN\n#define MAX_UBYTE UCHAR_MAX\n#define MAX_SHORT SHRT_MAX\n#define MIN_SHORT SHRT_MIN\n#define MAX_USHORT USHRT_MAX\n#define MAX_INT INT_MAX\n#ifndef INT_MIN\n#define INT_MIN (-INT_MAX - 1)\n#endif\n#define MIN_INT INT_MIN\n#define MAX_UINT UINT_MAX\n#define MAX_LONG LONG_MAX\n#define MIN_LONG LONG_MIN\n#define MAX_ULONG ULONG_MAX\n\n#define SIZEOF_LONGDOUBLE SIZEOF_LONG_DOUBLE\n#define SIZEOF_LONGLONG SIZEOF_LONG_LONG\n#define BITSOF_BOOL sizeof(Bool)*CHAR_BIT\n#define BITSOF_CHAR CHAR_BIT\n#define BITSOF_SHORT (SIZEOF_SHORT*CHAR_BIT)\n#define BITSOF_INT (SIZEOF_INT*CHAR_BIT)\n#define BITSOF_LONG (SIZEOF_LONG*CHAR_BIT)\n#define BITSOF_LONGLONG (SIZEOF_LONGLONG*CHAR_BIT)\n#define BITSOF_FLOAT (SIZEOF_FLOAT*CHAR_BIT)\n#define BITSOF_DOUBLE (SIZEOF_DOUBLE*CHAR_BIT)\n#define BITSOF_LONGDOUBLE (SIZEOF_LONGDOUBLE*CHAR_BIT)\n\n\n#if BITSOF_LONG == 8\n#define PyArray_INT8 PyArray_LONG\n#define PyArray_UINT8 PyArray_ULONG\n\ttypedef long Int8;\n\ttypedef unsigned long UInt8;\n#define STRBITSOF_LONG \"8\"\n#elif BITSOF_LONG == 16\n#define PyArray_INT16 PyArray_LONG\n#define PyArray_UINT16 PyArray_ULONG\n\ttypedef long Int16;\n\ttypedef unsigned long UInt16;\n#define STRBITSOF_LONG \"16\"\n#elif BITSOF_LONG == 32\n#define PyArray_INT32 PyArray_LONG\n#define PyArray_UINT32 PyArray_ULONG\n\ttypedef long Int32;\n\ttypedef unsigned long UInt32;\n\ttypedef unsigned long PyArray_UCS4;\n#define STRBITSOF_LONG \"32\"\n#elif BITSOF_LONG == 64\n#define PyArray_INT64 PyArray_LONG\n#define PyArray_UINT64 PyArray_ULONG\n\ttypedef long Int64;\n\ttypedef unsigned long UInt64;\n#define STRBITSOF_LONG \"64\"\n#elif BITSOF_LONG == 128\n#define PyArray_INT128 PyArray_LONG\n#define PyArray_UINT128 PyArray_ULONG\n\ttypedef long Int128;\n\ttypedef unsigned long UInt128;\n#define STRBITSOF_LONG \"128\"\n#endif\n\n#if BITSOF_LONGLONG == 8\n# ifndef PyArray_INT8\n# define PyArray_INT8 PyArray_LONGLONG\n# define PyArray_UINT8 PyArray_ULONGLONG\n\ttypedef longlong Int8;\n\ttypedef ulonglong UInt8;\n# endif\n# define MAX_LONGLONG MAX_INT8\n# define MIN_LONGLONG MIN_INT8\n# define MAX_ULONGLONG MAX_UINT8\n#define STRBITSOF_LONGLONG \"8\"\n#elif BITSOF_LONGLONG == 16\n# ifndef PyArray_INT16\n# define PyArray_INT16 PyArray_LONGLONG\n# define PyArray_UINT16 PyArray_ULONGLONG\n\ttypedef longlong Int16;\n\ttypedef ulonglong UInt16;\n# endif\n# define MAX_LONGLONG MAX_INT16\n# define MIN_LONGLONG MIN_INT16\n# define MAX_ULONGLONG MAX_UINT16\n#define STRBITSOF_LONGLONG \"16\"\n#elif BITSOF_LONGLONG == 32\n# ifndef PyArray_INT32\n# define PyArray_INT32 PyArray_LONGLONG\n# define PyArray_UINT32 PyArray_ULONGLONG\n\ttypedef longlong Int32;\n\ttypedef ulonglong UInt32;\n\ttypedef ulonglong PyArray_UCS4;\n# endif\n# define MAX_LONGLONG MAX_INT32\n# define MIN_LONGLONG MIN_INT32\n# define MAX_ULONGLONG MAX_UINT32\n#define STRBITSOF_LONGLONG \"32\"\n#elif BITSOF_LONGLONG == 64\n# ifndef PyArray_INT64\n# define PyArray_INT64 PyArray_LONGLONG\n# define PyArray_UINT64 PyArray_ULONGLONG\n\ttypedef longlong Int64;\n\ttypedef ulonglong UInt64;\n# endif\n# define MAX_LONGLONG MAX_INT64\n# define MIN_LONGLONG MIN_INT64\n# define MAX_ULONGLONG MAX_UINT64\n#define STRBITSOF_LONGLONG \"64\"\n#elif BITSOF_LONGLONG == 128\n# ifndef PyArray_INT128\n# define PyArray_INT128 PyArray_LONGLONG\n# define PyArray_UINT128 PyArray_ULONGLONG\n\ttypedef longlong Int128;\n\ttypedef ulonglong UInt128;\n# endif\n# define MAX_LONGLONG MAX_INT128\n# define MIN_LONGLONG MIN_INT128\n# define MAX_ULONGLONG MAX_UINT128\n#define STRBITSOF_LONGLONG \"128\"\n#elif BITSOF_LONGLONG == 256\n# define PyArray_INT256 PyArray_LONGLONG\n# define PyArray_UINT256 PyArray_ULONGLONG\n\ttypedef longlong Int256;\n\ttypedef ulonglong UInt256;\n# define MAX_LONGLONG MAX_INT256\n# define MIN_LONGLONG MIN_INT256\n# define MAX_ULONGLONG MAX_UINT256\n#define STRBITSOF_LONGLONG \"256\"\n#endif\n\n#if BITSOF_INT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_INT\n#define PyArray_UINT8 PyArray_UINT\n\ttypedef int Int8;\n\ttypedef unsigned int UInt8;\n#endif\n#define STRBITSOF_INT \"8\"\n#elif BITSOF_INT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_INT\n#define PyArray_UINT16 PyArray_UINT\n\ttypedef int Int16;\n\ttypedef unsigned int UInt16;\n#endif\n#define STRBITSOF_INT \"16\"\n#elif BITSOF_INT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_INT\n#define PyArray_UINT32 PyArray_UINT\n\ttypedef int Int32;\n\ttypedef unsigned int UInt32;\n\ttypedef unsigned int PyArray_UCS4;\n#endif\n#define STRBITSOF_INT \"32\"\n#elif BITSOF_INT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_INT\n#define PyArray_UINT64 PyArray_UINT\n\ttypedef int Int64;\n\ttypedef unsigned int UInt64;\n#endif\n#define STRBITSOF_INT \"64\"\n#elif BITSOF_INT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_INT\n#define PyArray_UINT128 PyArray_UINT\n\ttypedef int Int128;\n\ttypedef unsigned int UInt128;\n#endif\n#define STRBITSOF_INT \"128\"\n#endif\n\n#if BITSOF_SHORT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_SHORT\n#define PyArray_UINT8 PyArray_USHORT\n\ttypedef short Int8;\n\ttypedef unsigned short UInt8;\n#endif\n#define STRBITSOF_SHORT \"8\"\n#elif BITSOF_SHORT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_SHORT\n#define PyArray_UINT16 PyArray_USHORT\n\ttypedef short Int16;\n\ttypedef unsigned short UInt16;\n#endif\n#define STRBITSOF_SHORT \"16\"\n#elif BITSOF_SHORT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_SHORT\n#define PyArray_UINT32 PyArray_USHORT\n\ttypedef short Int32;\n\ttypedef unsigned short UInt32;\n\ttypedef unsigned short PyArray_UCS4;\n#endif\n#define STRBITSOF_SHORT \"32\"\n#elif BITSOF_SHORT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_SHORT\n#define PyArray_UINT64 PyArray_USHORT\n\ttypedef short Int64;\n\ttypedef unsigned short UInt64;\n#endif\n#define STRBITSOF_SHORT \"64\"\n#elif BITSOF_SHORT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_SHORT\n#define PyArray_UINT128 PyArray_USHORT\n\ttypedef short Int128;\n\ttypedef unsigned short UInt128;\n#endif\n#define STRBITSOF_SHORT \"128\"\n#endif\n\n\n#if BITSOF_CHAR == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_BYTE\n#define PyArray_UINT8 PyArray_UBYTE\n\ttypedef signed char Int8;\n\ttypedef unsigned char UInt8;\n#endif\n#define STRBITSOF_CHAR \"8\"\n#elif BITSOF_CHAR == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_BYTE\n#define PyArray_UINT16 PyArray_UBYTE\n\ttypedef signed char Int16;\n\ttypedef unsigned char UInt16;\n#endif\n#define STRBITSOF_CHAR \"16\"\n#elif BITSOF_CHAR == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_BYTE\n#define PyArray_UINT32 PyArray_UBYTE\n\ttypedef signed char Int32;\n\ttypedef unsigned char UInt32;\n\ttypedef unsigned char PyArray_UCS4;\n#endif\n#define STRBITSOF_CHAR \"32\"\n#elif BITSOF_CHAR == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_BYTE\n#define PyArray_UINT64 PyArray_UBYTE\n\ttypedef signed char Int64;\n\ttypedef unsigned char UInt64;\n#endif\n#define STRBITSOF_CHAR \"64\"\n#elif BITSOF_CHAR == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_BYTE\n#define PyArray_UINT128 PyArray_UBYTE\n\ttypedef signed char Int128;\n\ttypedef unsigned char UInt128;\n#endif\n#define STRBITSOF_CHAR \"128\"\n#endif\n\n\n\n#if BITSOF_DOUBLE == 16\n#define STRBITSOF_DOUBLE \"16\"\n#define STRBITSOF_CDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_DOUBLE\n#define PyArray_COMPLEX32 PyArray_CDOUBLE\n\ttypedef double Float16;\n\ttypedef cdouble Complex32;\n#endif\n#elif BITSOF_DOUBLE == 32\n#define STRBITSOF_DOUBLE \"32\"\n#define STRBITSOF_CDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_DOUBLE\n#define PyArray_COMPLEX64 PyArray_CDOUBLE\n\ttypedef double Float32;\n\ttypedef cdouble Complex64;\n#endif\n#elif BITSOF_DOUBLE == 64\n#define STRBITSOF_DOUBLE \"64\"\n#define STRBITSOF_CDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_DOUBLE\n#define PyArray_COMPLEX128 PyArray_CDOUBLE\n\ttypedef double Float64;\n\ttypedef cdouble Complex128;\n#endif\n#elif BITSOF_DOUBLE == 80\n#define STRBITSOF_DOUBLE \"80\"\n#define STRBITSOF_CDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_DOUBLE\n#define PyArray_COMPLEX160 PyArray_CDOUBLE\n\ttypedef double Float80;\n\ttypedef cdouble Complex160;\n#endif\n#elif BITSOF_DOUBLE == 96\n#define STRBITSOF_DOUBLE \"96\"\n#define STRBITSOF_CDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_DOUBLE\n#define PyArray_COMPLEX192 PyArray_CDOUBLE\n\ttypedef double Float96;\n\ttypedef cdouble Complex192;\n#endif\n#elif BITSOF_DOUBLE == 128\n#define STRBITSOF_DOUBLE \"128\"\n#define STRBITSOF_CDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_DOUBLE\n#define PyArray_COMPLEX256 PyArray_CDOUBLE\n\ttypedef double Float128;\n\ttypedef cdouble Complex256;\n#endif\n#endif\n\n\n\n#if BITSOF_FLOAT == 16\n#define STRBITSOF_FLOAT \"16\"\n#define STRBITSOF_CFLOAT \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_FLOAT\n#define PyArray_COMPLEX32 PyArray_CFLOAT\n\ttypedef float Float16;\n\ttypedef cfloat Complex32;\n#endif\n#elif BITSOF_FLOAT == 32\n#define STRBITSOF_FLOAT \"32\"\n#define STRBITSOF_CFLOAT \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_FLOAT\n#define PyArray_COMPLEX64 PyArray_CFLOAT\n\ttypedef float Float32;\n\ttypedef cfloat Complex64;\n#endif\n#elif BITSOF_FLOAT == 64\n#define STRBITSOF_FLOAT \"64\"\n#define STRBITSOF_CFLOAT \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_FLOAT\n#define PyArray_COMPLEX128 PyArray_CFLOAT\n\ttypedef float Float64;\n\ttypedef cfloat Complex128;\n#endif\n#elif BITSOF_FLOAT == 80\n#define STRBITSOF_FLOAT \"80\"\n#define STRBITSOF_CFLOAT \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_FLOAT\n#define PyArray_COMPLEX160 PyArray_CFLOAT\n\ttypedef float Float80;\n\ttypedef cfloat Complex160;\n#endif\n#elif BITSOF_FLOAT == 96\n#define STRBITSOF_FLOAT \"96\"\n#define STRBITSOF_CFLOAT \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_FLOAT\n#define PyArray_COMPLEX192 PyArray_CFLOAT\n\ttypedef float Float96;\n\ttypedef cfloat Complex192;\n#endif\n#elif BITSOF_FLOAT == 128\n#define STRBITSOF_FLOAT \"128\"\n#define STRBITSOF_CFLOAT \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_FLOAT\n#define PyArray_COMPLEX256 PyArray_CFLOAT\n\ttypedef float Float128;\n\ttypedef cfloat Complex256;\n#endif\n#endif\n\n\n#if BITSOF_LONGDOUBLE == 16\n#define STRBITSOF_LONGDOUBLE \"16\"\n#define STRBITSOF_CLONGDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX32 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float16;\n\ttypedef clongdouble Complex32;\n#endif\n#elif BITSOF_LONGDOUBLE == 32\n#define STRBITSOF_LONGDOUBLE \"32\"\n#define STRBITSOF_CLONGDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX64 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float32;\n\ttypedef clongdouble Complex64;\n#endif\n#elif BITSOF_LONGDOUBLE == 64\n#define STRBITSOF_LONGDOUBLE \"64\"\n#define STRBITSOF_CLONGDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX128 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float64;\n\ttypedef clongdouble Complex128;\n#endif\n#elif BITSOF_LONGDOUBLE == 80\n#define STRBITSOF_LONGDOUBLE \"80\"\n#define STRBITSOF_CLONGDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX160 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float80;\n\ttypedef clongdouble Complex160;\n#endif\n#elif BITSOF_LONGDOUBLE == 96\n#define STRBITSOF_LONGDOUBLE \"96\"\n#define STRBITSOF_CLONGDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX192 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float96;\n\ttypedef clongdouble Complex192;\n#endif\n#elif BITSOF_LONGDOUBLE == 128\n#define STRBITSOF_LONGDOUBLE \"128\"\n#define STRBITSOF_CLONGDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX256 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float128;\n\ttypedef clongdouble Complex256;\n#endif\n#elif BITSOF_LONGDOUBLE == 256\n#define STRBITSOF_LONGDOUBLE \"256\"\n#define STRBITSOF_CLONGDOUBLE \"512\"\n#define PyArray_FLOAT256 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX512 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float256;\n\ttypedef clongdouble Complex512;\n#endif\n\n\t/* End of typedefs for numarray style bit-width names */\n\n/* This is to typedef Intp to the appropriate pointer size for this platform.\n * Py_intptr_t, Py_uintptr_t are defined in pyport.h. */\ntypedef Py_intptr_t intp;\ntypedef Py_uintptr_t uintp;\n#define SIZEOF_INTP SIZEOF_PY_INTPTR_T\n#define SIZEOF_UINTP SIZEOF_PY_INTPTR_T\n\n#if PY_VERSION_HEX >= 0x02050000\n#define _int_or_ssize_t Py_ssize_t\n#else\n#define _int_or_ssize_t int\n#endif\n\n#define INTP_FMT \"d\"\n\n#if SIZEOF_PY_INTPTR_T == SIZEOF_INT\n\t#define PyArray_INTP PyArray_INT\n\t#define PyArray_UINTP PyArray_UINT\n #define PyIntpArrType_Type PyIntArrType_Type\n #define PyUIntpArrType_Type PyUIntArrType_Type\n\t#define MAX_INTP MAX_INT\n\t#define MIN_INTP MIN_INT\n\t#define MAX_UINTP MAX_UINT\n#elif SIZEOF_PY_INTPTR_T == SIZEOF_LONG\n\t#define PyArray_INTP PyArray_LONG\n\t#define PyArray_UINTP PyArray_ULONG\n #define PyIntpArrType_Type PyLongArrType_Type\n #define PyUIntpArrType_Type PyULongArrType_Type\n\t#define MAX_INTP MAX_LONG\n\t#define MIN_INTP MIN_LONG\n\t#define MAX_UINTP MAX_ULONG\n #undef INTP_FMT\n #define INTP_FMT \"ld\"\n#elif defined(PY_LONG_LONG) && (SIZEOF_PY_INTPTR_T == SIZEOF_LONG_LONG)\n\t#define PyArray_INTP PyArray_LONGLONG\n\t#define PyArray_UINTP PyArray_ULONGLONG\n #define PyIntpArrType_Type PyLongLongArrType_Type\n #define PyUIntpArrType_Type PyULongLongArrType_Type\n\t#define MAX_INTP MAX_LONGLONG\n\t#define MIN_INTP MIN_LONGLONG\n\t#define MAX_UINTP MAX_ULONGLONG\n #undef INTP_FMT\n #define INTP_FMT \"Ld\"\n#endif\n\n#define ERR(str) fprintf(stderr, #str); fflush(stderr);\n#define ERR2(str) fprintf(stderr, str); fflush(stderr);\n\n /* Macros to define how array, and dimension/strides data is\n allocated.\n */\n\n /* Data buffer */\n#define PyDataMem_NEW(size) ((char *)malloc(size))\n /* #define PyArrayMem_NEW(size) PyMem_NEW(char, size)*/\n#define PyDataMem_FREE(ptr) free(ptr)\n /* #define PyArrayMem_FREE(ptr) PyMem_Free(ptr) */\n#define PyDataMem_RENEW(ptr,size) ((char *)realloc(ptr,size))\n\n#define PyArray_USE_PYMEM 0\n\n#if PyArray_USE_PYMEM == 1\n#define _pya_malloc PyObject_Malloc\n#define _pya_free PyObject_Free\n#define _pya_realloc PyObject_Realloc\n#else\n#define _pya_malloc malloc\n#define _pya_free free\n#define _pya_realloc realloc\n#endif\n\n/* Dimensions and strides */\n#define PyDimMem_NEW(size) ((intp *)_pya_malloc(size*sizeof(intp)))\n#define PyDimMem_FREE(ptr) _pya_free(ptr)\n#define PyDimMem_RENEW(ptr,size) ((intp *)_pya_realloc(ptr,size*sizeof(intp)))\n\n\n /* These must deal with unaligned and swapped data if necessary */\ntypedef PyObject * (PyArray_GetItemFunc) (void *, void *);\ntypedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);\n\ntypedef void (PyArray_CopySwapNFunc)(void *, void *, intp, int, int);\ntypedef void (PyArray_CopySwapFunc)(void *, void *, int, int);\ntypedef Bool (PyArray_NonzeroFunc)(void *, void *);\n\n\n /* These assume aligned and notswapped data -- a buffer will be\n used before or contiguous data will be obtained\n */\ntypedef int (PyArray_CompareFunc)(const void *, const void *, void *);\ntypedef int (PyArray_ArgFunc)(void*, intp, intp*, void *);\ntypedef void (PyArray_DotFunc)(void *, intp, void *, intp, void *, intp,\n\t\t\t void *);\ntypedef void (PyArray_VectorUnaryFunc)(void *, void *, intp, void *, void *);\ntypedef int (PyArray_ScanFunc)(FILE *, void *, void *, void *);\ntypedef int (PyArray_FromStrFunc)(char *, void *, char **, void *);\n\ntypedef int (PyArray_FillFunc)(void *, intp, void *);\n\ntypedef int (PyArray_SortFunc)(void *, intp, void *);\ntypedef int (PyArray_ArgSortFunc)(void *, intp *, intp, void *);\n\ntypedef int (PyArray_FillWithScalarFunc)(void *, intp, void *, void *);\n\ntypedef struct {\n intp *ptr;\n int len;\n} PyArray_Dims;\n\ntypedef struct {\n\t/* Functions to cast to all other standard types*/\n\tPyArray_VectorUnaryFunc *cast[PyArray_NTYPES];\n\n\t/* Functions to get and set items with standard\n\t Python types -- not array scalars */\n\tPyArray_GetItemFunc *getitem;\n\tPyArray_SetItemFunc *setitem;\n\n\t/* Copy and/or swap data. Memory areas may not overlap */\n\t/* Use memmove first if they might */\n\tPyArray_CopySwapNFunc *copyswapn;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Function to compare items */\n\tPyArray_CompareFunc *compare;\n\n\t/* Function to select largest */\n\tPyArray_ArgFunc *argmax;\n\n\t/* Function to compute dot product */\n\tPyArray_DotFunc\t*dotfunc;\n\n\t/* Function to scan an ASCII file and\n\t place a single value plus possible separator */\n\tPyArray_ScanFunc *scanfunc;\n\n\t/* Function to read a single value from a string */\n\t/* and adjust the pointer */\n\tPyArray_FromStrFunc *fromstr;\n\n\t/* Function to determine if data is zero or not */\n\tPyArray_NonzeroFunc *nonzero;\n\n\t/* Used for arange */\n\tPyArray_FillFunc *fill;\n\n\t/* Function to fill arrays with scalar values */\n\tPyArray_FillWithScalarFunc *fillwithscalar;\n\n\t/* Sorting functions */\n\tPyArray_SortFunc *sort[PyArray_NSORTS];\n\tPyArray_ArgSortFunc *argsort[PyArray_NSORTS];\n\n} PyArray_ArrFuncs;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tPyTypeObject *typeobj; /* the type object representing an\n\t\t\t\t intance of this type */\n\tchar kind; /* kind for this type */\n\tchar type; /* unique-character representing this type */\n\tchar byteorder; /* '>' (big), '<' (little), '|'\n\t\t\t\t (not-applicable), or '=' (native). */\n char hasobject; /* non-zero if it has object arrays in fields */\n\tint type_num; /* number representing this type */\n\tint elsize; /* element size for this type */\n\tint alignment; /* alignment needed for this type */\n\tstruct _arr_descr\t\t\t\t\t\\\n\t*subarray; /* Non-NULL if this type is\n\t\t\t\t is an array (C-contiguous)\n\t\t\t\t of some other type\n\t\t\t\t*/\n\tPyObject *fields; /* The fields dictionary for this type */\n\t /* For statically defined descr this\n\t\t\t\t is always Py_None */\n\n\tPyArray_ArrFuncs *f; /* a table of functions specific for each\n\t\t\t\t basic data descriptor */\n} PyArray_Descr;\n\ntypedef struct _arr_descr {\n\tPyArray_Descr *base;\n\tPyObject *shape; /* a tuple */\n} PyArray_ArrayDescr;\n\n\n/*\n The main array object structure. It is recommended to use the macros\n defined below (PyArray_DATA and friends) access fields here, instead\n of the members themselves.\n */\n\ntypedef struct PyArrayObject {\n\tPyObject_HEAD\n\tchar *data; /* pointer to raw data buffer */\n\tint nd; /* number of dimensions, also called ndim */\n\tintp *dimensions; /* size in each dimension */\n intp *strides; /* bytes to jump to get to the\n\t\t\t\t next element in each dimension */\n\tPyObject *base; /* This object should be decref'd\n\t\t\t\t upon deletion of array */\n\t /* For views it points to the original array */\n\t /* For creation from buffer object it points\n\t\t\t\t to an object that shold be decref'd on\n\t\t\t\t deletion */\n\t /* For UPDATEIFCOPY flag this is an array\n\t\t\t\t to-be-updated upon deletion of this one */\n\tPyArray_Descr *descr; /* Pointer to type structure */\n\tint flags; /* Flags describing array -- see below*/\n\tPyObject *weakreflist; /* For weakreferences */\n} PyArrayObject;\n\n\n#define fortran fortran_ /* For some compilers */\n\n/* Mirrors buffer object to ptr */\n\ntypedef struct {\n PyObject_HEAD\n PyObject *base;\n void *ptr;\n intp len;\n int flags;\n} PyArray_Chunk;\n\n/* Array flags */\n\n/* Means c-style contiguous (last index varies the fastest). The\n data elements right after each other. */\n#define CONTIGUOUS 0x0001\n/* set if array is a contiguous Fortran array: the first index\n varies the fastest in memory (strides array is reverse of\n C-contiguous array)*/\n#define FORTRAN 0x0002\n\n/*\n Note: all 0-d arrays are CONTIGUOUS and FORTRAN contiguous. If a\n 1-d array is CONTIGUOUS it is also FORTRAN contiguous\n*/\n\n/* If set, the array owns the data: it will be free'd when the array\n is deleted. */\n#define OWNDATA 0x0004\n#define OWN_DATA OWNDATA\n\n/* An array never has these three set; they're only used as parameter\n flags to the the various FromAny functions */\n/* Cause a cast to occur regardless of whether or not it is safe. */\n#define FORCECAST 0x0010\n/* Always copy the array. Returned arrays are always CONTIGUOUS, ALIGNED,\n and WRITEABLE. */\n#define ENSURECOPY 0x0020\n/* Make sure the returned array is an ndarray or a bigndarray */\n#define ENSUREARRAY 0x0040\n\n/* Array data is aligned on the appropiate memory address for the\n type stored (e.g., an array of doubles (8 bytes each) starts on\n a memory address that's a multiple of 8) */\n#define ALIGNED 0x0100\n/* Array data has the native endianness */\n#define NOTSWAPPED 0x0200\n/* Array data is writeable */\n#define WRITEABLE 0x0400\n/* If this flag is set, then base contains a pointer to an array of\n the same size that should be updated with the current contents of\n this array when this array is deallocated\n*/\n#define UPDATEIFCOPY 0x1000\n\n\n#define BEHAVED_FLAGS ALIGNED | WRITEABLE\n#define BEHAVED_NS_FLAGS ALIGNED | WRITEABLE | NOTSWAPPED\n#define CARRAY_FLAGS CONTIGUOUS | BEHAVED_FLAGS\n#define CARRAY_FLAGS_RO CONTIGUOUS | ALIGNED\n#define FARRAY_FLAGS FORTRAN | BEHAVED_FLAGS\n#define FARRAY_FLAGS_RO FORTRAN | ALIGNED\n#define DEFAULT_FLAGS CARRAY_FLAGS\n\n#define UPDATE_ALL_FLAGS CONTIGUOUS | FORTRAN | ALIGNED\n\n\n/* Size of internal buffers used for alignment */\n#define PyArray_BUFSIZE 10000\n#define PyArray_MIN_BUFSIZE 5\n#define PyArray_MAX_BUFSIZE 100000000\n\n/*\n * C API: consists of Macros and functions. The MACROS are defined here.\n */\n\n\n#define PyArray_CHKFLAGS(m, FLAGS) \\\n\t((((PyArrayObject *)(m))->flags & (FLAGS)) == (FLAGS))\n#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, CONTIGUOUS)\n#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, WRITEABLE)\n#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, ALIGNED)\n\n#ifndef MAX\n#define MAX(a,b) (((a)>(b))?(a):(b))\n#endif\n#ifndef MIN\n#define MIN(a,b) (((a)<(b))?(a):(b))\n#endif\n\n/* Useful if a and b have to be evaluated. */\n\n#define tMAX(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_>_y_ ? _x_ : _y_}\n#define tMIN(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_<_y_ ? _x_ : _y_}\n\n#if defined(ALLOW_THREADS)\n#define BEGIN_THREADS_DEF PyThreadState *_save;\n#define BEGIN_THREADS _save = PyEval_SaveThread();\n#define END_THREADS PyEval_RestoreThread(_save);\n#define ALLOW_C_API_DEF PyGILState_STATE __save__;\n#define ALLOW_C_API __save__ = PyGILState_Ensure();\n#define DISABLE_C_API PyGILState_Release(__save__);\n#else\n#define BEGIN_THREADS_DEF\n#define BEGIN_THREADS\n#define END_THREADS\n#define ALLOW_C_API_DEF\n#define\tALLOW_C_API\n#define\tDISABLE_C_API\n#endif\n\n\n\n\ntypedef struct {\n PyObject_HEAD\n\tint nd_m1; /* number of dimensions - 1 */\n intp\t\t index, size;\n\tintp coordinates[MAX_DIMS];/* N-dimensional loop */\n intp dims_m1[MAX_DIMS]; /* ao->dimensions - 1 */\n\tintp strides[MAX_DIMS]; /* ao->strides or fake */\n\tintp backstrides[MAX_DIMS];/* how far to jump back */\n\tintp factors[MAX_DIMS]; /* shape factors */\n\tPyArrayObject *ao;\n\tchar *dataptr; /* pointer to current item*/\n Bool contiguous;\n} PyArrayIterObject;\n\n\n/* Iterator API */\n#define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type)\n\n#define PyArray_ITER_RESET(it) {\t\t\t\t\t\\\n\tit->index = 0;\t\t\t\t\t\t \\\n\tit->dataptr = it->ao->data;\t\t\t\t\t\\\n\tmemset(it->coordinates, 0, (it->nd_m1+1)*sizeof(intp));\t\t\\\n}\n\n#define _PyArray_ITER_NEXT1(it) {\t\t\\\n\t\tit->dataptr += it->strides[0];\t\\\n\t\tit->coordinates[0]++;\t\t\\\n\t}\n\n#define _PyArray_ITER_NEXT2(it) {\t\t\t\t\t\\\n\t\tif (it->coordinates[1] < it->dims_m1[1]) {\t\t\\\n\t\t\tit->coordinates[1]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->coordinates[1] = 0;\t\t\t\t\\\n\t\t\tit->coordinates[0]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[0] -\t\t\t\\\n\t\t\t\tit->backstrides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_NEXT(it) {\t\t\t\t\t\t\\\n\tit->index++;\t\t\t\t\t\t \\\n if (it->nd_m1 == 0) {\t\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT1(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse if (it->contiguous) it->dataptr += it->ao->descr->elsize; \\\n\telse if (it->nd_m1 == 1) {\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT2(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse {\t\t\t\t\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_ >= 0; _i_--) {\t\t\\\n\t\t\tif (it->coordinates[_i_] <\t\t\t\\\n\t\t\t it->dims_m1[_i_]) {\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_]++;\t\t\t\\\n\t\t\t\tit->dataptr += it->strides[_i_];\t\\\n\t\t\t\tbreak;\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t\telse {\t\t\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_] = 0;\t\t\\\n\t\t\t\tit->dataptr -= it->backstrides[_i_];\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_GOTO(it, destination) {\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tit->index = 0;\t\t\t\t\t\t\\\n\t\tit->dataptr = it->ao->data;\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_>=0; _i_--) {\t\t\t\\\n\t\t\tit->dataptr += destination[_i_] *\t\t\\\n\t\t\t\tit->strides[_i_];\t\t\t\\\n\t\t\tit->coordinates[_i_] = destination[_i_];\t\\\n\t\t\tit->index += destination[_i_] *\t\t\t\\\n\t\t\t\t( _i_==it->nd_m1 ? 1 :\t\t\t\\\n\t\t\t\t it->dims_m1[i+1]+1) ;\t\t \\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_GOTO1D(it, ind) { \\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tintp _lind_ = (intp) (ind);\t\t\t\t\\\n\t\tit->index = _lind_;\t\t\t\t\t\\\n if (it->nd_m1 == 0) { \\\n it->dataptr = it->ao->data + (ind) * \\\n it->strides[0]; \\\n } \\\n else if (it->contiguous) \\\n\t\t\tit->dataptr = it->ao->data + (ind) *\t\t\\\n\t\t\t\tit->ao->descr->elsize;\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->dataptr = it->ao->data;\t\t\t\\\n\t\t\tfor (_i_ = 0; _i_<=it->nd_m1; _i_++) {\t\t\\\n\t\t\t\tit->dataptr += (_lind_ / it->factors[_i_]) \\\n\t\t\t\t\t* it->strides[_i_];\t\t\\\n\t\t\t\t_lind_ %= it->factors[_i_];\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_DATA(it) ((PyArrayIterObject *)it)->dataptr\n\n\n/*\n Any object passed to PyArray_Broadcast must be binary compatible with\n this structure.\n*/\n\ntypedef struct {\n\tPyObject_HEAD\n\n\tint numiter; /* number of iters */\n\tintp size; /* broadcasted size */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* iterators */\n} PyArrayMultiIterObject;\n\n#define PyArray_MultiIter_RESET(multi) {\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index = 0;\t\t\t\t \\\n\t\tfor (_mi_ = 0; _mi_ < _mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_RESET(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_NEXT(multi) {\t\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index += 1;\t\t\t\t \\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_NEXT(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_GOTO(multi, dest) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO(_mul_->iters[_mi_], dest);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_GOTO1D(multi, ind) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO1D(_mul_->iters[_mi_], ind);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_DATA(multi, i) \\\n\t((PyArrayMultiIterObject *)multi)->iters[i]->dataptr\n\n#define PyArray_MultiIter_SIZE(multi) \\\n\t((PyArrayMultiIterObject *)multi)->size;\n\n\n/* Store the information needed for fancy-indexing over an array */\n\ntypedef struct {\n\tPyObject_HEAD\n\t/* Multi-iterator portion --- needs to be present in this order to\n\t work with PyArray_Broadcast */\n\n\tint numiter; /* number of index-array\n\t\t\t\t\t\t\t iterators */\n\tintp size; /* size of broadcasted\n\t\t\t\t\t\t\t result */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* index object\n\t\t\t\t\t\t\t iterators */\n\tPyArrayIterObject *ait; /* flat Iterator for\n\t\t\t\t\t\t\t underlying array */\n\n\t/* flat iterator for subspace (when numiter < nd) */\n\tPyArrayIterObject *subspace;\n\n\t/* if subspace iteration, then this is the array of\n\t axes in the underlying array represented by the\n\t index objects */\n\tint iteraxes[MAX_DIMS];\n\t/* if subspace iteration, the these are the coordinates\n\t to the start of the subspace.\n\t*/\n\tintp bscoord[MAX_DIMS];\n\n\tPyObject *indexobj; /* reference to\n\t\t\t\t\t\t\t creating obj */\n\tint view;\n\tint consec;\n\tchar *dataptr;\n\n} PyArrayMapIterObject;\n\n/* All sorts of useful ways to look into a PyArrayObject.\n These are the recommended over casting to PyArrayObject and accessing\n the members directly.\n */\n\n#define PyArray_NDIM(obj) (((PyArrayObject *)(obj))->nd)\n#define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || PyArray_CHKFLAGS(m, CONTIGUOUS) || \\\n\t\t\t\t PyArray_CHKFLAGS(m, FORTRAN))\n#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, FORTRAN) && (PyArray_NDIM(m) > 1))\n#define FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, FORTRAN) ? FORTRAN : 0))\n#define PyArray_DATA(obj) ((void *)(((PyArrayObject *)(obj))->data))\n#define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data)\n#define PyArray_DIMS(obj) (((PyArrayObject *)(obj))->dimensions)\n#define PyArray_STRIDES(obj) (((PyArrayObject *)(obj))->strides)\n#define PyArray_DIM(obj,n) (((PyArrayObject *)(obj))->dimensions[n])\n#define PyArray_STRIDE(obj,n) (((PyArrayObject *)(obj))->strides[n])\n#define PyArray_BASE(obj) (((PyArrayObject *)(obj))->base)\n#define PyArray_DESCR(obj) (((PyArrayObject *)(obj))->descr)\n#define PyArray_FLAGS(obj) (((PyArrayObject *)(obj))->flags)\n#define PyArray_ITEMSIZE(obj) (((PyArrayObject *)(obj))->descr->elsize)\n#define PyArray_TYPE(obj) (((PyArrayObject *)(obj))->descr->type_num)\n#define PyArray_GETITEM(obj,itemptr)\t\t\t\\\n\t((PyArrayObject *)(obj))->descr->f->getitem((char *)itemptr,\t\\\n\t\t\t\t\t\t (PyArrayObject *)obj);\n#define PyArray_SETITEM(obj,itemptr,v)\t\t\t\t\t\\\n\t(obj)->descr->f->setitem((PyObject *)v,(char *)(itemptr),\t\t\\\n\t\t\t (PyArrayObject *)(obj));\n\n\n#define PyTypeNum_ISBOOL(type) (type == PyArray_BOOL)\n#define PyTypeNum_ISUNSIGNED(type) ((type == PyArray_UBYTE) || \\\n\t\t\t\t (type == PyArray_USHORT) || \\\n\t\t\t\t (type == PyArray_UINT) ||\t\\\n\t\t\t\t (type == PyArray_ULONG) || \\\n\t\t\t\t (type == PyArray_ULONGLONG))\n\n#define PyTypeNum_ISSIGNED(type) ((type == PyArray_BYTE) ||\t\\\n\t\t\t (type == PyArray_SHORT) ||\t\\\n\t\t\t (type == PyArray_INT) ||\t\\\n\t\t\t (type == PyArray_LONG) ||\t\\\n\t\t\t (type == PyArray_LONGLONG))\n\n#define PyTypeNum_ISINTEGER(type) ((type >= PyArray_BYTE) &&\t\\\n\t\t\t\t(type <= PyArray_ULONGLONG))\n\n#define PyTypeNum_ISFLOAT(type) ((type >= PyArray_FLOAT) && \\\n\t\t\t (type <= PyArray_LONGDOUBLE))\n\n#define PyTypeNum_ISNUMBER(type) (type <= PyArray_CLONGDOUBLE)\n\n#define PyTypeNum_ISSTRING(type) ((type == PyArray_UCHAR) || \\\n\t\t\t (type == PyArray_UNICODE))\n\n#define PyTypeNum_ISCOMPLEX(type) ((type >= PyArray_CFLOAT) && \\\n\t\t\t\t(type <= PyArray_CLONGDOUBLE))\n\n#define PyTypeNum_ISPYTHON(type) ((type == PyArray_LONG) || \\\n\t\t\t\t (type == PyArray_DOUBLE) ||\t\\\n\t\t\t\t (type == PyArray_CDOUBLE) ||\t\\\n\t\t (type == PyArray_BOOL) || \\\n\t\t\t\t (type == PyArray_OBJECT ))\n\n#define PyTypeNum_ISFLEXIBLE(type) ((type>=PyArray_STRING) && \\\n\t\t\t\t (type<=PyArray_VOID))\n\n#define PyTypeNum_ISUSERDEF(type) ((type >= PyArray_USERDEF) && \\\n\t\t\t\t (type < PyArray_USERDEF+\\\n\t\t\t\t PyArray_NUMUSERTYPES))\n\n#define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \\\n PyTypeNum_ISUSERDEF(type))\n\n#define PyTypeNum_ISOBJECT(type) ((type) == PyArray_OBJECT)\n\n#define _PyADt(o) ((PyArray_Descr *)o)->type_num\n#define PyDescr_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj))\n#define PyDescr_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(_PyADt(obj))\n#define PyDescr_ISSIGNED(obj) PyTypeNum_ISSIGNED(_PyADt(obj))\n#define PyDescr_ISINTEGER(obj) PyTypeNum_ISINTEGER(_PyADt(obj))\n#define PyDescr_ISFLOAT(obj) PyTypeNum_ISFLOAT(_PyADt(obj))\n#define PyDescr_ISNUMBER(obj) PyTypeNum_ISNUMBER(_PyADt(obj))\n#define PyDescr_ISSTRING(obj) PyTypeNum_ISSTRING(_PyADt(obj))\n#define PyDescr_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(_PyADt(obj))\n#define PyDescr_ISPYTHON(obj) PyTypeNum_ISPYTHON(_PyADt(obj))\n#define PyDescr_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(_PyADt(obj))\n#define PyDescr_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(_PyADt(obj))\n#define PyDescr_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(_PyADt(obj))\n#define PyDescr_ISOBJECT(obj) PyTypeNum_ISOBJECT(_PyADt(obj))\n#undef _PyAD\n\n#define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))\n#define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))\n#define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))\n#define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))\n#define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))\n#define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))\n#define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj))\n#define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))\n#define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))\n#define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))\n#define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))\n\n#define PyArray_LITTLE '<'\n#define PyArray_BIG '>'\n#define PyArray_NATIVE '='\n#define PyArray_SWAP 's'\n#define PyArray_IGNORE '|'\n\n#ifdef WORDS_BIGENDIAN\n#define PyArray_NATBYTE PyArray_BIG\n#define PyArray_OPPBYTE PyArray_LITTLE\n#else\n#define PyArray_NATBYTE PyArray_LITTLE\n#define PyArray_OPPBYTE PyArray_BIG\n#endif\n\n#define PyArray_ISNBO(arg) ((arg) != PyArray_OPPBYTE)\n#define PyArray_IsNativeByteOrder PyArray_ISNBO\n#define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)\n\n#define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) &&\t\\\n\t\t\t\t PyArray_ISNOTSWAPPED(m))\n#define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS)\n#define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS_RO)\n#define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS)\n#define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS_RO)\n#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, BEHAVED_FLAGS)\n#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, ALIGNED)\n\n\n\n/* This is the form of the struct that's returned pointed by the\n PyCObject attribute of an array __array_struct__. See\n http://numeric.scipy.org/array_interface.html for the full\n documentation. */\ntypedef struct {\n int version; /* contains the integer 2 as a sanity check */\n int nd; /* number of dimensions */\n char typekind; /* kind in array --- character code of typestr */\n int itemsize; /* size of each element */\n int flags; /* how should be data interpreted. Valid\n flags are CONTIGUOUS (1), FORTRAN (2),\n ALIGNED (0x100), NOTSWAPPED (0x200), and\n WRITEABLE (0x400)*/\n intp *shape; /* A length-nd array of shape information */\n intp *strides; /* A length-nd array of stride information */\n void *data; /* A pointer to the first element of the array */\n} PyArrayInterface;\n\n/* Includes the \"function\" C-API -- these are all stored in a\n list of pointers --- one for each file\n The two lists are concatenated into one in multiarray.\n\n They are available as import_array()\n*/\n\n\n#include \"__multiarray_api.h\"\n\n\n/* C-API that requries previous API to be defined */\n\n#define PyArray_DescrCheck(op) ((op)->ob_type == &PyArrayDescr_Type)\n\n#define PyArray_Check(op) ((op)->ob_type == &PyArray_Type ||\t\t\\\n\t\t\t PyObject_TypeCheck((op), &PyArray_Type))\n#define PyArray_CheckExact(op) ((op)->ob_type == &PyArray_Type)\n\n#define PyArray_IsZeroDim(op) (PyArray_Check(op) && (PyArray_NDIM(op) == 0))\n#define PyArray_IsScalar(obj, cls)\t\t\t\t\\\n\t(PyObject_TypeCheck((obj), &Py##cls##ArrType_Type))\n#define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \\\n PyArray_IsZeroDim(m))\n#define PyArray_IsPythonScalar(obj) \\\n\t(PyInt_Check(obj) || PyFloat_Check(obj) || PyComplex_Check(obj) || \\\n\t PyLong_Check(obj) || PyBool_Check(obj) || PyString_Check(obj) || \\\n\t PyUnicode_Check(obj))\n#define PyArray_IsAnyScalar(obj)\t\t\t\t\t\\\n\t(PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))\n#define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \\\n\t\t\t\t PyArray_CheckScalar(obj))\n\n#define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? Py_INCREF(m), m : \\\n (PyArrayObject *)(PyArray_Copy(m)))\n\n#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))\n#define PyArray_NBYTES(m) (PyArray_ITEMSIZE(m) * PyArray_SIZE(m))\n#define PyArray_FROM_O(m) PyArray_FromAny(m, NULL, 0, 0, 0, NULL)\n#define PyArray_FROM_OF(m,flags) PyArray_CheckFromAny(m, NULL, 0, 0, flags, NULL)\n#define PyArray_FROM_OT(m,type) PyArray_FromAny(m, PyArray_DescrFromType(type), \\\n 0, 0, 0, NULL);\n#define PyArray_FROM_OTF(m, type, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \\\n (((flags) & ENSURECOPY) ? \\\n ((flags) | DEFAULT_FLAGS) : (flags)), NULL)\n#define PyArray_FROMANY(m, type, min, max, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \\\n (((flags) & ENSURECOPY) ? \\\n (flags) | DEFAULT_FLAGS : (flags)), NULL)\n\n#define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), (val), PyArray_NBYTES(obj))\n\n#define REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)\n#define MAX_ELSIZE 2*SIZEOF_LONGDOUBLE\n\n#define PyArray_ContiguousFromAny(op, type, min_depth, max_depth) \\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, DEFAULT_FLAGS, NULL)\n\n#define PyArray_EquivArrTypes(a1, a2)\t\t\t\t\t\\\n\tPyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))\n#define PyArray_EquivTypenums(typenum1, typenum2)\t\t\\\n\tPyArray_EquivTypes(PyArray_DescrFromType(typenum1),\t\\\n\t\t\t PyArray_DescrFromType(typenum2))\n\n#define PyArray_EquivByteorders(b1, b2) \\\n\t((b1 == b2) || (PyArray_ISNBO(b1) == PyArray_ISNBO(b2)))\n\n#define PyArray_SimpleNew(nd, dims, typenum) \\\n\tPyArray_New(&PyArray_Type, nd, dims, typenum, NULL, NULL, 0, 0, NULL)\n#define PyArray_SimpleNewFromData(nd, dims, typenum, data) \\\n PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, data, 0, CARRAY_FLAGS, NULL)\n#define PyArray_SimpleNewFromDescr(nd, dims, descr) \\\n\tPyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, NULL, NULL, 0, NULL)\n#define PyArray_EnsureAnyArray(obj) \\\n\t(PyArray_Check(obj) ? obj : PyArray_EnsureArray(obj))\n\n\n/* These might be faster without the dereferencing of obj\n going on inside -- of course an optimizing compiler should\n inline the constants inside a for loop making it a moot point\n*/\n\n#define PyArray_GETPTR1(obj, i) (void *)(PyArray_BYTES(obj) +\t\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0))\n\n#define PyArray_GETPTR2(obj, i, j) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1))\n\n#define PyArray_GETPTR3(obj, i, j, k) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\\n\t\t\t\t\t k*PyArray_STRIDE(obj, 2)) \\\n\n#define PyArray_GETPTR4(obj, i, j, k, l) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\\n\t\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\\n\t\t\t\t\t\t k*PyArray_STRIDE(obj, 2) + \\\n\t\t\t\t\t\t l*PyArray_STRIDE(obj, 3))\n\n#define PyArray_DESCR_REPLACE(descr) do {\t\\\n\t\tPyArray_Descr *_new_;\t\t\t\\\n\t\t_new_ = PyArray_DescrNew(descr);\t\\\n\t\tPy_XDECREF(descr);\t\t\t\\\n\t\tdescr = _new_;\t\t\t\t\\\n\t} while(0)\n\n/* Copy should always return contiguous array */\n#define PyArray_Copy(obj) PyArray_NewCopy(obj, 0)\n\n#define PyArray_FromObject(op, type, min_depth, max_depth)\t\t\\\n\tPyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, BEHAVED_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_ContiguousFromObject(op, type, min_depth, max_depth)\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_CopyFromObject(op, type, min_depth, max_depth)\t\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, ENSURECOPY | DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_Cast(mp, type_num) \\\n\tPyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)\n\n/* Compatibility with old Numeric stuff -- don't use in new code */\n\n#define PyArray_FromDimsAndData(nd, d, type, data) \\\n\tPyArray_FromDimsAndDataAndDescr(nd, d, PyArray_DescrFromType(type), \\\n\t\t\t\t\tdata)\n\n#define PyArray_UNSIGNED_TYPES\n#define PyArray_SBYTE PyArray_BYTE\n#define PyArray_CHAR PyArray_BYTE\n#define PyArray_CopyArray PyArray_CopyInto\n#define _PyArray_multiply_list PyArray_MultiplyIntList\n#define PyArray_ISSPACESAVER(m) FALSE\n#define PyScalarArray_Check PyArray_CheckScalar\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# undef CAT\n# undef CAT2\n# undef NS\n# undef longlong\n# undef ulonglong\n# undef Bool\n# undef longdouble\n# undef byte\n# undef ubyte\n# undef ushort\n# undef uint\n# undef ulong\n# undef cfloat\n# undef cdouble\n# undef clongdouble\n# undef Int8\n# undef UInt8\n# undef Int16\n# undef UInt16\n# undef Int32\n# undef UInt32\n# undef Int64\n# undef UInt64\n# undef Int128\n# undef UInt128\n# undef Int256\n# undef UInt256\n# undef Float16\n# undef Complex32\n# undef Float32\n# undef Complex64\n# undef Float64\n# undef Complex128\n# undef Float80\n# undef Complex160\n# undef Float96\n# undef Complex192\n# undef Float128\n# undef Complex256\n# undef intp\n# undef uintp\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* !Py_ARRAYOBJECT_H */\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": 300, + "complexity": 0, + "token_count": 1410, + "diff_parsed": { + "added": [ + "#define NDARRAY_VERSION 0x00090702" + ], + "deleted": [ + "#define NDARRAY_VERSION 0x00090701" + ] + } + }, + { + "old_path": null, + "new_path": "numpy/core/include/numpy/arrayscalars.h", + "filename": "arrayscalars.h", + "extension": "h", + "change_type": "ADD", + "diff": "@@ -0,0 +1,139 @@\n+#ifndef _MULTIARRAYMODULE\n+typedef struct {\n+\tPyObject_HEAD\n+\tBool obval;\n+} PyBoolScalarObject;\n+#endif\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tsigned char obval;\n+} PyByteScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tshort obval;\n+} PyShortScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tint obval;\n+} PyIntScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tlong obval;\n+} PyLongScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tlonglong obval;\n+} PyLongLongScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tunsigned char obval;\n+} PyUByteScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tunsigned short obval;\n+} PyUShortScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tunsigned int obval;\n+} PyUIntScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tunsigned long obval;\n+} PyULongScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tulonglong obval;\n+} PyULongLongScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tfloat obval;\n+} PyFloatScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tdouble obval;\n+} PyDoubleScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tlongdouble obval;\n+} PyLongDoubleScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tcfloat obval;\n+} PyCFloatScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tcdouble obval;\n+} PyCDoubleScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tclongdouble obval;\n+} PyCLongDoubleScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tPyObject * obval;\n+} PyObjectScalarObject;\n+\n+\n+typedef struct {\n+\tPyObject_HEAD\n+\tchar obval;\n+} PyScalarObject;\n+\n+#define PyStringScalarObject PyStringObject\n+#define PyUnicodeScalarObject PyUnicodeObject\n+\n+typedef struct {\n+\tPyObject_VAR_HEAD\n+\tchar *obval;\n+\tPyArray_Descr *descr;\n+\tint flags;\n+\tPyObject *base;\n+} PyVoidScalarObject;\n+\n+/* to be exposed in C-API */\n+#define PyArrayScalar_False ((PyObject *)&_PyArrayScalar_BoolValues[0])\n+#define PyArrayScalar_True ((PyObject *)&_PyArrayScalar_BoolValues[1])\n+#define PyArrayScalar_RETURN_BOOL_FROM_LONG(i)\t\t\t\\\n+\treturn Py_INCREF(&_PyArrayScalar_BoolValues[((i)!=0)]),\t\\\n+\t\t(PyObject *)&_PyArrayScalar_BoolValues[((i)!=0)]\n+#define PyArrayScalar_RETURN_FALSE\t\t\\\n+\treturn Py_INCREF(PyArrayScalar_False),\t\\\n+\t\tPyArrayScalar_False\n+#define PyArrayScalar_RETURN_TRUE\t\t\\\n+\treturn Py_INCREF(PyArrayScalar_True),\t\\\n+\t\tPyArrayScalar_True\n+/* end to be exposed in C-API */\n", + "added_lines": 139, + "deleted_lines": 0, + "source_code": "#ifndef _MULTIARRAYMODULE\ntypedef struct {\n\tPyObject_HEAD\n\tBool obval;\n} PyBoolScalarObject;\n#endif\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tsigned char obval;\n} PyByteScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tshort obval;\n} PyShortScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tint obval;\n} PyIntScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tlong obval;\n} PyLongScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tlonglong obval;\n} PyLongLongScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tunsigned char obval;\n} PyUByteScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tunsigned short obval;\n} PyUShortScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tunsigned int obval;\n} PyUIntScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tunsigned long obval;\n} PyULongScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tulonglong obval;\n} PyULongLongScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tfloat obval;\n} PyFloatScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tdouble obval;\n} PyDoubleScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tlongdouble obval;\n} PyLongDoubleScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tcfloat obval;\n} PyCFloatScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tcdouble obval;\n} PyCDoubleScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tclongdouble obval;\n} PyCLongDoubleScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tPyObject * obval;\n} PyObjectScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tchar obval;\n} PyScalarObject;\n\n#define PyStringScalarObject PyStringObject\n#define PyUnicodeScalarObject PyUnicodeObject\n\ntypedef struct {\n\tPyObject_VAR_HEAD\n\tchar *obval;\n\tPyArray_Descr *descr;\n\tint flags;\n\tPyObject *base;\n} PyVoidScalarObject;\n\n/* to be exposed in C-API */\n#define PyArrayScalar_False ((PyObject *)&_PyArrayScalar_BoolValues[0])\n#define PyArrayScalar_True ((PyObject *)&_PyArrayScalar_BoolValues[1])\n#define PyArrayScalar_RETURN_BOOL_FROM_LONG(i)\t\t\t\\\n\treturn Py_INCREF(&_PyArrayScalar_BoolValues[((i)!=0)]),\t\\\n\t\t(PyObject *)&_PyArrayScalar_BoolValues[((i)!=0)]\n#define PyArrayScalar_RETURN_FALSE\t\t\\\n\treturn Py_INCREF(PyArrayScalar_False),\t\\\n\t\tPyArrayScalar_False\n#define PyArrayScalar_RETURN_TRUE\t\t\\\n\treturn Py_INCREF(PyArrayScalar_True),\t\\\n\t\tPyArrayScalar_True\n/* end to be exposed in C-API */\n", + "source_code_before": null, + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": 83, + "complexity": 0, + "token_count": 218, + "diff_parsed": { + "added": [ + "#ifndef _MULTIARRAYMODULE", + "typedef struct {", + "\tPyObject_HEAD", + "\tBool obval;", + "} PyBoolScalarObject;", + "#endif", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tsigned char obval;", + "} PyByteScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tshort obval;", + "} PyShortScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tint obval;", + "} PyIntScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tlong obval;", + "} PyLongScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tlonglong obval;", + "} PyLongLongScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tunsigned char obval;", + "} PyUByteScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tunsigned short obval;", + "} PyUShortScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tunsigned int obval;", + "} PyUIntScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tunsigned long obval;", + "} PyULongScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tulonglong obval;", + "} PyULongLongScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tfloat obval;", + "} PyFloatScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tdouble obval;", + "} PyDoubleScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tlongdouble obval;", + "} PyLongDoubleScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tcfloat obval;", + "} PyCFloatScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tcdouble obval;", + "} PyCDoubleScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tclongdouble obval;", + "} PyCLongDoubleScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tPyObject * obval;", + "} PyObjectScalarObject;", + "", + "", + "typedef struct {", + "\tPyObject_HEAD", + "\tchar obval;", + "} PyScalarObject;", + "", + "#define PyStringScalarObject PyStringObject", + "#define PyUnicodeScalarObject PyUnicodeObject", + "", + "typedef struct {", + "\tPyObject_VAR_HEAD", + "\tchar *obval;", + "\tPyArray_Descr *descr;", + "\tint flags;", + "\tPyObject *base;", + "} PyVoidScalarObject;", + "", + "/* to be exposed in C-API */", + "#define PyArrayScalar_False ((PyObject *)&_PyArrayScalar_BoolValues[0])", + "#define PyArrayScalar_True ((PyObject *)&_PyArrayScalar_BoolValues[1])", + "#define PyArrayScalar_RETURN_BOOL_FROM_LONG(i)\t\t\t\\", + "\treturn Py_INCREF(&_PyArrayScalar_BoolValues[((i)!=0)]),\t\\", + "\t\t(PyObject *)&_PyArrayScalar_BoolValues[((i)!=0)]", + "#define PyArrayScalar_RETURN_FALSE\t\t\\", + "\treturn Py_INCREF(PyArrayScalar_False),\t\\", + "\t\tPyArrayScalar_False", + "#define PyArrayScalar_RETURN_TRUE\t\t\\", + "\treturn Py_INCREF(PyArrayScalar_True),\t\\", + "\t\tPyArrayScalar_True", + "/* end to be exposed in C-API */" + ], + "deleted": [] + } + }, + { + "old_path": "numpy/core/src/arrayobject.c", + "new_path": "numpy/core/src/arrayobject.c", + "filename": "arrayobject.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -790,7 +790,7 @@ PyArray_FromDims(int nd, int *d, int type)\n \t*/\n \tif (ret && (PyArray_DESCR(ret)->type_num != PyArray_OBJECT)) {\n \t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n-\t}\n+\t} \n \treturn ret;\n }\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/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_)\n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear();\n priority = default_;\n }\n Py_XDECREF(ret);\n return priority;\n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a\n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n }\n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int\ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides,\n\t intp *src_dimensions, int src_nd, int elsize,\n\t int copies) {\n intp i, j;\n\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1,\n dest_dimensions+1, dest_nd-1,\n src, src_strides,\n src_dimensions, src_nd,\n elsize, copies) == -1)\n return -1;\n }\n return 0;\n }\n\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError,\n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) &&\n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] !=\n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src)\n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\n dest_strides_ptr = dest_strides;\n\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1)\n return NULL;\n\n new_data = (char *)_pya_malloc(stride);\n\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions,\n dest_nd, src->data, src_strides,\n src_dimensions, src_nd, elsize, copies);\n\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *,\n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int\nPyArray_INCREF(PyArrayObject *mp)\n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap)\n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n\n\n if ((numitems == 1) || (itemsize == srcstrides))\n memcpy(d1, s1, itemsize*numitems);\n else {\n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n }\n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG\n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i)\n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp\nPyArray_Size(PyObject *op)\n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n }\n\telse {\n return 0;\n }\n}\n\n/* If destination is not the right type, then src\n will be cast to destination.\n*/\n\n/* Does a flat iterator-based copy.\n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however.\n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n\n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError,\n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n\n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, elsize);\n PyArray_INCREF(dest);\n return 0;\n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n }\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int\nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)\n{\n PyArrayObject *src;\n int ret;\n\t\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d,\n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t} \n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,\n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd,\n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran,\n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\n return (PyObject *)ret;\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) {\n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED;\n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=0;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use\n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifndef Py_UNICODE_WIDE\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\treturn obj;\n#endif\n\t\t}\n\t\telse {\n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, itemsize);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this.\n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag\n*/\n\n/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp)\n{\n\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n\n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int\nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs,\n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/*\n copyies over from the old descr table for anything\n NULL or zero in what is given.\n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)\n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data,\n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError,\n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr,\n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element\"\\\n \" %d to file\",\n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj);\n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj),\n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\",\n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1)\n fwrite(sep, 1, n3, fp);\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self)\n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0)\n\t\treturn self->descr->f->getitem(self->data,self);\n\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n\n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void\narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an\n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE\n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n\n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\narray_length(PyArrayObject *self)\n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i)\n{\n\tchar *item;\n\tPyArrayObject *r;\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1,\n\t\t\t\t\t\t self->dimensions+1,\n\t\t\t\t\t\t self->strides+1, item,\n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\nstatic PyObject *\narray_item_nice(PyArrayObject *self, _int_or_ssize_t i)\n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\n\nstatic int\narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v)\n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret;\n }\n\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if PY_VERSION_HEX < 0x02050000\n #if SIZEOF_INT == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#else\n #if SIZEOF_SIZE_T == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#endif\n#ifndef array_ass_item\nstatic int\narray_ass_item(PyArrayObject *self, _int_or_ssize_t i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int\nparse_index(PyArrayObject *self, PyObject *op,\n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError,\n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\n nd_old = nd_new = 0;\n\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n\t/* tuple for transpose is\n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of\n\t the broadcasted index array\n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the\n\t result\n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2)\n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call.\n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type,\n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret))\n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, PyArray_ITEMSIZE(arr));\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS];\n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL)\n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0\n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from\n Python when using a[object] unless object is a standard slice object\n (not an extended one).\n\n*/\n\n/* There are two situations:\n\n 1 - the subscript is a standard view and a reference to the\n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned.\n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *);\n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op)\n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr,\n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis) {\n\t\t\t/* XXX: This leads to a small inconsistency\n\t\t\t XXX: with the nd>0 case where (x[...] is x)\n\t\t\t XXX: is false for nd>0 case. */\n\t\t\tPy_INCREF(self);\n\t\t\treturn (PyObject *)self;\n\t\t}\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op)) {\n\t\t\t\tPy_INCREF(self);\n\t\t\t\treturn (PyObject *)self;\n\t\t\t}\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset))\n == -1)\n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset,\n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL)\n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be\n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *);\n\nstatic int\narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)\n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr,\n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1;\n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to\n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op)\n{\n\t/* The following is just a copy of PyArray_Return with an\n\t additional logic in the nd == 0 case. More efficient\n\t implementation may be possible by refactoring\n\t array_subscript */\n\n\tPyArrayObject *mp = (PyArrayObject *)array_subscript(self, op);\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tBool noellipses = TRUE;\n\t\tif (op == Py_Ellipsis)\n\t\t\tnoellipses = FALSE;\n\t\telse if (PySequence_Check(op)) {\n\t\t\tint n, i;\n\t\t\tn = PySequence_Size(op);\n\t\t\tfor (i = 0; i < n; ++i) \n\t\t\t\tif (PySequence_GetItem(op, i) == Py_Ellipsis) {\n\t\t\t\t\tnoellipses = FALSE;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t\tif (noellipses) {\n\t\t\tPyObject *ret;\n\t\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\t\tPy_DECREF(mp);\n\t\t\treturn ret;\n\t\t}\n\t}\n\treturn (PyObject *)mp;\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t /*mp_length*/\n#else\n (inquiry)array_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic _int_or_ssize_t\narray_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp)\n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic _int_or_ssize_t\narray_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"accessing non-existing array segment\");\n return -1;\n }\n\n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic _int_or_ssize_t\narray_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (PyArray_CHKFLAGS(self, WRITEABLE))\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic _int_or_ssize_t\narray_getcharbuf(PyArrayObject *self, _int_or_ssize_t segment, const char **ptrptr)\n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError,\n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (writebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (segcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (charbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#else\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#endif\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n *square,\n *reciprocal,\n *ones_like,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum,\n\t\t*rint;\n} NumericOps;\n\nstatic NumericOps n_ops; /* NB: static objects inlitialized to zero */\n\n/* Dictionary can contain any of the numeric operations, by name.\n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n\n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint\nPyArray_SetNumericOps(PyObject *dict)\n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n SET(square);\n SET(reciprocal);\n SET(ones_like);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\n SET(true_divide);\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n\tSET(rint);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void)\n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL)\n\t\treturn NULL;\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n GET(square);\n GET(reciprocal);\n GET(ones_like);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide);\n GET(true_divide);\n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\tGET(rint);\n\treturn dict;\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,\n\t\t\t\t PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2)\n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\n\nstatic PyObject *array_float(PyArrayObject *v);\n\n\nstatic int\narray_power_is_scalar(PyObject *o2, double* exp)\n{\n PyObject *temp;\n const int optimize_fpexps = 1;\n if (PyInt_Check(o2)) {\n *exp = (double)PyInt_AsLong(o2);\n return 1;\n }\n if (optimize_fpexps && PyFloat_Check(o2)) {\n *exp = PyFloat_AsDouble(o2);\n return 1;\n }\n if (PyArray_CheckScalar(o2)) {\n if (PyArray_ISINTEGER(o2) || (optimize_fpexps && PyArray_ISFLOAT(o2))) {\n temp = array_float((PyArrayObject *)o2);\n if (temp != NULL) {\n *exp = PyFloat_AsDouble(o2);\n Py_DECREF(temp);\n return 1;\n }\n }\n }\n return 0;\n}\n\n/* optimize float array or complex array to a scalar power */\nstatic PyObject *\nfast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) {\n double exp;\n if (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) || PyArray_ISCOMPLEX(a1))) {\n if (array_power_is_scalar(o2, &exp)) {\n PyObject *fastop = NULL;\n if (exp == 1.0) {\n /* we have to do this one special, as the \"copy\" method of\n array objects isn't set up early enough to be added\n by PyArray_SetNumericOps.\n */\n if (inplace) {\n return (PyObject *)a1;\n } else {\n return PyArray_Copy(a1);\n }\n } else if (exp == -1.0) {\n fastop = n_ops.reciprocal;\n } else if (exp == 0.0) {\n fastop = n_ops.ones_like;\n } else if (exp == 0.5) {\n fastop = n_ops.sqrt;\n } else if (exp == 2.0) {\n fastop = n_ops.square;\n } else {\n return NULL;\n }\n if (inplace) {\n PyArray_GenericInplaceUnaryFunction(a1, fastop);\n } else {\n return PyArray_GenericUnaryFunction(a1, fastop);\n }\n }\n }\n return NULL;\n}\n\nstatic PyObject *\narray_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 0);\n if (!value) {\n value = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\n\nstatic PyObject *\narray_negative(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 1);\n if (!value) {\n value = PyArray_GenericInplaceBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int\narray_any_nonzero(PyArrayObject *mp)\n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2)\n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_float(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to a \"\\\n\t\t\t\t\"float; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_long(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/\n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected\n*/\n\n\nstatic PyObject *\narray_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t _int_or_ssize_t ihigh)\n{\n PyArrayObject *r;\n _int_or_ssize_t l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n self->dimensions[0] = l;\n\tif (r == NULL) return NULL;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS);\n return (PyObject *)r;\n}\n\n\nstatic int\narray_ass_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t\t_int_or_ssize_t ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res;\n int ret;\n\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\nstatic PySequenceMethods array_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (ssizeargfunc)NULL,\n\t(ssizeargfunc)array_item_nice,\n\t(ssizessizeargfunc)array_slice,\n (ssizeobjargproc)array_ass_item,\t /*sq_ass_item*/\n (ssizessizeobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(ssizeargfunc)NULL,\n#else\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t /*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n#endif\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int\ndump_data(char **string, int *n, int *max_n, char *data, int nd,\n intp *dimensions, intp *strides, PyArrayObject* self)\n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\n if (nd == 0) {\n\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata,\n\t\t self->nd, self->dimensions,\n self->strides, self) < 0) {\n\t\t_pya_free(string); return NULL;\n\t}\n\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void\nPyArray_SetStringFunction(PyObject *op, int repr)\n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_ReprFunction = op;\n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_StrFunction = op;\n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)\n{\n PyObject *array_other, *result;\n\tint typenum;\n\n switch (cmp_op)\n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then return False\n\t\t\t\t This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of False\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the\n\t\t\t two array objects can not be compared together so\n\t\t\t return zero\n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be\n\t\t\t\t compared and cannot be equal, therefore,\n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t other,\n\t\t\t\t\t\t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL,\n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int\n_IsFortranContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap)\n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object\n\t If it is a writeable array, then return TRUE\n\t If we can find an array object\n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable\n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA))\n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly\n\t and unpickled array can be set and reset writeable\n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t\telse ret->flags &= ~WRITEABLE;\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not\n ever be able to walk outside of the memory implied numbytes and offset.\n\n The available memory is assumed to start at -offset and proceed\n to numbytes-offset. The strides are checked to ensure\n that accessing memory using striding will not try to reach beyond\n this memory for any of the axes.\n\n If numbytes is 0 it will be calculated using the dimensions and\n element-size.\n\n This function checks for walking beyond the beginning and right-end\n of the buffer and therefore works for any integer stride (positive\n or negative).\n*/\n\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\tintp byte_begin;\n\tintp begin;\n\tintp end;\n\n\tif (numbytes == 0)\n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\n\tbegin = -offset;\n\tend = numbytes - offset - elsize;\n\tfor (i=0; i end))\n\t\t\treturn FALSE;\n\t}\n\treturn TRUE;\n\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings\n depending on data and strides:\n\n If data is given, then flags is flags associated with data.\n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument\n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set).\n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired.\n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize,\n\t\t int inflag, int *objflags)\n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\n/* and update the dimensions and strides\n appropriately. Dimensions and strides are added\n to the end unless we have a FORTRAN array\n and then they are added to the beginning\n\n Strides are only added if given (because data is given).\n*/\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,\n\t\t\t intp *newstrides, int oldnd, int isfortran)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\tint tuple;\n\n\told = *des;\n\t*des = old->subarray->base;\n\n\n\tmydim = newdims + oldnd;\n\ttuple = PyTuple_Check(old->subarray->shape);\n\tif (tuple) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t}\n\telse {\n\t\tnumnew = 1;\n\t}\n\n\n\tnewnd = oldnd + numnew;\n\tif (newnd > MAX_DIMS) goto finish;\n\tif (isfortran) {\n\t\tmemmove(newdims+numnew, newdims, oldnd*sizeof(intp));\n\t\tmydim = newdims;\n\t}\n\n\tif (tuple) {\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\tif (isfortran) {\n\t\t\tmemmove(newstrides+numnew, newstrides,\n\t\t\t\toldnd*sizeof(intp));\n\t\t\tmystrides = newstrides;\n\t\t}\n\t\t/* Make new strides -- alwasy C-contiguous */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\n finish:\n\tPy_INCREF(*des);\n\tPy_DECREF(old);\n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,\n\t\t intp *dims, intp *strides, void *data,\n\t\t int flags, PyObject *obj)\n{\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tint isfortran=0;\n\t\tisfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || \\\n\t\t\t(!data && flags);\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims,\n\t\t\t\t\t\t newstrides, nd, isfortran);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims,\n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { \n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN;\n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse { /* we allow strides even when we create\n\t\t\t the memory, but be careful with this...\n\t\t */\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays\n\t\t e.g. shape=(0,) -- otherwise buffer exposure\n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in,\n\t\t\t\t\t this object won't own it\n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for\n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype.\n\t If obj is NULL, then call method with Py_None \n\t*/\n\tif ((subtype != &PyArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (strides != NULL) { /* did not allocate own data \n\t\t\t\t\t or funny strides */\n\t\t\t/* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tif (obj == NULL) obj=Py_None;\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n If refcheck is 0, then the reference count is not checked\n and assumed to be 1.\n You still must own this data and have no weak-references and no base\n object.\n*/\nstatic PyObject *\nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\n if (!PyArray_ISONESEGMENT(self)) {\n PyErr_SetString(PyExc_ValueError,\n \"resize only works on single-segment arrays\");\n return NULL;\n }\n\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n\n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (refcheck) refcnt = REFCOUNT(self);\n\t\telse refcnt = 1;\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (newsize == 0) sd = self->descr->elsize;\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n\n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) {\n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0,\n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n\n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n\n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n self->flags, &(self->flags));\n\n\n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\n return Py_None;\n\n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\tPyArray_FillWithScalarFunc* fillwithscalar =\n\t\t\tarr->descr->f->fillwithscalar;\n\t\tif (fillwithscalar && PyArray_ISALIGNED(arr)) {\n\t\t\tcopyswap(fromptr, NULL, swap, itemsize);\n\t\t\tfillwithscalar(toptr, size, fromptr, arr);\n\t\t}\n\t\telse {\n\t\t\twhile (size--) {\n\t\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\t\ttoptr += itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL;\n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous\n\t array of a specific type and shape.\n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims,\n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter,\n &strides,\n &fortran))\n\t\tgoto fail;\n\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"data-type with unspecified variable length\");\n\t\tgoto fail;\n\t}\n\t\n\tif (strides.ptr != NULL) {\n\t\tintp nb, off;\n\t\tif (strides.len != dims.len) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides, if given, must be \"\t\\\n\t\t\t\t\t\"the same length as shape\");\n\t\t\tgoto fail;\n\t\t}\n\n\t\tif (buffer.ptr == NULL) {\n\t\t\tnb = 0;\n\t\t\toff = 0;\n\t\t}\n\t\telse {\n\t\t\tnb = buffer.len;\n\t\t\toff = offset;\n\t\t}\n\t\t\n\n\t\tif (!PyArray_CheckStrides(itemsize, dims.len, \n\t\t\t\t\t nb, off,\n\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides is incompatible \"\t\\\n\t\t\t\t\t\"with shape of requested \"\t\\\n\t\t\t\t\t\"array and size of buffer\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\t\t\t\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len,\n\t\t\t\t\t dims.ptr,\n\t\t\t\t\t strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = (buffer.len-offset) / itemsize;\n }\n else if ((strides.ptr == NULL) && \\\n\t\t\t buffer.len < itemsize*\t\t\t\t\\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError,\n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t offset + (char *)buffer.ptr,\n\t\t\t\t\t buffer.flags, NULL);\n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base);\n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyArray_NewFlagsObject((PyObject *)self);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n\tint nd;\n\tPyObject *ret;\n\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret),\n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret),\n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes=0;\n\tintp offset=0;\n\tint buf_len;\n\tchar *buf;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base && PyArray_Check(new->base)) {\n\t\tnew = (PyArrayObject *)(new->base);\n\t}\n\t/* Get the available memory through the buffer\n\t interface on new->base or if that fails\n\t from the current new */\n\tif (new->base && PyObject_AsReadBuffer(new->base,\n\t\t\t\t\t (const void **)&buf,\n\t\t\t\t\t &buf_len) >= 0) {\n\t\toffset = self->data - buf;\n\t\tnumbytes = buf_len + offset;\n\t}\n\telse {\n\t\tPyErr_Clear();\n \t\tnumbytes = PyArray_MultiplyList(new->dimensions,\n\t\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\toffset = self->data - new->data;\n\t}\n\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes,\n\t\t\t\t offset,\n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self))\n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self)\n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0,\n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf,\n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse\n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse\n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed.\n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the\n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0)\n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n\telse if (newtype->elsize > self->descr->elsize) {\n\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update\n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\t/* We would decref newtype here --- temp will\n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tif (temp == NULL) return -1;\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\tPy_INCREF(temp->descr);\n\t\t/* Fool deallocator not to delete these*/\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype;\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA);\n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num -\n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type,\n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new);\n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int\narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode,\n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr));\n memmove(selfit->dataptr, arrit->dataptr,\n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size)\n PyArray_ITER_RESET(arrit);\n }\n retval = 0;\n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->descr->elsize);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size)\n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\",\n\t (getter)array_ndim_get,\n\t NULL,\n\t \"number of array dimensions\"},\n {\"flags\",\n\t (getter)array_flags_get,\n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\",\n\t (getter)array_shape_get,\n\t (setter)array_shape_set,\n\t \"tuple of array dimensions\"},\n {\"strides\",\n\t (getter)array_strides_get,\n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)array_data_get,\n\t (setter)array_data_set,\n\t \"pointer to start of data\"},\n {\"itemsize\",\n\t (getter)array_itemsize_get,\n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\",\n\t (getter)array_real_get,\n\t (setter)array_real_set,\n\t \"real part of array\"},\n {\"imag\",\n\t (getter)array_imag_get,\n\t (setter)array_imag_set,\n\t \"imaginary part of array\"},\n\t{\"flat\",\n\t (getter)array_flat_get,\n\t (setter)array_flat_set,\n\t \"a 1-d view of a contiguous array\"},\n\t{\"__array_data__\",\n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\",\n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n\t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */\n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] =\n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\nstatic PyTypeObject PyArray_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0,\t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n &array_as_sequence,\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str,\t /*tp_str*/\n\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n &array_as_buffer, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT\n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter,\t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n array_alloc,\t /* tp_alloc */\n (newfunc)array_new,\t\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int\ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple)\n{\n int d=0;\n PyObject *e;\n\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0)\n\t\treturn 1;\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize)\n{\n\tint n, r, i;\n\tPyObject *e;\n\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s)\n\t\t\t*itemsize = MAX(*itemsize, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype ---\n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately\n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE &&\n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\nstatic PyArray_Descr *\n_array_find_python_scalar_type(PyObject *op)\n{\n if (PyFloat_Check(op)) {\n return PyArray_DescrFromType(PyArray_DOUBLE);\n } else if (PyComplex_Check(op)) {\n return PyArray_DescrFromType(PyArray_CDOUBLE);\n } else if (PyInt_Check(op)) {\n /* bools are a subclass of int */\n if (PyBool_Check(op)) {\n return PyArray_DescrFromType(PyArray_BOOL);\n } else {\n return PyArray_DescrFromType(PyArray_LONG);\n }\n } else if (PyLong_Check(op)) {\n /* if integer can fit into a longlong then return that\n */\n if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n PyErr_Clear();\n return PyArray_DescrFromType(PyArray_OBJECT);\n }\n return PyArray_DescrFromType(PyArray_LONGLONG);\n }\n return NULL;\n}\n\n/* op is an object to be converted to an ndarray.\n\n minitype is the minimum type-descriptor needed.\n\n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n\n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\n\tif (minitype == NULL)\n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\n if (max < 0) goto deflt;\n\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n chktype = _array_find_python_scalar_type(op);\n if (chktype) {\n goto finish;\n }\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n\n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind,\n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n }\n\n\tif (PyInstance_Check(op)) goto deflt;\n\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\n finish:\n\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype;\n}\n\nstatic int\nAssign_Array(PyArrayObject *self, PyObject *v)\n{\n PyObject *e;\n int l, r;\n\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\n l=PyObject_Length(v);\n if(l < 0) return -1;\n\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1;\n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */\n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode)\n{\n PyArrayObject *ret;\n\tint itemsize;\n\tint type;\n\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= 4;\n\n\t\tif (itemsize != typecode->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(typecode);\n\t\t\ttypecode->elsize = itemsize;\n\t\t}\n\t}\n\n ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL,\n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\tif (ret == NULL) return NULL;\n\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode */\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string,\n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid input sequence\");\n\t\tgoto fail;\n }\n\n\tif (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {\n\t\tnd = max_depth;\n\t}\n\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid number of dimensions\");\n\t\tgoto fail;\n }\n\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\n if(!r) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int\nPyArray_ValidType(int type)\n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in))\n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, 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\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n oelsize);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject *\nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING)\n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd,\n\t\t\t\t mp->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\n}\n\n/* The number of elements in out must be an integer multiple\n of the number of elements in mp.\n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1;\n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * mpsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr,\n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)\n{\n\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1)\n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse {\n if ((flags & ENSUREARRAY)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype,\n\t\t\t\t\t\t newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr;\n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\n\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong))\n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char))\n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long))\n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap)\n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n\n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL;\n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n\n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data,\n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr));\n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n\n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context)\n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, \n\t\t\t\t\t\t\t\t NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None,\n\t\t\t\t\t\t context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", \n\t\t\t\t\t\t typecode, context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", \n\t\t\t\t\t\t\t typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError,\n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n}\n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,\n int max_depth, int flags, PyObject *context)\n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op))\n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t} else if (newtype == NULL &&\n (newtype = _array_find_python_scalar_type(op))) {\n r = Array_FromScalar(op, newtype);\n }\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, \n\t\t\t\t\t\tflags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\n\t/* Be sure we succeed here */\n\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int\nPyArray_ObjectType(PyObject *op, int minimum_type)\n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of\n CONTIGUOUS,\n FORTRAN,\n ALIGNED,\n WRITEABLE,\n NOTSWAPPED,\n ENSURECOPY,\n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should\n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or\n not it has such features.\n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well.\n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n\n FORTRAN can be set in the FLAGS to request a FORTRAN array.\n Fortran arrays are always behaved (aligned,\n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d).\n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array.\n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe.\n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,\n int max_depth, int requires, PyObject *context)\n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0,\n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place\n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op)) return op;\n\n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int\nPyArray_CanCastSafely(int fromtype, int totype)\n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype))\n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode\n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\n\t\t*/\n\t}\n\treturn ret;\n}\n\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n\n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd;\n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D)\n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic _int_or_ssize_t\niter_length(PyArrayIterObject *self)\n{\n return self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr,\n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1)\n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t 1, &n_steps,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail;\n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0,\n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n\t\t\t\t itemsize);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size)\n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size)\n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)\n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size)\n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0,\n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)iter_length,\t\t /*mp_length*/\n#else\n (inquiry)iter_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op)\n{\n\n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options:\n 1) underlying array is contiguous\n -- return 1-d wrapper around it\n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, it->ao->data,\n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r);\n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n\n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\",\n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &iter_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t\t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular\n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators\n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++)\n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already\n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1)\n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\n\t\t\t\t\t\t\t\"to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of\n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord,\n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t sizeof(intp));\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so,\n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size.\n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere.\n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well.\n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0\n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t/* But, be sure to do it with a true array.\n\t */\n\tif (PyArray_CheckExact(arr)) {\n\t\tsub = array_subscript(arr, mit->indexobj);\n\t}\n\telse {\n\t\tPy_INCREF(arr);\n\t\tobj = PyArray_EnsureArray((PyObject *)arr);\n\t\tif (obj == NULL) goto fail;\n\t\tsub = array_subscript((PyArrayObject *)obj, mit->indexobj);\n\t\tPy_DECREF(obj);\n\t}\n\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects\n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been\n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj))\n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj,\n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1;\n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) *indptr, (int) (dimsize-1),\n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0,\n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n\tmit->index = 0;\n\tmit->ait = NULL;\n\tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY\n#undef SOBJ_ISFANCY\n#undef SOBJ_BADARRAY\n#undef SOBJ_TOOMANY\n#undef SOBJ_LISTTUP\n\n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple\n\t (with at least 1 list or arrayobject or Bool object), */\n\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i,\n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing\n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n\n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work.\n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a);\n mapiter is equivalent to a[indexobj].flat but the latter gets to use\n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t\t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t\t /* tp_iter */\n (iternextfunc)0,\t /* tp_iternext */\n 0,\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\n\tint i, err=0;\n\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\n\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL)\n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i,\n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(multi->iters[i]);\n\t_pya_free(multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\",\n\t (getter)arraymultiter_size_get,\n\t NULL,\n\t \"total size of broadcasted result\"},\n {\"index\",\n\t (getter)arraymultiter_index_get,\n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter),\n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t\t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods,\t /* tp_methods */\n arraymultiter_members,\t\t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types.\n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these\n builtins will be attempted leading to problems.\n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically\n allocated).\n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless\n there is a reference-count problem\n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set.\n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base,\n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0)\n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\",\n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self)\n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\",\n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr)\n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr)\n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv))\n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\n\t/* Now return the state which is at least\n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize\n and alignment for EXTENDED arrays\n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\n\tif (PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are:\n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args)\n{\n\tchar endian=PyArray_SWAP;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS,\n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n\tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\ndescr_length(PyArray_Descr *self)\n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op)\n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError,\n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)descr_length,\t\t /*mp_length*/\n#else\n (inquiry)descr_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t\t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &descr_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t/* tp_iternext */\n arraydescr_methods,\t\t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n\n/** Array Flags Object **/\n\ntypedef struct PyArrayFlagsObject {\n PyObject_HEAD\n PyObject *arr;\n int flags;\n} PyArrayFlagsObject;\n\n/*OBJECT_API\n Get New ArrayFlagsObject\n*/\nstatic PyObject *\nPyArray_NewFlagsObject(PyObject *obj)\n{\n PyObject *flagobj;\n int flags;\n if (obj == NULL) {\n flags = CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n }\n else {\n flags = PyArray_FLAGS(obj);\n }\n flagobj = PyArrayFlags_Type.tp_alloc(&PyArrayFlags_Type, 0);\n if (flagobj == NULL) return NULL;\n Py_XINCREF(obj);\n ((PyArrayFlagsObject *)flagobj)->arr = obj;\n ((PyArrayFlagsObject *)flagobj)->flags = flags;\n\n return flagobj;\n}\n\nstatic void\narrayflags_dealloc(PyArrayFlagsObject *self)\n{\n\tPy_XDECREF(self->arr);\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n\n#define _define_get(UPPER, lower) \\\nstatic PyObject * \\\narrayflags_ ## lower ## _get(PyArrayFlagsObject *self) \\\n{ \\\n PyObject *item; \\\n item = ((self->flags & (UPPER)) == (UPPER)) ? Py_True : Py_False; \\\n Py_INCREF(item); \\\n return item; \\\n}\n\n_define_get(CONTIGUOUS, contiguous)\n_define_get(FORTRAN, fortran)\n_define_get(UPDATEIFCOPY, updateifcopy)\n_define_get(OWNDATA, owndata)\n_define_get(ALIGNED, aligned)\n_define_get(WRITEABLE, writeable)\n\n_define_get(ALIGNED|WRITEABLE, behaved)\n_define_get(ALIGNED|WRITEABLE|CONTIGUOUS, carray)\n\nstatic PyObject *\narrayflags_forc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) ||\n ((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_fnc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_farray_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & (ALIGNED|WRITEABLE|FORTRAN)) == \\\n (ALIGNED|WRITEABLE|FORTRAN)) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_num_get(PyArrayFlagsObject *self)\n{\n return PyInt_FromLong(self->flags);\n}\n\n/* relies on setflags order being write, align, uic */\nstatic int\narrayflags_updateifcopy_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False));\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_aligned_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_writeable_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None, Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\n\nstatic PyGetSetDef arrayflags_getsets[] = {\n\t{\"contiguous\",\n\t (getter)arrayflags_contiguous_get,\n\t NULL,\n\t \"\"},\n {\"fortran\",\n (getter)arrayflags_fortran_get,\n NULL,\n \"\"},\n {\"updateifcopy\",\n (getter)arrayflags_updateifcopy_get,\n (setter)arrayflags_updateifcopy_set,\n \"\"},\n {\"owndata\",\n (getter)arrayflags_owndata_get,\n NULL,\n \"\"},\n {\"aligned\",\n (getter)arrayflags_aligned_get,\n (setter)arrayflags_aligned_set,\n \"\"},\n {\"writeable\",\n (getter)arrayflags_writeable_get,\n (setter)arrayflags_writeable_set,\n \"\"},\n {\"fnc\",\n (getter)arrayflags_fnc_get,\n NULL,\n \"\"},\n {\"forc\",\n (getter)arrayflags_forc_get,\n NULL,\n \"\"},\n {\"behaved\",\n (getter)arrayflags_behaved_get,\n NULL,\n \"\"},\n {\"carray\",\n (getter)arrayflags_carray_get,\n NULL,\n \"\"},\n {\"farray\",\n (getter)arrayflags_farray_get,\n NULL,\n \"\"},\n {\"num\",\n (getter)arrayflags_num_get,\n NULL,\n \"\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyObject *\narrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)\n{\n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n\tswitch(n) {\n\tcase 1:\n\t\tswitch(key[0]) {\n\t\tcase 'C':\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tcase 'F':\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tcase 'W':\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tcase 'B':\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tcase 'O':\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tcase 'A':\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tcase 'U':\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tdefault:\n\t\t\tgoto fail;\n\t\t}\n\t\tbreak;\n\tcase 2:\n\t\tif (strncmp(key, \"CA\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FA\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 3:\n\t\tif (strncmp(key, \"FNC\", n)==0)\n\t\t\treturn arrayflags_fnc_get(self);\n\t\tbreak;\n\tcase 4:\n\t\tif (strncmp(key, \"FORC\", n)==0)\n\t\t\treturn arrayflags_forc_get(self);\n\t\tbreak;\n\tcase 6:\n\t\tif (strncmp(key, \"CARRAY\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FARRAY\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 7:\n\t\tif (strncmp(key,\"FORTRAN\",n)==0)\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tif (strncmp(key,\"BEHAVED\",n)==0)\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tif (strncmp(key,\"OWNDATA\",n)==0)\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tif (strncmp(key,\"ALIGNED\",n)==0)\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tbreak;\n\tcase 9:\t\n\t\tif (strncmp(key,\"WRITEABLE\",n)==0)\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tbreak;\n\tcase 10:\n\t\tif (strncmp(key,\"CONTIGUOUS\",n)==0)\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tbreak;\n\tcase 12:\n\t\tif (strncmp(key, \"UPDATEIFCOPY\", n)==0)\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tbreak;\n\t}\n\n fail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return NULL;\n}\n\nstatic int\narrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)\n{ \n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n if (((n==9) && (strncmp(key, \"WRITEABLE\", n)==0)) ||\n\t ((n==1) && (strncmp(key, \"W\", n)==0)))\n return arrayflags_writeable_set(self, item);\n else if (((n==7) && (strncmp(key, \"ALIGNED\", n)==0)) || \n ((n==1) && (strncmp(key, \"A\", n)==0)))\n return arrayflags_aligned_set(self, item);\n else if (((n==12) && (strncmp(key, \"UPDATEIFCOPY\", n)==0)) ||\n ((n==1) && (strncmp(key, \"U\", n)==0)))\n return arrayflags_updateifcopy_set(self, item); \n\nfail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return -1;\n}\n\nstatic char *\n_torf_(int flags, int val)\n{\n if ((flags & val) == val) return \"True\";\n else return \"False\"; \n}\n\nstatic PyObject *\narrayflags_print(PyArrayFlagsObject *self)\n{\n int fl = self->flags;\n \n return PyString_FromFormat(\" %s : %s\\n %s : %s\\n %s : %s\\n\"\\\n \" %s : %s\\n %s : %s\\n %s : %s\",\n \"CONTIGUOUS\", _torf_(fl, CONTIGUOUS),\n \"FORTRAN\", _torf_(fl, FORTRAN),\n \"OWNDATA\", _torf_(fl, OWNDATA),\n \"WRITEABLE\", _torf_(fl, WRITEABLE),\n \"ALIGNED\", _torf_(fl, ALIGNED),\n \"UPDATEIFCOPY\", _torf_(fl, UPDATEIFCOPY));\n}\n\n\nstatic PyMappingMethods arrayflags_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)NULL, \t\t /*mp_length*/\n#else\n (inquiry)NULL, \t\t /*mp_length*/\n#endif\n (binaryfunc)arrayflags_getitem,\t /*mp_subscript*/\n (objobjargproc)arrayflags_setitem, /*mp_ass_subscript*/\n};\n\n\nstatic PyObject *\narrayflags_new(PyTypeObject *self, PyObject *args, PyObject *kwds)\n{\n PyObject *arg=NULL;\n if (!PyArg_UnpackTuple(args, \"flagsobj\", 0, 1, &arg))\n return NULL;\n\n if ((arg != NULL) && PyArray_Check(arg)) {\n return PyArray_NewFlagsObject(arg);\n }\n else {\n return PyArray_NewFlagsObject(NULL);\n }\n}\n\nstatic PyTypeObject PyArrayFlags_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\n \"numpy.flagsobj\",\n sizeof(PyArrayFlagsObject),\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayflags_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t0,\t\t /* tp_compare */\n (reprfunc)arrayflags_print, /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &arrayflags_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arrayflags_print, /* tp_str */\n 0,\t \t /* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t /* tp_iternext */\n 0,\t \t /* tp_methods */\n 0,\t /* tp_members */\n arrayflags_getsets, /* tp_getset */\n 0,\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t /* tp_init */\n 0,\t /* tp_alloc */\n arrayflags_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "source_code_before": "/*\n Provide multidimensional arrays as a basic object type in python.\n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004\n\nHeavily modified in 2005 with inspiration from Numarray\n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University\n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by\nSpace Science Telescope Institute\n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_)\n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear();\n priority = default_;\n }\n Py_XDECREF(ret);\n return priority;\n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a\n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n }\n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int\ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides,\n\t intp *src_dimensions, int src_nd, int elsize,\n\t int copies) {\n intp i, j;\n\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1,\n dest_dimensions+1, dest_nd-1,\n src, src_strides,\n src_dimensions, src_nd,\n elsize, copies) == -1)\n return -1;\n }\n return 0;\n }\n\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError,\n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) &&\n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] !=\n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src)\n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\n dest_strides_ptr = dest_strides;\n\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1)\n return NULL;\n\n new_data = (char *)_pya_malloc(stride);\n\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions,\n dest_nd, src->data, src_strides,\n src_dimensions, src_nd, elsize, copies);\n\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *,\n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int\nPyArray_INCREF(PyArrayObject *mp)\n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap)\n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n\n\n if ((numitems == 1) || (itemsize == srcstrides))\n memcpy(d1, s1, itemsize*numitems);\n else {\n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n }\n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG\n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i)\n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp\nPyArray_Size(PyObject *op)\n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n }\n\telse {\n return 0;\n }\n}\n\n/* If destination is not the right type, then src\n will be cast to destination.\n*/\n\n/* Does a flat iterator-based copy.\n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however.\n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n\n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError,\n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n\n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, elsize);\n PyArray_INCREF(dest);\n return 0;\n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n }\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int\nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)\n{\n PyArrayObject *src;\n int ret;\n\t\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d,\n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t}\n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,\n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd,\n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran,\n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\n return (PyObject *)ret;\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) {\n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED;\n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=0;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use\n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifndef Py_UNICODE_WIDE\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\treturn obj;\n#endif\n\t\t}\n\t\telse {\n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, itemsize);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this.\n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag\n*/\n\n/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp)\n{\n\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n\n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int\nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs,\n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/*\n copyies over from the old descr table for anything\n NULL or zero in what is given.\n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)\n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data,\n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError,\n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr,\n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element\"\\\n \" %d to file\",\n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj);\n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj),\n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\",\n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1)\n fwrite(sep, 1, n3, fp);\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self)\n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0)\n\t\treturn self->descr->f->getitem(self->data,self);\n\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n\n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void\narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an\n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE\n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n\n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\narray_length(PyArrayObject *self)\n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i)\n{\n\tchar *item;\n\tPyArrayObject *r;\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1,\n\t\t\t\t\t\t self->dimensions+1,\n\t\t\t\t\t\t self->strides+1, item,\n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\nstatic PyObject *\narray_item_nice(PyArrayObject *self, _int_or_ssize_t i)\n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\n\nstatic int\narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v)\n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret;\n }\n\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if PY_VERSION_HEX < 0x02050000\n #if SIZEOF_INT == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#else\n #if SIZEOF_SIZE_T == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#endif\n#ifndef array_ass_item\nstatic int\narray_ass_item(PyArrayObject *self, _int_or_ssize_t i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int\nparse_index(PyArrayObject *self, PyObject *op,\n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError,\n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\n nd_old = nd_new = 0;\n\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n\t/* tuple for transpose is\n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of\n\t the broadcasted index array\n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the\n\t result\n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2)\n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call.\n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type,\n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret))\n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, PyArray_ITEMSIZE(arr));\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS];\n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL)\n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0\n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from\n Python when using a[object] unless object is a standard slice object\n (not an extended one).\n\n*/\n\n/* There are two situations:\n\n 1 - the subscript is a standard view and a reference to the\n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned.\n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *);\n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op)\n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr,\n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis) {\n\t\t\t/* XXX: This leads to a small inconsistency\n\t\t\t XXX: with the nd>0 case where (x[...] is x)\n\t\t\t XXX: is false for nd>0 case. */\n\t\t\tPy_INCREF(self);\n\t\t\treturn (PyObject *)self;\n\t\t}\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op)) {\n\t\t\t\tPy_INCREF(self);\n\t\t\t\treturn (PyObject *)self;\n\t\t\t}\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset))\n == -1)\n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset,\n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL)\n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be\n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *);\n\nstatic int\narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)\n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr,\n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1;\n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to\n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op)\n{\n\t/* The following is just a copy of PyArray_Return with an\n\t additional logic in the nd == 0 case. More efficient\n\t implementation may be possible by refactoring\n\t array_subscript */\n\n\tPyArrayObject *mp = (PyArrayObject *)array_subscript(self, op);\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tBool noellipses = TRUE;\n\t\tif (op == Py_Ellipsis)\n\t\t\tnoellipses = FALSE;\n\t\telse if (PySequence_Check(op)) {\n\t\t\tint n, i;\n\t\t\tn = PySequence_Size(op);\n\t\t\tfor (i = 0; i < n; ++i) \n\t\t\t\tif (PySequence_GetItem(op, i) == Py_Ellipsis) {\n\t\t\t\t\tnoellipses = FALSE;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t\tif (noellipses) {\n\t\t\tPyObject *ret;\n\t\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\t\tPy_DECREF(mp);\n\t\t\treturn ret;\n\t\t}\n\t}\n\treturn (PyObject *)mp;\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t /*mp_length*/\n#else\n (inquiry)array_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic _int_or_ssize_t\narray_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp)\n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic _int_or_ssize_t\narray_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"accessing non-existing array segment\");\n return -1;\n }\n\n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic _int_or_ssize_t\narray_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (PyArray_CHKFLAGS(self, WRITEABLE))\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic _int_or_ssize_t\narray_getcharbuf(PyArrayObject *self, _int_or_ssize_t segment, const char **ptrptr)\n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError,\n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (writebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (segcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (charbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#else\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#endif\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n *square,\n *reciprocal,\n *ones_like,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum,\n\t\t*rint;\n} NumericOps;\n\nstatic NumericOps n_ops; /* NB: static objects inlitialized to zero */\n\n/* Dictionary can contain any of the numeric operations, by name.\n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n\n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint\nPyArray_SetNumericOps(PyObject *dict)\n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n SET(square);\n SET(reciprocal);\n SET(ones_like);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\n SET(true_divide);\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n\tSET(rint);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void)\n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL)\n\t\treturn NULL;\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n GET(square);\n GET(reciprocal);\n GET(ones_like);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide);\n GET(true_divide);\n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\tGET(rint);\n\treturn dict;\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,\n\t\t\t\t PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2)\n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\n\nstatic PyObject *array_float(PyArrayObject *v);\n\n\nstatic int\narray_power_is_scalar(PyObject *o2, double* exp)\n{\n PyObject *temp;\n const int optimize_fpexps = 1;\n if (PyInt_Check(o2)) {\n *exp = (double)PyInt_AsLong(o2);\n return 1;\n }\n if (optimize_fpexps && PyFloat_Check(o2)) {\n *exp = PyFloat_AsDouble(o2);\n return 1;\n }\n if (PyArray_CheckScalar(o2)) {\n if (PyArray_ISINTEGER(o2) || (optimize_fpexps && PyArray_ISFLOAT(o2))) {\n temp = array_float((PyArrayObject *)o2);\n if (temp != NULL) {\n *exp = PyFloat_AsDouble(o2);\n Py_DECREF(temp);\n return 1;\n }\n }\n }\n return 0;\n}\n\n/* optimize float array or complex array to a scalar power */\nstatic PyObject *\nfast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) {\n double exp;\n if (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) || PyArray_ISCOMPLEX(a1))) {\n if (array_power_is_scalar(o2, &exp)) {\n PyObject *fastop = NULL;\n if (exp == 1.0) {\n /* we have to do this one special, as the \"copy\" method of\n array objects isn't set up early enough to be added\n by PyArray_SetNumericOps.\n */\n if (inplace) {\n return (PyObject *)a1;\n } else {\n return PyArray_Copy(a1);\n }\n } else if (exp == -1.0) {\n fastop = n_ops.reciprocal;\n } else if (exp == 0.0) {\n fastop = n_ops.ones_like;\n } else if (exp == 0.5) {\n fastop = n_ops.sqrt;\n } else if (exp == 2.0) {\n fastop = n_ops.square;\n } else {\n return NULL;\n }\n if (inplace) {\n PyArray_GenericInplaceUnaryFunction(a1, fastop);\n } else {\n return PyArray_GenericUnaryFunction(a1, fastop);\n }\n }\n }\n return NULL;\n}\n\nstatic PyObject *\narray_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 0);\n if (!value) {\n value = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\n\nstatic PyObject *\narray_negative(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 1);\n if (!value) {\n value = PyArray_GenericInplaceBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int\narray_any_nonzero(PyArrayObject *mp)\n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2)\n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_float(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to a \"\\\n\t\t\t\t\"float; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_long(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/\n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected\n*/\n\n\nstatic PyObject *\narray_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t _int_or_ssize_t ihigh)\n{\n PyArrayObject *r;\n _int_or_ssize_t l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n self->dimensions[0] = l;\n\tif (r == NULL) return NULL;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS);\n return (PyObject *)r;\n}\n\n\nstatic int\narray_ass_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t\t_int_or_ssize_t ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res;\n int ret;\n\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\nstatic PySequenceMethods array_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (ssizeargfunc)NULL,\n\t(ssizeargfunc)array_item_nice,\n\t(ssizessizeargfunc)array_slice,\n (ssizeobjargproc)array_ass_item,\t /*sq_ass_item*/\n (ssizessizeobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(ssizeargfunc)NULL,\n#else\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t /*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n#endif\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int\ndump_data(char **string, int *n, int *max_n, char *data, int nd,\n intp *dimensions, intp *strides, PyArrayObject* self)\n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\n if (nd == 0) {\n\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata,\n\t\t self->nd, self->dimensions,\n self->strides, self) < 0) {\n\t\t_pya_free(string); return NULL;\n\t}\n\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void\nPyArray_SetStringFunction(PyObject *op, int repr)\n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_ReprFunction = op;\n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_StrFunction = op;\n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)\n{\n PyObject *array_other, *result;\n\tint typenum;\n\n switch (cmp_op)\n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then return False\n\t\t\t\t This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of False\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the\n\t\t\t two array objects can not be compared together so\n\t\t\t return zero\n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be\n\t\t\t\t compared and cannot be equal, therefore,\n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t other,\n\t\t\t\t\t\t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL,\n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int\n_IsFortranContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap)\n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object\n\t If it is a writeable array, then return TRUE\n\t If we can find an array object\n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable\n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA))\n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly\n\t and unpickled array can be set and reset writeable\n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t\telse ret->flags &= ~WRITEABLE;\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not\n ever be able to walk outside of the memory implied numbytes and offset.\n\n The available memory is assumed to start at -offset and proceed\n to numbytes-offset. The strides are checked to ensure\n that accessing memory using striding will not try to reach beyond\n this memory for any of the axes.\n\n If numbytes is 0 it will be calculated using the dimensions and\n element-size.\n\n This function checks for walking beyond the beginning and right-end\n of the buffer and therefore works for any integer stride (positive\n or negative).\n*/\n\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\tintp byte_begin;\n\tintp begin;\n\tintp end;\n\n\tif (numbytes == 0)\n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\n\tbegin = -offset;\n\tend = numbytes - offset - elsize;\n\tfor (i=0; i end))\n\t\t\treturn FALSE;\n\t}\n\treturn TRUE;\n\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings\n depending on data and strides:\n\n If data is given, then flags is flags associated with data.\n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument\n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set).\n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired.\n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize,\n\t\t int inflag, int *objflags)\n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\n/* and update the dimensions and strides\n appropriately. Dimensions and strides are added\n to the end unless we have a FORTRAN array\n and then they are added to the beginning\n\n Strides are only added if given (because data is given).\n*/\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,\n\t\t\t intp *newstrides, int oldnd, int isfortran)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\tint tuple;\n\n\told = *des;\n\t*des = old->subarray->base;\n\n\n\tmydim = newdims + oldnd;\n\ttuple = PyTuple_Check(old->subarray->shape);\n\tif (tuple) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t}\n\telse {\n\t\tnumnew = 1;\n\t}\n\n\n\tnewnd = oldnd + numnew;\n\tif (newnd > MAX_DIMS) goto finish;\n\tif (isfortran) {\n\t\tmemmove(newdims+numnew, newdims, oldnd*sizeof(intp));\n\t\tmydim = newdims;\n\t}\n\n\tif (tuple) {\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\tif (isfortran) {\n\t\t\tmemmove(newstrides+numnew, newstrides,\n\t\t\t\toldnd*sizeof(intp));\n\t\t\tmystrides = newstrides;\n\t\t}\n\t\t/* Make new strides -- alwasy C-contiguous */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\n finish:\n\tPy_INCREF(*des);\n\tPy_DECREF(old);\n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,\n\t\t intp *dims, intp *strides, void *data,\n\t\t int flags, PyObject *obj)\n{\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tint isfortran=0;\n\t\tisfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || \\\n\t\t\t(!data && flags);\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims,\n\t\t\t\t\t\t newstrides, nd, isfortran);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims,\n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { \n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN;\n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse { /* we allow strides even when we create\n\t\t\t the memory, but be careful with this...\n\t\t */\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays\n\t\t e.g. shape=(0,) -- otherwise buffer exposure\n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in,\n\t\t\t\t\t this object won't own it\n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for\n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype.\n\t If obj is NULL, then call method with Py_None \n\t*/\n\tif ((subtype != &PyArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (strides != NULL) { /* did not allocate own data \n\t\t\t\t\t or funny strides */\n\t\t\t/* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tif (obj == NULL) obj=Py_None;\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n If refcheck is 0, then the reference count is not checked\n and assumed to be 1.\n You still must own this data and have no weak-references and no base\n object.\n*/\nstatic PyObject *\nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\n if (!PyArray_ISONESEGMENT(self)) {\n PyErr_SetString(PyExc_ValueError,\n \"resize only works on single-segment arrays\");\n return NULL;\n }\n\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n\n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (refcheck) refcnt = REFCOUNT(self);\n\t\telse refcnt = 1;\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (newsize == 0) sd = self->descr->elsize;\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n\n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) {\n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0,\n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n\n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n\n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n self->flags, &(self->flags));\n\n\n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\n return Py_None;\n\n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\tPyArray_FillWithScalarFunc* fillwithscalar =\n\t\t\tarr->descr->f->fillwithscalar;\n\t\tif (fillwithscalar && PyArray_ISALIGNED(arr)) {\n\t\t\tcopyswap(fromptr, NULL, swap, itemsize);\n\t\t\tfillwithscalar(toptr, size, fromptr, arr);\n\t\t}\n\t\telse {\n\t\t\twhile (size--) {\n\t\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\t\ttoptr += itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL;\n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous\n\t array of a specific type and shape.\n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims,\n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter,\n &strides,\n &fortran))\n\t\tgoto fail;\n\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"data-type with unspecified variable length\");\n\t\tgoto fail;\n\t}\n\t\n\tif (strides.ptr != NULL) {\n\t\tintp nb, off;\n\t\tif (strides.len != dims.len) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides, if given, must be \"\t\\\n\t\t\t\t\t\"the same length as shape\");\n\t\t\tgoto fail;\n\t\t}\n\n\t\tif (buffer.ptr == NULL) {\n\t\t\tnb = 0;\n\t\t\toff = 0;\n\t\t}\n\t\telse {\n\t\t\tnb = buffer.len;\n\t\t\toff = offset;\n\t\t}\n\t\t\n\n\t\tif (!PyArray_CheckStrides(itemsize, dims.len, \n\t\t\t\t\t nb, off,\n\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides is incompatible \"\t\\\n\t\t\t\t\t\"with shape of requested \"\t\\\n\t\t\t\t\t\"array and size of buffer\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\t\t\t\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len,\n\t\t\t\t\t dims.ptr,\n\t\t\t\t\t strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = (buffer.len-offset) / itemsize;\n }\n else if ((strides.ptr == NULL) && \\\n\t\t\t buffer.len < itemsize*\t\t\t\t\\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError,\n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t offset + (char *)buffer.ptr,\n\t\t\t\t\t buffer.flags, NULL);\n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base);\n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyArray_NewFlagsObject((PyObject *)self);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n\tint nd;\n\tPyObject *ret;\n\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret),\n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret),\n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes=0;\n\tintp offset=0;\n\tint buf_len;\n\tchar *buf;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base && PyArray_Check(new->base)) {\n\t\tnew = (PyArrayObject *)(new->base);\n\t}\n\t/* Get the available memory through the buffer\n\t interface on new->base or if that fails\n\t from the current new */\n\tif (new->base && PyObject_AsReadBuffer(new->base,\n\t\t\t\t\t (const void **)&buf,\n\t\t\t\t\t &buf_len) >= 0) {\n\t\toffset = self->data - buf;\n\t\tnumbytes = buf_len + offset;\n\t}\n\telse {\n\t\tPyErr_Clear();\n \t\tnumbytes = PyArray_MultiplyList(new->dimensions,\n\t\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\toffset = self->data - new->data;\n\t}\n\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes,\n\t\t\t\t offset,\n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self))\n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self)\n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0,\n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf,\n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse\n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse\n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed.\n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the\n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0)\n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n\telse if (newtype->elsize > self->descr->elsize) {\n\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update\n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\t/* We would decref newtype here --- temp will\n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tif (temp == NULL) return -1;\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\tPy_INCREF(temp->descr);\n\t\t/* Fool deallocator not to delete these*/\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype;\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA);\n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num -\n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type,\n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new);\n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int\narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode,\n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr));\n memmove(selfit->dataptr, arrit->dataptr,\n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size)\n PyArray_ITER_RESET(arrit);\n }\n retval = 0;\n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->descr->elsize);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size)\n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\",\n\t (getter)array_ndim_get,\n\t NULL,\n\t \"number of array dimensions\"},\n {\"flags\",\n\t (getter)array_flags_get,\n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\",\n\t (getter)array_shape_get,\n\t (setter)array_shape_set,\n\t \"tuple of array dimensions\"},\n {\"strides\",\n\t (getter)array_strides_get,\n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)array_data_get,\n\t (setter)array_data_set,\n\t \"pointer to start of data\"},\n {\"itemsize\",\n\t (getter)array_itemsize_get,\n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\",\n\t (getter)array_real_get,\n\t (setter)array_real_set,\n\t \"real part of array\"},\n {\"imag\",\n\t (getter)array_imag_get,\n\t (setter)array_imag_set,\n\t \"imaginary part of array\"},\n\t{\"flat\",\n\t (getter)array_flat_get,\n\t (setter)array_flat_set,\n\t \"a 1-d view of a contiguous array\"},\n\t{\"__array_data__\",\n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\",\n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n\t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */\n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] =\n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\nstatic PyTypeObject PyArray_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0,\t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n &array_as_sequence,\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str,\t /*tp_str*/\n\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n &array_as_buffer, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT\n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter,\t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n array_alloc,\t /* tp_alloc */\n (newfunc)array_new,\t\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int\ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple)\n{\n int d=0;\n PyObject *e;\n\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0)\n\t\treturn 1;\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize)\n{\n\tint n, r, i;\n\tPyObject *e;\n\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s)\n\t\t\t*itemsize = MAX(*itemsize, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype ---\n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately\n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE &&\n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\nstatic PyArray_Descr *\n_array_find_python_scalar_type(PyObject *op)\n{\n if (PyFloat_Check(op)) {\n return PyArray_DescrFromType(PyArray_DOUBLE);\n } else if (PyComplex_Check(op)) {\n return PyArray_DescrFromType(PyArray_CDOUBLE);\n } else if (PyInt_Check(op)) {\n /* bools are a subclass of int */\n if (PyBool_Check(op)) {\n return PyArray_DescrFromType(PyArray_BOOL);\n } else {\n return PyArray_DescrFromType(PyArray_LONG);\n }\n } else if (PyLong_Check(op)) {\n /* if integer can fit into a longlong then return that\n */\n if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n PyErr_Clear();\n return PyArray_DescrFromType(PyArray_OBJECT);\n }\n return PyArray_DescrFromType(PyArray_LONGLONG);\n }\n return NULL;\n}\n\n/* op is an object to be converted to an ndarray.\n\n minitype is the minimum type-descriptor needed.\n\n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n\n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\n\tif (minitype == NULL)\n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\n if (max < 0) goto deflt;\n\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n chktype = _array_find_python_scalar_type(op);\n if (chktype) {\n goto finish;\n }\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n\n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind,\n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n }\n\n\tif (PyInstance_Check(op)) goto deflt;\n\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\n finish:\n\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype;\n}\n\nstatic int\nAssign_Array(PyArrayObject *self, PyObject *v)\n{\n PyObject *e;\n int l, r;\n\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\n l=PyObject_Length(v);\n if(l < 0) return -1;\n\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1;\n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */\n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode)\n{\n PyArrayObject *ret;\n\tint itemsize;\n\tint type;\n\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= 4;\n\n\t\tif (itemsize != typecode->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(typecode);\n\t\t\ttypecode->elsize = itemsize;\n\t\t}\n\t}\n\n ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL,\n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\tif (ret == NULL) return NULL;\n\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode */\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string,\n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid input sequence\");\n\t\tgoto fail;\n }\n\n\tif (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {\n\t\tnd = max_depth;\n\t}\n\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid number of dimensions\");\n\t\tgoto fail;\n }\n\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\n if(!r) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int\nPyArray_ValidType(int type)\n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in))\n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, 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\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n oelsize);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject *\nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING)\n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd,\n\t\t\t\t mp->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\n}\n\n/* The number of elements in out must be an integer multiple\n of the number of elements in mp.\n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1;\n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * mpsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr,\n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)\n{\n\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1)\n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse {\n if ((flags & ENSUREARRAY)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype,\n\t\t\t\t\t\t newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr;\n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\n\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong))\n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char))\n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long))\n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap)\n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n\n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL;\n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n\n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data,\n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr));\n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n\n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context)\n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, \n\t\t\t\t\t\t\t\t NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None,\n\t\t\t\t\t\t context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", \n\t\t\t\t\t\t typecode, context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", \n\t\t\t\t\t\t\t typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError,\n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n}\n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,\n int max_depth, int flags, PyObject *context)\n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op))\n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t} else if (newtype == NULL &&\n (newtype = _array_find_python_scalar_type(op))) {\n r = Array_FromScalar(op, newtype);\n }\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, \n\t\t\t\t\t\tflags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\n\t/* Be sure we succeed here */\n\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int\nPyArray_ObjectType(PyObject *op, int minimum_type)\n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of\n CONTIGUOUS,\n FORTRAN,\n ALIGNED,\n WRITEABLE,\n NOTSWAPPED,\n ENSURECOPY,\n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should\n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or\n not it has such features.\n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well.\n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n\n FORTRAN can be set in the FLAGS to request a FORTRAN array.\n Fortran arrays are always behaved (aligned,\n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d).\n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array.\n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe.\n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,\n int max_depth, int requires, PyObject *context)\n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0,\n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place\n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op)) return op;\n\n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int\nPyArray_CanCastSafely(int fromtype, int totype)\n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype))\n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode\n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\n\t\t*/\n\t}\n\treturn ret;\n}\n\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n\n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd;\n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D)\n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic _int_or_ssize_t\niter_length(PyArrayIterObject *self)\n{\n return self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr,\n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1)\n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t 1, &n_steps,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail;\n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0,\n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n\t\t\t\t itemsize);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size)\n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size)\n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)\n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size)\n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0,\n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)iter_length,\t\t /*mp_length*/\n#else\n (inquiry)iter_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op)\n{\n\n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options:\n 1) underlying array is contiguous\n -- return 1-d wrapper around it\n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, it->ao->data,\n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r);\n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n\n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\",\n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &iter_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t\t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular\n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators\n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++)\n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already\n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1)\n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\n\t\t\t\t\t\t\t\"to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of\n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord,\n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t sizeof(intp));\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so,\n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size.\n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere.\n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well.\n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0\n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t/* But, be sure to do it with a true array.\n\t */\n\tif (PyArray_CheckExact(arr)) {\n\t\tsub = array_subscript(arr, mit->indexobj);\n\t}\n\telse {\n\t\tPy_INCREF(arr);\n\t\tobj = PyArray_EnsureArray((PyObject *)arr);\n\t\tif (obj == NULL) goto fail;\n\t\tsub = array_subscript((PyArrayObject *)obj, mit->indexobj);\n\t\tPy_DECREF(obj);\n\t}\n\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects\n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been\n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj))\n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj,\n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1;\n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) *indptr, (int) (dimsize-1),\n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0,\n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n\tmit->index = 0;\n\tmit->ait = NULL;\n\tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY\n#undef SOBJ_ISFANCY\n#undef SOBJ_BADARRAY\n#undef SOBJ_TOOMANY\n#undef SOBJ_LISTTUP\n\n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple\n\t (with at least 1 list or arrayobject or Bool object), */\n\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i,\n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing\n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n\n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work.\n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a);\n mapiter is equivalent to a[indexobj].flat but the latter gets to use\n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t\t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t\t /* tp_iter */\n (iternextfunc)0,\t /* tp_iternext */\n 0,\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\n\tint i, err=0;\n\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\n\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL)\n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i,\n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(multi->iters[i]);\n\t_pya_free(multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\",\n\t (getter)arraymultiter_size_get,\n\t NULL,\n\t \"total size of broadcasted result\"},\n {\"index\",\n\t (getter)arraymultiter_index_get,\n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter),\n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t\t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods,\t /* tp_methods */\n arraymultiter_members,\t\t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types.\n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these\n builtins will be attempted leading to problems.\n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically\n allocated).\n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless\n there is a reference-count problem\n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set.\n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base,\n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0)\n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\",\n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self)\n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\",\n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr)\n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr)\n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv))\n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\n\t/* Now return the state which is at least\n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize\n and alignment for EXTENDED arrays\n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\n\tif (PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are:\n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args)\n{\n\tchar endian=PyArray_SWAP;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS,\n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n\tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\ndescr_length(PyArray_Descr *self)\n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op)\n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError,\n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)descr_length,\t\t /*mp_length*/\n#else\n (inquiry)descr_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t\t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &descr_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t/* tp_iternext */\n arraydescr_methods,\t\t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n\n/** Array Flags Object **/\n\ntypedef struct PyArrayFlagsObject {\n PyObject_HEAD\n PyObject *arr;\n int flags;\n} PyArrayFlagsObject;\n\n/*OBJECT_API\n Get New ArrayFlagsObject\n*/\nstatic PyObject *\nPyArray_NewFlagsObject(PyObject *obj)\n{\n PyObject *flagobj;\n int flags;\n if (obj == NULL) {\n flags = CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n }\n else {\n flags = PyArray_FLAGS(obj);\n }\n flagobj = PyArrayFlags_Type.tp_alloc(&PyArrayFlags_Type, 0);\n if (flagobj == NULL) return NULL;\n Py_XINCREF(obj);\n ((PyArrayFlagsObject *)flagobj)->arr = obj;\n ((PyArrayFlagsObject *)flagobj)->flags = flags;\n\n return flagobj;\n}\n\nstatic void\narrayflags_dealloc(PyArrayFlagsObject *self)\n{\n\tPy_XDECREF(self->arr);\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n\n#define _define_get(UPPER, lower) \\\nstatic PyObject * \\\narrayflags_ ## lower ## _get(PyArrayFlagsObject *self) \\\n{ \\\n PyObject *item; \\\n item = ((self->flags & (UPPER)) == (UPPER)) ? Py_True : Py_False; \\\n Py_INCREF(item); \\\n return item; \\\n}\n\n_define_get(CONTIGUOUS, contiguous)\n_define_get(FORTRAN, fortran)\n_define_get(UPDATEIFCOPY, updateifcopy)\n_define_get(OWNDATA, owndata)\n_define_get(ALIGNED, aligned)\n_define_get(WRITEABLE, writeable)\n\n_define_get(ALIGNED|WRITEABLE, behaved)\n_define_get(ALIGNED|WRITEABLE|CONTIGUOUS, carray)\n\nstatic PyObject *\narrayflags_forc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) ||\n ((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_fnc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_farray_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & (ALIGNED|WRITEABLE|FORTRAN)) == \\\n (ALIGNED|WRITEABLE|FORTRAN)) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_num_get(PyArrayFlagsObject *self)\n{\n return PyInt_FromLong(self->flags);\n}\n\n/* relies on setflags order being write, align, uic */\nstatic int\narrayflags_updateifcopy_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False));\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_aligned_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_writeable_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None, Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\n\nstatic PyGetSetDef arrayflags_getsets[] = {\n\t{\"contiguous\",\n\t (getter)arrayflags_contiguous_get,\n\t NULL,\n\t \"\"},\n {\"fortran\",\n (getter)arrayflags_fortran_get,\n NULL,\n \"\"},\n {\"updateifcopy\",\n (getter)arrayflags_updateifcopy_get,\n (setter)arrayflags_updateifcopy_set,\n \"\"},\n {\"owndata\",\n (getter)arrayflags_owndata_get,\n NULL,\n \"\"},\n {\"aligned\",\n (getter)arrayflags_aligned_get,\n (setter)arrayflags_aligned_set,\n \"\"},\n {\"writeable\",\n (getter)arrayflags_writeable_get,\n (setter)arrayflags_writeable_set,\n \"\"},\n {\"fnc\",\n (getter)arrayflags_fnc_get,\n NULL,\n \"\"},\n {\"forc\",\n (getter)arrayflags_forc_get,\n NULL,\n \"\"},\n {\"behaved\",\n (getter)arrayflags_behaved_get,\n NULL,\n \"\"},\n {\"carray\",\n (getter)arrayflags_carray_get,\n NULL,\n \"\"},\n {\"farray\",\n (getter)arrayflags_farray_get,\n NULL,\n \"\"},\n {\"num\",\n (getter)arrayflags_num_get,\n NULL,\n \"\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyObject *\narrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)\n{\n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n\tswitch(n) {\n\tcase 1:\n\t\tswitch(key[0]) {\n\t\tcase 'C':\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tcase 'F':\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tcase 'W':\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tcase 'B':\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tcase 'O':\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tcase 'A':\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tcase 'U':\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tdefault:\n\t\t\tgoto fail;\n\t\t}\n\t\tbreak;\n\tcase 2:\n\t\tif (strncmp(key, \"CA\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FA\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 3:\n\t\tif (strncmp(key, \"FNC\", n)==0)\n\t\t\treturn arrayflags_fnc_get(self);\n\t\tbreak;\n\tcase 4:\n\t\tif (strncmp(key, \"FORC\", n)==0)\n\t\t\treturn arrayflags_forc_get(self);\n\t\tbreak;\n\tcase 6:\n\t\tif (strncmp(key, \"CARRAY\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FARRAY\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 7:\n\t\tif (strncmp(key,\"FORTRAN\",n)==0)\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tif (strncmp(key,\"BEHAVED\",n)==0)\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tif (strncmp(key,\"OWNDATA\",n)==0)\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tif (strncmp(key,\"ALIGNED\",n)==0)\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tbreak;\n\tcase 9:\t\n\t\tif (strncmp(key,\"WRITEABLE\",n)==0)\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tbreak;\n\tcase 10:\n\t\tif (strncmp(key,\"CONTIGUOUS\",n)==0)\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tbreak;\n\tcase 12:\n\t\tif (strncmp(key, \"UPDATEIFCOPY\", n)==0)\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tbreak;\n\t}\n\n fail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return NULL;\n}\n\nstatic int\narrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)\n{ \n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n if (((n==9) && (strncmp(key, \"WRITEABLE\", n)==0)) ||\n\t ((n==1) && (strncmp(key, \"W\", n)==0)))\n return arrayflags_writeable_set(self, item);\n else if (((n==7) && (strncmp(key, \"ALIGNED\", n)==0)) || \n ((n==1) && (strncmp(key, \"A\", n)==0)))\n return arrayflags_aligned_set(self, item);\n else if (((n==12) && (strncmp(key, \"UPDATEIFCOPY\", n)==0)) ||\n ((n==1) && (strncmp(key, \"U\", n)==0)))\n return arrayflags_updateifcopy_set(self, item); \n\nfail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return -1;\n}\n\nstatic char *\n_torf_(int flags, int val)\n{\n if ((flags & val) == val) return \"True\";\n else return \"False\"; \n}\n\nstatic PyObject *\narrayflags_print(PyArrayFlagsObject *self)\n{\n int fl = self->flags;\n \n return PyString_FromFormat(\" %s : %s\\n %s : %s\\n %s : %s\\n\"\\\n \" %s : %s\\n %s : %s\\n %s : %s\",\n \"CONTIGUOUS\", _torf_(fl, CONTIGUOUS),\n \"FORTRAN\", _torf_(fl, FORTRAN),\n \"OWNDATA\", _torf_(fl, OWNDATA),\n \"WRITEABLE\", _torf_(fl, WRITEABLE),\n \"ALIGNED\", _torf_(fl, ALIGNED),\n \"UPDATEIFCOPY\", _torf_(fl, UPDATEIFCOPY));\n}\n\n\nstatic PyMappingMethods arrayflags_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)NULL, \t\t /*mp_length*/\n#else\n (inquiry)NULL, \t\t /*mp_length*/\n#endif\n (binaryfunc)arrayflags_getitem,\t /*mp_subscript*/\n (objobjargproc)arrayflags_setitem, /*mp_ass_subscript*/\n};\n\n\nstatic PyObject *\narrayflags_new(PyTypeObject *self, PyObject *args, PyObject *kwds)\n{\n PyObject *arg=NULL;\n if (!PyArg_UnpackTuple(args, \"flagsobj\", 0, 1, &arg))\n return NULL;\n\n if ((arg != NULL) && PyArray_Check(arg)) {\n return PyArray_NewFlagsObject(arg);\n }\n else {\n return PyArray_NewFlagsObject(NULL);\n }\n}\n\nstatic PyTypeObject PyArrayFlags_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\n \"numpy.flagsobj\",\n sizeof(PyArrayFlagsObject),\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayflags_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t0,\t\t /* tp_compare */\n (reprfunc)arrayflags_print, /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &arrayflags_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arrayflags_print, /* tp_str */\n 0,\t \t /* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t /* tp_iternext */\n 0,\t \t /* tp_methods */\n 0,\t /* tp_members */\n arrayflags_getsets, /* tp_getset */\n 0,\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t /* tp_init */\n 0,\t /* tp_alloc */\n arrayflags_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "methods": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 76, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 65, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 99, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 134, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 207, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 241, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 291, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 319, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 344, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 387, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 427, + "end_line": 509, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 516, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 593, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Size", + "long_name": "PyArray_Size( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 33, + "parameters": [ + "op" + ], + "start_line": 614, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 638, + "end_line": 718, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyObject", + "long_name": "PyArray_CopyObject( PyArrayObject * dest , PyObject * src_object)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 722, + "end_line": 736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDimsAndDataAndDescr", + "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 137, + "parameters": [ + "nd", + "d", + "descr", + "data" + ], + "start_line": 749, + "end_line": 775, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDims", + "long_name": "PyArray_FromDims( int nd , int * d , int type)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "nd", + "d", + "type" + ], + "start_line": 781, + "end_line": 795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewCopy", + "long_name": "PyArray_NewCopy( PyArrayObject * m1 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 804, + "end_line": 824, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 17, + "token_count": 616, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 833, + "end_line": 949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 965, + "end_line": 968, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Return", + "long_name": "PyArray_Return( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 91, + "parameters": [ + "mp" + ], + "start_line": 978, + "end_line": 1000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDataType", + "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 9, + "token_count": 229, + "parameters": [ + "type" + ], + "start_line": 1014, + "end_line": 1054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDescrForType", + "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 214, + "parameters": [ + "typenum", + "descr" + ], + "start_line": 1069, + "end_line": 1110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToFile", + "long_name": "PyArray_ToFile( PyArrayObject * self , FILE * fp , char * sep , char * format)", + "filename": "arrayobject.c", + "nloc": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1117, + "end_line": 1208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToList", + "long_name": "PyArray_ToList( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self" + ], + "start_line": 1214, + "end_line": 1243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToString", + "long_name": "PyArray_ToString( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 170, + "parameters": [ + "self" + ], + "start_line": 1246, + "end_line": 1282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_dealloc", + "long_name": "array_dealloc( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 1291, + "end_line": 1328, + "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": 1335, + "end_line": 1343, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_big_item", + "long_name": "array_big_item( PyArrayObject * self , intp i)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 4, + "token_count": 151, + "parameters": [ + "self", + "i" + ], + "start_line": 1346, + "end_line": 1371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , _int_or_ssize_t i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1374, + "end_line": 1377, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_ass_big_item", + "long_name": "array_ass_big_item( PyArrayObject * self , intp i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1380, + "end_line": 1415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , _int_or_ssize_t i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1428, + "end_line": 1431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "slice_coerce_index", + "long_name": "slice_coerce_index( PyObject * o , intp * v)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "o", + "v" + ], + "start_line": 1437, + "end_line": 1445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "slice_GetIndices", + "long_name": "slice_GetIndices( PySliceObject * r , intp length , intp * start , intp * stop , intp * step , intp * slicelength)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 24, + "token_count": 376, + "parameters": [ + "r", + "length", + "start", + "stop", + "step", + "slicelength" + ], + "start_line": 1451, + "end_line": 1501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "parse_subindex", + "long_name": "parse_subindex( PyObject * op , intp * step_size , intp * n_steps , intp max)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "step_size", + "n_steps", + "max" + ], + "start_line": 1508, + "end_line": 1553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "parse_index", + "long_name": "parse_index( PyArrayObject * self , PyObject * op , intp * dimensions , intp * strides , intp * offset_ptr)", + "filename": "arrayobject.c", + "nloc": 88, + "complexity": 20, + "token_count": 539, + "parameters": [ + "self", + "op", + "dimensions", + "strides", + "offset_ptr" + ], + "start_line": 1557, + "end_line": 1651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "_swap_axes", + "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1654, + "end_line": 1691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1703, + "end_line": 1756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetMap", + "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 53, + "complexity": 12, + "token_count": 382, + "parameters": [ + "mit", + "op" + ], + "start_line": 1759, + "end_line": 1819, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 0 + }, + { + "name": "count_new_axes_0d", + "long_name": "count_new_axes_0d( PyObject * tuple)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 7, + "token_count": 124, + "parameters": [ + "tuple" + ], + "start_line": 1822, + "end_line": 1849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "add_new_axes_0d", + "long_name": "add_new_axes_0d( PyArrayObject * arr , int newaxis_count)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 121, + "parameters": [ + "arr", + "newaxis_count" + ], + "start_line": 1852, + "end_line": 1871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 1883, + "end_line": 1945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 107, + "complexity": 28, + "token_count": 674, + "parameters": [ + "self", + "op" + ], + "start_line": 1969, + "end_line": 2094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2109, + "end_line": 2214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 10, + "token_count": 182, + "parameters": [ + "self", + "op" + ], + "start_line": 2223, + "end_line": 2262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , _int_or_ssize_t * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2285, + "end_line": 2297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2300, + "end_line": 2315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2319, + "end_line": 2328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , _int_or_ssize_t segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2331, + "end_line": 2342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 1, + "token_count": 182, + "parameters": [ + "dict" + ], + "start_line": 2420, + "end_line": 2457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 2, + "token_count": 203, + "parameters": [], + "start_line": 2467, + "end_line": 2510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2513, + "end_line": 2536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericAccumulateFunction", + "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2540, + "end_line": 2563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericBinaryFunction", + "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 44, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2567, + "end_line": 2574, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericUnaryFunction", + "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 38, + "parameters": [ + "m1", + "op" + ], + "start_line": 2577, + "end_line": 2584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceBinaryFunction", + "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 46, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2587, + "end_line": 2595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceUnaryFunction", + "long_name": "PyArray_GenericInplaceUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 40, + "parameters": [ + "m1", + "op" + ], + "start_line": 2598, + "end_line": 2605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2608, + "end_line": 2611, + "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": 2614, + "end_line": 2617, + "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": 2620, + "end_line": 2623, + "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": 2626, + "end_line": 2629, + "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": 2632, + "end_line": 2635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power_is_scalar", + "long_name": "array_power_is_scalar( PyObject * o2 , double * exp)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 132, + "parameters": [ + "o2", + "exp" + ], + "start_line": 2642, + "end_line": 2665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "fast_scalar_power", + "long_name": "fast_scalar_power( PyArrayObject * a1 , PyObject * o2 , int inplace)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 12, + "token_count": 181, + "parameters": [ + "a1", + "o2", + "inplace" + ], + "start_line": 2669, + "end_line": 2703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2706, + "end_line": 2715, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2719, + "end_line": 2722, + "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": 2725, + "end_line": 2728, + "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": 2731, + "end_line": 2734, + "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": 2737, + "end_line": 2740, + "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": 2743, + "end_line": 2746, + "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": 2749, + "end_line": 2752, + "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": 2755, + "end_line": 2758, + "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": 2761, + "end_line": 2764, + "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": 2767, + "end_line": 2770, + "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": 2773, + "end_line": 2776, + "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": 2779, + "end_line": 2782, + "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": 2785, + "end_line": 2788, + "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": 2791, + "end_line": 2794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2797, + "end_line": 2806, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2809, + "end_line": 2812, + "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": 2815, + "end_line": 2818, + "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": 2821, + "end_line": 2824, + "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": 2827, + "end_line": 2830, + "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": 2833, + "end_line": 2836, + "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": 2839, + "end_line": 2842, + "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": 2845, + "end_line": 2848, + "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": 2851, + "end_line": 2855, + "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": 2858, + "end_line": 2862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_any_nonzero", + "long_name": "array_any_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 95, + "parameters": [ + "mp" + ], + "start_line": 2866, + "end_line": 2884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_array_nonzero", + "long_name": "_array_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 3, + "token_count": 72, + "parameters": [ + "mp" + ], + "start_line": 2887, + "end_line": 2904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_divmod", + "long_name": "array_divmod( PyArrayObject * op1 , PyObject * op2)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 89, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2909, + "end_line": 2924, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_int", + "long_name": "array_int( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2928, + "end_line": 2954, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_float", + "long_name": "array_float( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2957, + "end_line": 2982, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_long", + "long_name": "array_long( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 2985, + "end_line": 3007, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_oct", + "long_name": "array_oct( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3010, + "end_line": 3032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_hex", + "long_name": "array_hex( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3035, + "end_line": 3057, + "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": 3060, + "end_line": 3064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 12, + "token_count": 268, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 3125, + "end_line": 3166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 3170, + "end_line": 3192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 3195, + "end_line": 3207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dump_data", + "long_name": "dump_data( char ** string , int * n , int * max_n , char * data , int nd , intp * dimensions , intp * strides , PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 7, + "token_count": 310, + "parameters": [ + "string", + "n", + "max_n", + "data", + "nd", + "dimensions", + "strides", + "self" + ], + "start_line": 3240, + "end_line": 3287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_repr_builtin", + "long_name": "array_repr_builtin( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 4, + "token_count": 224, + "parameters": [ + "self" + ], + "start_line": 3290, + "end_line": 3326, + "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": 3335, + "end_line": 3352, + "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": 3355, + "end_line": 3367, + "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": 3370, + "end_line": 3382, + "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": 90, + "complexity": 19, + "token_count": 392, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3385, + "end_line": 3491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 171, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3494, + "end_line": 3523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntTupleFromIntp", + "long_name": "PyArray_IntTupleFromIntp( int len , intp * vals)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 109, + "parameters": [ + "len", + "vals" + ], + "start_line": 3529, + "end_line": 3549, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3557, + "end_line": 3592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3598, + "end_line": 3617, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 3621, + "end_line": 3639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 3642, + "end_line": 3659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_IsWriteable", + "long_name": "_IsWriteable( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 107, + "parameters": [ + "ap" + ], + "start_line": 3662, + "end_line": 3695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_UpdateFlags", + "long_name": "PyArray_UpdateFlags( PyArrayObject * ret , int flagmask)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 11, + "token_count": 157, + "parameters": [ + "ret", + "flagmask" + ], + "start_line": 3702, + "end_line": 3729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 117, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 3749, + "end_line": 3769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 3789, + "end_line": 3813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_New", + "long_name": "PyArray_New( PyTypeObject * subtype , int nd , intp * dims , int type_num , intp * strides , * data , int itemsize , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 4, + "token_count": 128, + "parameters": [ + "subtype", + "nd", + "dims", + "type_num", + "strides", + "data", + "itemsize", + "flags", + "obj" + ], + "start_line": 3819, + "end_line": 3841, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd , int isfortran)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 10, + "token_count": 311, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd", + "isfortran" + ], + "start_line": 3852, + "end_line": 3914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 132, + "complexity": 29, + "token_count": 785, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3922, + "end_line": 4088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 167, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape , int refcheck)", + "filename": "arrayobject.c", + "nloc": 83, + "complexity": 16, + "token_count": 511, + "parameters": [ + "self", + "newshape", + "refcheck" + ], + "start_line": 4101, + "end_line": 4200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 100, + "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": 4206, + "end_line": 4223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 8, + "token_count": 279, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4227, + "end_line": 4277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 21, + "token_count": 620, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4280, + "end_line": 4411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 132, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4415, + "end_line": 4423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ndim_get", + "long_name": "array_ndim_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4429, + "end_line": 4432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flags_get", + "long_name": "array_flags_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 4435, + "end_line": 4438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_get", + "long_name": "array_shape_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4441, + "end_line": 4444, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_set", + "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4448, + "end_line": 4477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "array_strides_get", + "long_name": "array_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4481, + "end_line": 4484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 9, + "token_count": 304, + "parameters": [ + "self", + "obj" + ], + "start_line": 4487, + "end_line": 4541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4545, + "end_line": 4552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4555, + "end_line": 4561, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4565, + "end_line": 4571, + "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": 4574, + "end_line": 4588, + "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": 4591, + "end_line": 4635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_itemsize_get", + "long_name": "array_itemsize_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 4639, + "end_line": 4642, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_size_get", + "long_name": "array_size_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4645, + "end_line": 4656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nbytes_get", + "long_name": "array_nbytes_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4659, + "end_line": 4670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4676, + "end_line": 4679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_descr_get", + "long_name": "array_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 4682, + "end_line": 4686, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "arg" + ], + "start_line": 4700, + "end_line": 4787, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 4790, + "end_line": 4808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_struct_get", + "long_name": "array_struct_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 2, + "token_count": 130, + "parameters": [ + "self" + ], + "start_line": 4811, + "end_line": 4829, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 4832, + "end_line": 4842, + "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": 4846, + "end_line": 4871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_real_set", + "long_name": "array_real_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 4, + "token_count": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 4875, + "end_line": 4908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_get", + "long_name": "array_imag_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self" + ], + "start_line": 4911, + "end_line": 4944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 4947, + "end_line": 4984, + "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": 4987, + "end_line": 4990, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flat_set", + "long_name": "array_flat_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 9, + "token_count": 348, + "parameters": [ + "self", + "val" + ], + "start_line": 4993, + "end_line": 5043, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_alloc", + "long_name": "array_alloc( PyTypeObject * type , int nitems)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 1, + "token_count": 39, + "parameters": [ + "type", + "nitems" + ], + "start_line": 5133, + "end_line": 5140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "discover_depth", + "long_name": "discover_depth( PyObject * s , int max , int stop_at_string , int stop_at_tuple)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 19, + "token_count": 243, + "parameters": [ + "s", + "max", + "stop_at_string", + "stop_at_tuple" + ], + "start_line": 5228, + "end_line": 5261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5264, + "end_line": 5286, + "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": 5293, + "end_line": 5319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_array_small_type", + "long_name": "_array_small_type( PyArray_Descr * chktype , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 169, + "parameters": [ + "chktype", + "mintype" + ], + "start_line": 5325, + "end_line": 5357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_python_scalar_type", + "long_name": "_array_find_python_scalar_type( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 8, + "token_count": 120, + "parameters": [ + "op" + ], + "start_line": 5360, + "end_line": 5383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 28, + "token_count": 634, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5395, + "end_line": 5525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "Assign_Array", + "long_name": "Assign_Array( PyArrayObject * self , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 121, + "parameters": [ + "self", + "v" + ], + "start_line": 5528, + "end_line": 5551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 189, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5556, + "end_line": 5594, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 24, + "token_count": 373, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5599, + "end_line": 5666, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 68, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 5673, + "end_line": 5682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_bufferedcast", + "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 18, + "token_count": 525, + "parameters": [ + "out", + "in" + ], + "start_line": 5688, + "end_line": 5781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5791, + "end_line": 5837, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastTo", + "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 241, + "parameters": [ + "out", + "mp" + ], + "start_line": 5847, + "end_line": 5900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 31, + "token_count": 658, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5905, + "end_line": 6031, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 501, + "parameters": [ + "str" + ], + "start_line": 6035, + "end_line": 6143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 6147, + "end_line": 6187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 6191, + "end_line": 6329, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6333, + "end_line": 6376, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 21, + "token_count": 410, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6382, + "end_line": 6466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6471, + "end_line": 6474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ObjectType", + "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 69, + "parameters": [ + "op", + "minimum_type" + ], + "start_line": 6481, + "end_line": 6494, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6540, + "end_line": 6556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 84, + "parameters": [ + "op" + ], + "start_line": 6569, + "end_line": 6585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastSafely", + "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 39, + "token_count": 444, + "parameters": [ + "fromtype", + "totype" + ], + "start_line": 6591, + "end_line": 6679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 6684, + "end_line": 6712, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterNew", + "long_name": "PyArray_IterNew( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 269, + "parameters": [ + "obj" + ], + "start_line": 6725, + "end_line": 6763, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterAllButAxis", + "long_name": "PyArray_IterAllButAxis( PyObject * obj , int axis)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 88, + "parameters": [ + "obj", + "axis" + ], + "start_line": 6771, + "end_line": 6788, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_next", + "long_name": "arrayiter_next( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 48, + "parameters": [ + "it" + ], + "start_line": 6793, + "end_line": 6803, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_dealloc", + "long_name": "arrayiter_dealloc( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "it" + ], + "start_line": 6806, + "end_line": 6810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 6813, + "end_line": 6816, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_Bool", + "long_name": "iter_subscript_Bool( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 7, + "token_count": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6820, + "end_line": 6870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_int", + "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 52, + "complexity": 8, + "token_count": 352, + "parameters": [ + "self", + "ind" + ], + "start_line": 6873, + "end_line": 6927, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 6931, + "end_line": 7064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 134, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_Bool", + "long_name": "iter_ass_sub_Bool( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7068, + "end_line": 7100, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_int", + "long_name": "iter_ass_sub_int( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 8, + "token_count": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7103, + "end_line": 7145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 7148, + "end_line": 7282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "iter_array", + "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 214, + "parameters": [ + "it", + "op" + ], + "start_line": 7299, + "end_line": 7344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "iter_copy", + "long_name": "iter_copy( PyArrayIterObject * it , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "it", + "args" + ], + "start_line": 7349, + "end_line": 7353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7369, + "end_line": 7384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7449, + "end_line": 7465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Broadcast", + "long_name": "PyArray_Broadcast( PyArrayMultiIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 13, + "token_count": 464, + "parameters": [ + "mit" + ], + "start_line": 7472, + "end_line": 7541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterReset", + "long_name": "PyArray_MapIterReset( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7545, + "end_line": 7582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7588, + "end_line": 7632, + "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": 107, + "complexity": 23, + "token_count": 715, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7650, + "end_line": 7789, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 140, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7795, + "end_line": 7867, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 7870, + "end_line": 7996, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 8000, + "end_line": 8009, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiIterNew", + "long_name": "PyArray_MultiIterNew( int n , ...)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 10, + "token_count": 231, + "parameters": [ + "n" + ], + "start_line": 8080, + "end_line": 8129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_new", + "long_name": "arraymultiter_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 11, + "token_count": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8132, + "end_line": 8177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_next", + "long_name": "arraymultiter_next( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 111, + "parameters": [ + "multi" + ], + "start_line": 8180, + "end_line": 8199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_dealloc", + "long_name": "arraymultiter_dealloc( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 41, + "parameters": [ + "multi" + ], + "start_line": 8202, + "end_line": 8209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_size_get", + "long_name": "arraymultiter_size_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8212, + "end_line": 8222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_index_get", + "long_name": "arraymultiter_index_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8225, + "end_line": 8235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_shape_get", + "long_name": "arraymultiter_shape_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 8238, + "end_line": 8241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_iters_get", + "long_name": "arraymultiter_iters_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 8244, + "end_line": 8256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_reset", + "long_name": "arraymultiter_reset( PyArrayMultiIterObject * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 38, + "parameters": [ + "self", + "args" + ], + "start_line": 8286, + "end_line": 8293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewFromType", + "long_name": "PyArray_DescrNewFromType( int type_num)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 1, + "token_count": 37, + "parameters": [ + "type_num" + ], + "start_line": 8352, + "end_line": 8361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNew", + "long_name": "PyArray_DescrNew( PyArray_Descr * base)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 151, + "parameters": [ + "base" + ], + "start_line": 8379, + "end_line": 8401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_dealloc", + "long_name": "arraydescr_dealloc( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 8407, + "end_line": 8417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_subdescr_get", + "long_name": "arraydescr_subdescr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 8436, + "end_line": 8444, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8447, + "end_line": 8462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8465, + "end_line": 8487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8490, + "end_line": 8498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8501, + "end_line": 8508, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 8511, + "end_line": 8530, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isbuiltin_get", + "long_name": "arraydescr_isbuiltin_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 8537, + "end_line": 8544, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isnative_get", + "long_name": "arraydescr_isnative_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 8547, + "end_line": 8554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_fields_get", + "long_name": "arraydescr_fields_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 8557, + "end_line": 8564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_new", + "long_name": "arraydescr_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 272, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8612, + "end_line": 8664, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 8670, + "end_line": 8731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8739, + "end_line": 8781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewByteorder", + "long_name": "PyArray_DescrNewByteorder( PyArray_Descr * self , char newendian)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 386, + "parameters": [ + "self", + "newendian" + ], + "start_line": 8801, + "end_line": 8867, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_newbyteorder", + "long_name": "arraydescr_newbyteorder( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 47, + "parameters": [ + "self", + "args" + ], + "start_line": 8878, + "end_line": 8886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_str", + "long_name": "arraydescr_str( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 6, + "token_count": 287, + "parameters": [ + "self" + ], + "start_line": 8901, + "end_line": 8946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_repr", + "long_name": "arraydescr_repr( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 8949, + "end_line": 8958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_compare", + "long_name": "arraydescr_compare( PyArray_Descr * self , PyObject * other)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "other" + ], + "start_line": 8961, + "end_line": 8971, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 8978, + "end_line": 8985, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 8988, + "end_line": 9019, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFlagsObject", + "long_name": "PyArray_NewFlagsObject( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 3, + "token_count": 96, + "parameters": [ + "obj" + ], + "start_line": 9097, + "end_line": 9114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_dealloc", + "long_name": "arrayflags_dealloc( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 9117, + "end_line": 9121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_forc_get", + "long_name": "arrayflags_forc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 9145, + "end_line": 9157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_fnc_get", + "long_name": "arrayflags_fnc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9160, + "end_line": 9172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_farray_get", + "long_name": "arrayflags_farray_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 9175, + "end_line": 9188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_num_get", + "long_name": "arrayflags_num_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 9191, + "end_line": 9194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_updateifcopy_set", + "long_name": "arrayflags_updateifcopy_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9198, + "end_line": 9210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_aligned_set", + "long_name": "arrayflags_aligned_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9213, + "end_line": 9226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_writeable_set", + "long_name": "arrayflags_writeable_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9229, + "end_line": 9242, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_getitem", + "long_name": "arrayflags_getitem( PyArrayFlagsObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 75, + "complexity": 31, + "token_count": 431, + "parameters": [ + "self", + "ind" + ], + "start_line": 9298, + "end_line": 9373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_setitem", + "long_name": "arrayflags_setitem( PyArrayFlagsObject * self , PyObject * ind , PyObject * item)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 14, + "token_count": 219, + "parameters": [ + "self", + "ind", + "item" + ], + "start_line": 9376, + "end_line": 9396, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_torf_", + "long_name": "_torf_( int flags , int val)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 27, + "parameters": [ + "flags", + "val" + ], + "start_line": 9399, + "end_line": 9403, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_print", + "long_name": "arrayflags_print( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 1, + "token_count": 77, + "parameters": [ + "self" + ], + "start_line": 9406, + "end_line": 9418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_new", + "long_name": "arrayflags_new( PyTypeObject * self , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9433, + "end_line": 9445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 76, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 65, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 99, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 134, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 207, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 241, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 291, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 319, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 344, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 387, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 427, + "end_line": 509, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 516, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 593, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Size", + "long_name": "PyArray_Size( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 33, + "parameters": [ + "op" + ], + "start_line": 614, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 638, + "end_line": 718, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyObject", + "long_name": "PyArray_CopyObject( PyArrayObject * dest , PyObject * src_object)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 722, + "end_line": 736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDimsAndDataAndDescr", + "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 137, + "parameters": [ + "nd", + "d", + "descr", + "data" + ], + "start_line": 749, + "end_line": 775, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDims", + "long_name": "PyArray_FromDims( int nd , int * d , int type)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "nd", + "d", + "type" + ], + "start_line": 781, + "end_line": 795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewCopy", + "long_name": "PyArray_NewCopy( PyArrayObject * m1 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 804, + "end_line": 824, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 17, + "token_count": 616, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 833, + "end_line": 949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 965, + "end_line": 968, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Return", + "long_name": "PyArray_Return( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 91, + "parameters": [ + "mp" + ], + "start_line": 978, + "end_line": 1000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDataType", + "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 9, + "token_count": 229, + "parameters": [ + "type" + ], + "start_line": 1014, + "end_line": 1054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDescrForType", + "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 214, + "parameters": [ + "typenum", + "descr" + ], + "start_line": 1069, + "end_line": 1110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToFile", + "long_name": "PyArray_ToFile( PyArrayObject * self , FILE * fp , char * sep , char * format)", + "filename": "arrayobject.c", + "nloc": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1117, + "end_line": 1208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToList", + "long_name": "PyArray_ToList( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self" + ], + "start_line": 1214, + "end_line": 1243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToString", + "long_name": "PyArray_ToString( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 170, + "parameters": [ + "self" + ], + "start_line": 1246, + "end_line": 1282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_dealloc", + "long_name": "array_dealloc( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 1291, + "end_line": 1328, + "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": 1335, + "end_line": 1343, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_big_item", + "long_name": "array_big_item( PyArrayObject * self , intp i)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 4, + "token_count": 151, + "parameters": [ + "self", + "i" + ], + "start_line": 1346, + "end_line": 1371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , _int_or_ssize_t i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1374, + "end_line": 1377, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_ass_big_item", + "long_name": "array_ass_big_item( PyArrayObject * self , intp i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1380, + "end_line": 1415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , _int_or_ssize_t i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1428, + "end_line": 1431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "slice_coerce_index", + "long_name": "slice_coerce_index( PyObject * o , intp * v)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "o", + "v" + ], + "start_line": 1437, + "end_line": 1445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "slice_GetIndices", + "long_name": "slice_GetIndices( PySliceObject * r , intp length , intp * start , intp * stop , intp * step , intp * slicelength)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 24, + "token_count": 376, + "parameters": [ + "r", + "length", + "start", + "stop", + "step", + "slicelength" + ], + "start_line": 1451, + "end_line": 1501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "parse_subindex", + "long_name": "parse_subindex( PyObject * op , intp * step_size , intp * n_steps , intp max)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "step_size", + "n_steps", + "max" + ], + "start_line": 1508, + "end_line": 1553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "parse_index", + "long_name": "parse_index( PyArrayObject * self , PyObject * op , intp * dimensions , intp * strides , intp * offset_ptr)", + "filename": "arrayobject.c", + "nloc": 88, + "complexity": 20, + "token_count": 539, + "parameters": [ + "self", + "op", + "dimensions", + "strides", + "offset_ptr" + ], + "start_line": 1557, + "end_line": 1651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "_swap_axes", + "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1654, + "end_line": 1691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1703, + "end_line": 1756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetMap", + "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 53, + "complexity": 12, + "token_count": 382, + "parameters": [ + "mit", + "op" + ], + "start_line": 1759, + "end_line": 1819, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 0 + }, + { + "name": "count_new_axes_0d", + "long_name": "count_new_axes_0d( PyObject * tuple)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 7, + "token_count": 124, + "parameters": [ + "tuple" + ], + "start_line": 1822, + "end_line": 1849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "add_new_axes_0d", + "long_name": "add_new_axes_0d( PyArrayObject * arr , int newaxis_count)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 121, + "parameters": [ + "arr", + "newaxis_count" + ], + "start_line": 1852, + "end_line": 1871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 1883, + "end_line": 1945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 107, + "complexity": 28, + "token_count": 674, + "parameters": [ + "self", + "op" + ], + "start_line": 1969, + "end_line": 2094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2109, + "end_line": 2214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 10, + "token_count": 182, + "parameters": [ + "self", + "op" + ], + "start_line": 2223, + "end_line": 2262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , _int_or_ssize_t * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2285, + "end_line": 2297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2300, + "end_line": 2315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2319, + "end_line": 2328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , _int_or_ssize_t segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2331, + "end_line": 2342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 1, + "token_count": 182, + "parameters": [ + "dict" + ], + "start_line": 2420, + "end_line": 2457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 2, + "token_count": 203, + "parameters": [], + "start_line": 2467, + "end_line": 2510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2513, + "end_line": 2536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericAccumulateFunction", + "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2540, + "end_line": 2563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericBinaryFunction", + "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 44, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2567, + "end_line": 2574, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericUnaryFunction", + "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 38, + "parameters": [ + "m1", + "op" + ], + "start_line": 2577, + "end_line": 2584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceBinaryFunction", + "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 46, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2587, + "end_line": 2595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceUnaryFunction", + "long_name": "PyArray_GenericInplaceUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 40, + "parameters": [ + "m1", + "op" + ], + "start_line": 2598, + "end_line": 2605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2608, + "end_line": 2611, + "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": 2614, + "end_line": 2617, + "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": 2620, + "end_line": 2623, + "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": 2626, + "end_line": 2629, + "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": 2632, + "end_line": 2635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power_is_scalar", + "long_name": "array_power_is_scalar( PyObject * o2 , double * exp)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 132, + "parameters": [ + "o2", + "exp" + ], + "start_line": 2642, + "end_line": 2665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "fast_scalar_power", + "long_name": "fast_scalar_power( PyArrayObject * a1 , PyObject * o2 , int inplace)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 12, + "token_count": 181, + "parameters": [ + "a1", + "o2", + "inplace" + ], + "start_line": 2669, + "end_line": 2703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2706, + "end_line": 2715, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2719, + "end_line": 2722, + "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": 2725, + "end_line": 2728, + "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": 2731, + "end_line": 2734, + "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": 2737, + "end_line": 2740, + "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": 2743, + "end_line": 2746, + "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": 2749, + "end_line": 2752, + "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": 2755, + "end_line": 2758, + "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": 2761, + "end_line": 2764, + "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": 2767, + "end_line": 2770, + "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": 2773, + "end_line": 2776, + "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": 2779, + "end_line": 2782, + "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": 2785, + "end_line": 2788, + "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": 2791, + "end_line": 2794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2797, + "end_line": 2806, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2809, + "end_line": 2812, + "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": 2815, + "end_line": 2818, + "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": 2821, + "end_line": 2824, + "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": 2827, + "end_line": 2830, + "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": 2833, + "end_line": 2836, + "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": 2839, + "end_line": 2842, + "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": 2845, + "end_line": 2848, + "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": 2851, + "end_line": 2855, + "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": 2858, + "end_line": 2862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_any_nonzero", + "long_name": "array_any_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 95, + "parameters": [ + "mp" + ], + "start_line": 2866, + "end_line": 2884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_array_nonzero", + "long_name": "_array_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 3, + "token_count": 72, + "parameters": [ + "mp" + ], + "start_line": 2887, + "end_line": 2904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_divmod", + "long_name": "array_divmod( PyArrayObject * op1 , PyObject * op2)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 89, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2909, + "end_line": 2924, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_int", + "long_name": "array_int( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2928, + "end_line": 2954, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_float", + "long_name": "array_float( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2957, + "end_line": 2982, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_long", + "long_name": "array_long( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 2985, + "end_line": 3007, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_oct", + "long_name": "array_oct( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3010, + "end_line": 3032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_hex", + "long_name": "array_hex( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3035, + "end_line": 3057, + "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": 3060, + "end_line": 3064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 12, + "token_count": 268, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 3125, + "end_line": 3166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 3170, + "end_line": 3192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 3195, + "end_line": 3207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dump_data", + "long_name": "dump_data( char ** string , int * n , int * max_n , char * data , int nd , intp * dimensions , intp * strides , PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 7, + "token_count": 310, + "parameters": [ + "string", + "n", + "max_n", + "data", + "nd", + "dimensions", + "strides", + "self" + ], + "start_line": 3240, + "end_line": 3287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_repr_builtin", + "long_name": "array_repr_builtin( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 4, + "token_count": 224, + "parameters": [ + "self" + ], + "start_line": 3290, + "end_line": 3326, + "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": 3335, + "end_line": 3352, + "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": 3355, + "end_line": 3367, + "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": 3370, + "end_line": 3382, + "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": 90, + "complexity": 19, + "token_count": 392, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3385, + "end_line": 3491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 171, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3494, + "end_line": 3523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntTupleFromIntp", + "long_name": "PyArray_IntTupleFromIntp( int len , intp * vals)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 109, + "parameters": [ + "len", + "vals" + ], + "start_line": 3529, + "end_line": 3549, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3557, + "end_line": 3592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3598, + "end_line": 3617, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 3621, + "end_line": 3639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 3642, + "end_line": 3659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_IsWriteable", + "long_name": "_IsWriteable( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 107, + "parameters": [ + "ap" + ], + "start_line": 3662, + "end_line": 3695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_UpdateFlags", + "long_name": "PyArray_UpdateFlags( PyArrayObject * ret , int flagmask)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 11, + "token_count": 157, + "parameters": [ + "ret", + "flagmask" + ], + "start_line": 3702, + "end_line": 3729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 117, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 3749, + "end_line": 3769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 3789, + "end_line": 3813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_New", + "long_name": "PyArray_New( PyTypeObject * subtype , int nd , intp * dims , int type_num , intp * strides , * data , int itemsize , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 4, + "token_count": 128, + "parameters": [ + "subtype", + "nd", + "dims", + "type_num", + "strides", + "data", + "itemsize", + "flags", + "obj" + ], + "start_line": 3819, + "end_line": 3841, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd , int isfortran)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 10, + "token_count": 311, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd", + "isfortran" + ], + "start_line": 3852, + "end_line": 3914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 132, + "complexity": 29, + "token_count": 785, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3922, + "end_line": 4088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 167, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape , int refcheck)", + "filename": "arrayobject.c", + "nloc": 83, + "complexity": 16, + "token_count": 511, + "parameters": [ + "self", + "newshape", + "refcheck" + ], + "start_line": 4101, + "end_line": 4200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 100, + "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": 4206, + "end_line": 4223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 8, + "token_count": 279, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4227, + "end_line": 4277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 21, + "token_count": 620, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4280, + "end_line": 4411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 132, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4415, + "end_line": 4423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ndim_get", + "long_name": "array_ndim_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4429, + "end_line": 4432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flags_get", + "long_name": "array_flags_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 4435, + "end_line": 4438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_get", + "long_name": "array_shape_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4441, + "end_line": 4444, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_set", + "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4448, + "end_line": 4477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "array_strides_get", + "long_name": "array_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4481, + "end_line": 4484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 9, + "token_count": 304, + "parameters": [ + "self", + "obj" + ], + "start_line": 4487, + "end_line": 4541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4545, + "end_line": 4552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4555, + "end_line": 4561, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4565, + "end_line": 4571, + "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": 4574, + "end_line": 4588, + "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": 4591, + "end_line": 4635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_itemsize_get", + "long_name": "array_itemsize_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 4639, + "end_line": 4642, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_size_get", + "long_name": "array_size_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4645, + "end_line": 4656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nbytes_get", + "long_name": "array_nbytes_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4659, + "end_line": 4670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4676, + "end_line": 4679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_descr_get", + "long_name": "array_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 4682, + "end_line": 4686, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "arg" + ], + "start_line": 4700, + "end_line": 4787, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 4790, + "end_line": 4808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_struct_get", + "long_name": "array_struct_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 2, + "token_count": 130, + "parameters": [ + "self" + ], + "start_line": 4811, + "end_line": 4829, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 4832, + "end_line": 4842, + "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": 4846, + "end_line": 4871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_real_set", + "long_name": "array_real_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 4, + "token_count": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 4875, + "end_line": 4908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_get", + "long_name": "array_imag_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self" + ], + "start_line": 4911, + "end_line": 4944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 4947, + "end_line": 4984, + "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": 4987, + "end_line": 4990, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flat_set", + "long_name": "array_flat_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 9, + "token_count": 348, + "parameters": [ + "self", + "val" + ], + "start_line": 4993, + "end_line": 5043, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_alloc", + "long_name": "array_alloc( PyTypeObject * type , int nitems)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 1, + "token_count": 39, + "parameters": [ + "type", + "nitems" + ], + "start_line": 5133, + "end_line": 5140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "discover_depth", + "long_name": "discover_depth( PyObject * s , int max , int stop_at_string , int stop_at_tuple)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 19, + "token_count": 243, + "parameters": [ + "s", + "max", + "stop_at_string", + "stop_at_tuple" + ], + "start_line": 5228, + "end_line": 5261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5264, + "end_line": 5286, + "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": 5293, + "end_line": 5319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_array_small_type", + "long_name": "_array_small_type( PyArray_Descr * chktype , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 169, + "parameters": [ + "chktype", + "mintype" + ], + "start_line": 5325, + "end_line": 5357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_python_scalar_type", + "long_name": "_array_find_python_scalar_type( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 8, + "token_count": 120, + "parameters": [ + "op" + ], + "start_line": 5360, + "end_line": 5383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 28, + "token_count": 634, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5395, + "end_line": 5525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "Assign_Array", + "long_name": "Assign_Array( PyArrayObject * self , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 121, + "parameters": [ + "self", + "v" + ], + "start_line": 5528, + "end_line": 5551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 189, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5556, + "end_line": 5594, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 24, + "token_count": 373, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5599, + "end_line": 5666, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 68, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 5673, + "end_line": 5682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_bufferedcast", + "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 18, + "token_count": 525, + "parameters": [ + "out", + "in" + ], + "start_line": 5688, + "end_line": 5781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5791, + "end_line": 5837, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastTo", + "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 241, + "parameters": [ + "out", + "mp" + ], + "start_line": 5847, + "end_line": 5900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 31, + "token_count": 658, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5905, + "end_line": 6031, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 501, + "parameters": [ + "str" + ], + "start_line": 6035, + "end_line": 6143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 6147, + "end_line": 6187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 6191, + "end_line": 6329, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6333, + "end_line": 6376, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 21, + "token_count": 410, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6382, + "end_line": 6466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6471, + "end_line": 6474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ObjectType", + "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 69, + "parameters": [ + "op", + "minimum_type" + ], + "start_line": 6481, + "end_line": 6494, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6540, + "end_line": 6556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 84, + "parameters": [ + "op" + ], + "start_line": 6569, + "end_line": 6585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastSafely", + "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 39, + "token_count": 444, + "parameters": [ + "fromtype", + "totype" + ], + "start_line": 6591, + "end_line": 6679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 6684, + "end_line": 6712, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterNew", + "long_name": "PyArray_IterNew( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 269, + "parameters": [ + "obj" + ], + "start_line": 6725, + "end_line": 6763, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterAllButAxis", + "long_name": "PyArray_IterAllButAxis( PyObject * obj , int axis)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 88, + "parameters": [ + "obj", + "axis" + ], + "start_line": 6771, + "end_line": 6788, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_next", + "long_name": "arrayiter_next( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 48, + "parameters": [ + "it" + ], + "start_line": 6793, + "end_line": 6803, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_dealloc", + "long_name": "arrayiter_dealloc( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "it" + ], + "start_line": 6806, + "end_line": 6810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 6813, + "end_line": 6816, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_Bool", + "long_name": "iter_subscript_Bool( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 7, + "token_count": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6820, + "end_line": 6870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_int", + "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 52, + "complexity": 8, + "token_count": 352, + "parameters": [ + "self", + "ind" + ], + "start_line": 6873, + "end_line": 6927, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 6931, + "end_line": 7064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 134, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_Bool", + "long_name": "iter_ass_sub_Bool( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7068, + "end_line": 7100, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_int", + "long_name": "iter_ass_sub_int( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 8, + "token_count": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7103, + "end_line": 7145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 7148, + "end_line": 7282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "iter_array", + "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 214, + "parameters": [ + "it", + "op" + ], + "start_line": 7299, + "end_line": 7344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "iter_copy", + "long_name": "iter_copy( PyArrayIterObject * it , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "it", + "args" + ], + "start_line": 7349, + "end_line": 7353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7369, + "end_line": 7384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7449, + "end_line": 7465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Broadcast", + "long_name": "PyArray_Broadcast( PyArrayMultiIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 13, + "token_count": 464, + "parameters": [ + "mit" + ], + "start_line": 7472, + "end_line": 7541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterReset", + "long_name": "PyArray_MapIterReset( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7545, + "end_line": 7582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7588, + "end_line": 7632, + "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": 107, + "complexity": 23, + "token_count": 715, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7650, + "end_line": 7789, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 140, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7795, + "end_line": 7867, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 7870, + "end_line": 7996, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 8000, + "end_line": 8009, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiIterNew", + "long_name": "PyArray_MultiIterNew( int n , ...)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 10, + "token_count": 231, + "parameters": [ + "n" + ], + "start_line": 8080, + "end_line": 8129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_new", + "long_name": "arraymultiter_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 11, + "token_count": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8132, + "end_line": 8177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_next", + "long_name": "arraymultiter_next( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 111, + "parameters": [ + "multi" + ], + "start_line": 8180, + "end_line": 8199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_dealloc", + "long_name": "arraymultiter_dealloc( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 41, + "parameters": [ + "multi" + ], + "start_line": 8202, + "end_line": 8209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_size_get", + "long_name": "arraymultiter_size_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8212, + "end_line": 8222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_index_get", + "long_name": "arraymultiter_index_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8225, + "end_line": 8235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_shape_get", + "long_name": "arraymultiter_shape_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 8238, + "end_line": 8241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_iters_get", + "long_name": "arraymultiter_iters_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 8244, + "end_line": 8256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_reset", + "long_name": "arraymultiter_reset( PyArrayMultiIterObject * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 38, + "parameters": [ + "self", + "args" + ], + "start_line": 8286, + "end_line": 8293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewFromType", + "long_name": "PyArray_DescrNewFromType( int type_num)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 1, + "token_count": 37, + "parameters": [ + "type_num" + ], + "start_line": 8352, + "end_line": 8361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNew", + "long_name": "PyArray_DescrNew( PyArray_Descr * base)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 151, + "parameters": [ + "base" + ], + "start_line": 8379, + "end_line": 8401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_dealloc", + "long_name": "arraydescr_dealloc( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 8407, + "end_line": 8417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_subdescr_get", + "long_name": "arraydescr_subdescr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 8436, + "end_line": 8444, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8447, + "end_line": 8462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8465, + "end_line": 8487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8490, + "end_line": 8498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8501, + "end_line": 8508, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 8511, + "end_line": 8530, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isbuiltin_get", + "long_name": "arraydescr_isbuiltin_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 8537, + "end_line": 8544, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isnative_get", + "long_name": "arraydescr_isnative_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 8547, + "end_line": 8554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_fields_get", + "long_name": "arraydescr_fields_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 8557, + "end_line": 8564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_new", + "long_name": "arraydescr_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 272, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8612, + "end_line": 8664, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 8670, + "end_line": 8731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8739, + "end_line": 8781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewByteorder", + "long_name": "PyArray_DescrNewByteorder( PyArray_Descr * self , char newendian)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 386, + "parameters": [ + "self", + "newendian" + ], + "start_line": 8801, + "end_line": 8867, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_newbyteorder", + "long_name": "arraydescr_newbyteorder( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 47, + "parameters": [ + "self", + "args" + ], + "start_line": 8878, + "end_line": 8886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_str", + "long_name": "arraydescr_str( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 6, + "token_count": 287, + "parameters": [ + "self" + ], + "start_line": 8901, + "end_line": 8946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_repr", + "long_name": "arraydescr_repr( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 8949, + "end_line": 8958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_compare", + "long_name": "arraydescr_compare( PyArray_Descr * self , PyObject * other)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "other" + ], + "start_line": 8961, + "end_line": 8971, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 8978, + "end_line": 8985, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 8988, + "end_line": 9019, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFlagsObject", + "long_name": "PyArray_NewFlagsObject( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 3, + "token_count": 96, + "parameters": [ + "obj" + ], + "start_line": 9097, + "end_line": 9114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_dealloc", + "long_name": "arrayflags_dealloc( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 9117, + "end_line": 9121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_forc_get", + "long_name": "arrayflags_forc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 9145, + "end_line": 9157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_fnc_get", + "long_name": "arrayflags_fnc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9160, + "end_line": 9172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_farray_get", + "long_name": "arrayflags_farray_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 9175, + "end_line": 9188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_num_get", + "long_name": "arrayflags_num_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 9191, + "end_line": 9194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_updateifcopy_set", + "long_name": "arrayflags_updateifcopy_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9198, + "end_line": 9210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_aligned_set", + "long_name": "arrayflags_aligned_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9213, + "end_line": 9226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_writeable_set", + "long_name": "arrayflags_writeable_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9229, + "end_line": 9242, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_getitem", + "long_name": "arrayflags_getitem( PyArrayFlagsObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 75, + "complexity": 31, + "token_count": 431, + "parameters": [ + "self", + "ind" + ], + "start_line": 9298, + "end_line": 9373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_setitem", + "long_name": "arrayflags_setitem( PyArrayFlagsObject * self , PyObject * ind , PyObject * item)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 14, + "token_count": 219, + "parameters": [ + "self", + "ind", + "item" + ], + "start_line": 9376, + "end_line": 9396, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_torf_", + "long_name": "_torf_( int flags , int val)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 27, + "parameters": [ + "flags", + "val" + ], + "start_line": 9399, + "end_line": 9403, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_print", + "long_name": "arrayflags_print( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 1, + "token_count": 77, + "parameters": [ + "self" + ], + "start_line": 9406, + "end_line": 9418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_new", + "long_name": "arrayflags_new( PyTypeObject * self , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9433, + "end_line": 9445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "PyArray_FromDims", + "long_name": "PyArray_FromDims( int nd , int * d , int type)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "nd", + "d", + "type" + ], + "start_line": 781, + "end_line": 795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + } + ], + "nloc": 7540, + "complexity": 1626, + "token_count": 43765, + "diff_parsed": { + "added": [ + "\t}" + ], + "deleted": [ + "\t}" + ] + } + }, + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -1,5 +1,7 @@\n /* The purpose of this module is to add faster math for array scalars\n- that does not go through the ufunc machinery\n+ that does not go through the ufunc machinery \n+\n+ but still supports error-modes. \n \n NOT FINISHED\n */\n@@ -8,9 +10,152 @@\n #include \"numpy/ufuncobject.h\"\n \n \n+/**end repeat**/\n+\n+\n /**begin repeat\n-name=bool,\n+#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n+**/\n+\n+static PyObject *\n+@name@_add(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_subtract(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_multiply(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_divide(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_remainder(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_divmod(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_power(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_negative(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_copy(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_absolute(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_nonzero_number(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_invert(PyObject *a, PyObject *b)\n+{\n+}\n \n+static PyObject *\n+@name@_lshift(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_rshift(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_and(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_xor(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_or(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_int(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_long(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_float(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_oct(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_hex(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_floor_divide(PyObject *a, PyObject *b)\n+{\n+}\n+\n+static PyObject *\n+@name@_true_divide(PyObject *a, PyObject *b)\n+{\n+}\n+\n+#if PY_VERSION_HEX >= 0x02050000\n+static Py_ssize_t\n+@name@_index(PyObject *a)\n+{\n+}\n+#endif\n+\n+\n+static PyObject*\n+@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n+{\n+}\n+/**end repeat**/\n+\n+\n+\n+\n+/**begin repeat\n+#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n **/\n static PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n@@ -51,30 +196,17 @@ static PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n-\n+#if PY_VERSION_HEX >= 0x02050000\n+\t(lenfunc)@name@_index, /*nb_index*/\n+#endif\n };\n \n-/**end repeat**/\n-\n-\n-/**begin repeat\n-\n-**/\n-\n-static PyObject*\n-@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n-{\n-}\n-/**end repeat**/\n-\n-\n-\n static void\n add_scalarmath(void)\n {\n /**begin repeat\n-name=bool,\n-NAME=Bool\n+#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n+#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n \tPyArr@NAME@Type_Type.tp_as_number = @name@_as_number;\n \tPyArr@NAME@Type_Type.tp_richcompare = @name@_richcompare;\n", + "added_lines": 152, + "deleted_lines": 20, + "source_code": "/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n */\n\n#include \"numpy/arrayobject.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n/**end repeat**/\n\n\n/**begin repeat\n#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n\nstatic PyObject *\n@name@_add(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_subtract(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_multiply(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_divide(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_remainder(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_divmod(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_negative(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_copy(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_absolute(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_nonzero_number(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_invert(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_lshift(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_rshift(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_and(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_xor(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_or(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_int(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_long(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_float(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_oct(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_hex(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_floor_divide(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_true_divide(PyObject *a, PyObject *b)\n{\n}\n\n#if PY_VERSION_HEX >= 0x02050000\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n}\n#endif\n\n\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n}\n/**end repeat**/\n\n\n\n\n/**begin repeat\n#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_copy, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero_number, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n\t(lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n\nstatic void\nadd_scalarmath(void)\n{\n/**begin repeat\n#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n**/\n\tPyArr@NAME@Type_Type.tp_as_number = @name@_as_number;\n\tPyArr@NAME@Type_Type.tp_richcompare = @name@_richcompare;\n/**end repeat**/\n}\n\n\n\nstatic struct PyMethodDef methods[] = {\n\t{\"alter_pyscalars\", (PyCFunction) alter_pyscalars,\n\t METH_VARARGS , doc_alterpyscalars},\n\t{NULL, NULL, 0}\n};\n\nDL_EXPORT(void) initscalarmath(void) {\n\tPyObject *m;\n\n\tm = Py_initModule(\"scalarmath\", methods);\n\t\n\tif (import_array() < 0) return;\n\tif (import_umath() < 0) return;\n\n\tadd_scalarmath();\n\t\n\treturn;\n}\n", + "source_code_before": "/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery\n\n NOT FINISHED\n */\n\n#include \"numpy/arrayobject.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n/**begin repeat\nname=bool,\n\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_copy, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero_number, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n\n};\n\n/**end repeat**/\n\n\n/**begin repeat\n\n**/\n\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n}\n/**end repeat**/\n\n\n\nstatic void\nadd_scalarmath(void)\n{\n/**begin repeat\nname=bool,\nNAME=Bool\n**/\n\tPyArr@NAME@Type_Type.tp_as_number = @name@_as_number;\n\tPyArr@NAME@Type_Type.tp_richcompare = @name@_richcompare;\n/**end repeat**/\n}\n\n\n\nstatic struct PyMethodDef methods[] = {\n\t{\"alter_pyscalars\", (PyCFunction) alter_pyscalars,\n\t METH_VARARGS , doc_alterpyscalars},\n\t{NULL, NULL, 0}\n};\n\nDL_EXPORT(void) initscalarmath(void) {\n\tPyObject *m;\n\n\tm = Py_initModule(\"scalarmath\", methods);\n\t\n\tif (import_array() < 0) return;\n\tif (import_umath() < 0) return;\n\n\tadd_scalarmath();\n\t\n\treturn;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + " that does not go through the ufunc machinery", + "", + " but still supports error-modes.", + "/**end repeat**/", + "", + "", + "#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#", + "**/", + "", + "static PyObject *", + "@name@_add(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_subtract(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_multiply(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_divide(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_remainder(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_divmod(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_power(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_negative(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_copy(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_absolute(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_nonzero_number(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_invert(PyObject *a, PyObject *b)", + "{", + "}", + "static PyObject *", + "@name@_lshift(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_rshift(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_and(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_xor(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_or(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_int(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_long(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_float(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_oct(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_hex(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_floor_divide(PyObject *a, PyObject *b)", + "{", + "}", + "", + "static PyObject *", + "@name@_true_divide(PyObject *a, PyObject *b)", + "{", + "}", + "", + "#if PY_VERSION_HEX >= 0x02050000", + "static Py_ssize_t", + "@name@_index(PyObject *a)", + "{", + "}", + "#endif", + "", + "", + "static PyObject*", + "@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)", + "{", + "}", + "/**end repeat**/", + "", + "", + "", + "", + "/**begin repeat", + "#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#", + "#if PY_VERSION_HEX >= 0x02050000", + "\t(lenfunc)@name@_index, /*nb_index*/", + "#endif", + "#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#", + "#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#" + ], + "deleted": [ + " that does not go through the ufunc machinery", + "name=bool,", + "", + "/**end repeat**/", + "", + "", + "/**begin repeat", + "", + "**/", + "", + "static PyObject*", + "@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)", + "{", + "}", + "/**end repeat**/", + "", + "", + "", + "name=bool,", + "NAME=Bool" + ] + } + }, + { + "old_path": "numpy/core/src/scalartypes.inc.src", + "new_path": "numpy/core/src/scalartypes.inc.src", + "filename": "scalartypes.inc.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -1,33 +1,14 @@\n /* -*- c -*- */\n \n+#ifndef _MULTIARRAYMODULE\n+#define _MULTIARRAYMODULE\n+#endif\n+#include \"numpy/arrayscalars.h\"\n static int PyArrayScalar_Offset[PyArray_NTYPES+1];\n-/* to be exposed in C-API */\n-#define PyArrayScalar_False ((PyObject *)&_PyArrayScalar_BoolValues[0])\n-#define PyArrayScalar_True ((PyObject *)&_PyArrayScalar_BoolValues[1])\n-#define PyArrayScalar_RETURN_BOOL_FROM_LONG(i)\t\t\t\\\n-\treturn Py_INCREF(&_PyArrayScalar_BoolValues[((i)!=0)]),\t\\\n-\t\t(PyObject *)&_PyArrayScalar_BoolValues[((i)!=0)]\n-#define PyArrayScalar_RETURN_FALSE\t\t\\\n-\treturn Py_INCREF(PyArrayScalar_False),\t\\\n-\t\tPyArrayScalar_False\n-#define PyArrayScalar_RETURN_TRUE\t\t\\\n-\treturn Py_INCREF(PyArrayScalar_True),\t\\\n-\t\tPyArrayScalar_True\n-/* end to be exposed in C-API */\n \n #define _SOFFSET_(obj, type_num) ((char *)(obj) + PyArrayScalar_Offset[(type_num)])\n \n-/**begin repeat\n-#name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,#\n-#type=Bool, signed char, short, int, long, longlong, unsigned char, unsigned short, unsigned int, unsigned long, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, PyObject *,char#\n-*/\n-typedef struct {\n-\tPyObject_HEAD\n-\t@type@ obval;\n-} Py@name@ScalarObject;\n-/**end repeat**/\n-\n-static PyBoolScalarObject _PyArrayScalar_BoolValues[] = {\n+static PyBoolScalarObject _PyArrayScalar_BoolValues[2] = {\n \t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 0},\n \t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 1},\n };\n@@ -51,17 +32,6 @@ static PyTypeObject Py@NAME@ArrType_Type = {\n /**end repeat**/\n \n \n-#define PyStringScalarObject PyStringObject\n-#define PyUnicodeScalarObject PyUnicodeObject\n-\n-typedef struct {\n-\tPyObject_VAR_HEAD\n-\tchar *obval;\n-\tPyArray_Descr *descr;\n-\tint flags;\n-\tPyObject *base;\n-} PyVoidScalarObject;\n-\n /* no error checking is performed -- ctypeptr must be same type as scalar */\n /* in case of flexible type, the data is not copied \n into ctypeptr which is expected to be a pointer to pointer */\n@@ -1658,9 +1628,9 @@ bool_arrtype_nonzero(PyObject *a)\n \n /* Arithmetic methods -- only so we can override &, |, ^. */\n static PyNumberMethods bool_arrtype_as_number = {\n-\t0,\t\t\t\t\t/* nb_add */\n+\tbool_arrtype_or,\t\t\t/* nb_add */\n \t0,\t\t\t\t\t/* nb_subtract */\n-\t0,\t\t\t\t\t/* nb_multiply */\n+\tbool_arrtype_and,\t\t\t/* nb_multiply */\n \t0,\t\t\t\t\t/* nb_divide */\n \t0,\t\t\t\t\t/* nb_remainder */\n \t0,\t\t\t\t\t/* nb_divmod */\n", + "added_lines": 7, + "deleted_lines": 37, + "source_code": "/* -*- c -*- */\n\n#ifndef _MULTIARRAYMODULE\n#define _MULTIARRAYMODULE\n#endif\n#include \"numpy/arrayscalars.h\"\nstatic int PyArrayScalar_Offset[PyArray_NTYPES+1];\n\n#define _SOFFSET_(obj, type_num) ((char *)(obj) + PyArrayScalar_Offset[(type_num)])\n\nstatic PyBoolScalarObject _PyArrayScalar_BoolValues[2] = {\n\t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 0},\n\t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 1},\n};\n\n/* Inheritance established later when tp_bases is set (or tp_base for \n single inheritance) */\n\n/**begin repeat\n\n#name=number, integer, signedinteger, unsignedinteger, inexact, floating, complexfloating, flexible, \ncharacter#\n#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating, ComplexFloating, Flexible, Character#\n*/\n\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@scalar\",\t\t /*tp_name*/\n sizeof(PyObject),\t\t /*tp_basicsize*/\n};\n/**end repeat**/\n\n\n/* no error checking is performed -- ctypeptr must be same type as scalar */\n/* in case of flexible type, the data is not copied \n into ctypeptr which is expected to be a pointer to pointer */\n/*OBJECT_API\n Convert to c-type\n*/\nstatic void\nPyArray_ScalarAsCtype(PyObject *scalar, void *ctypeptr)\n{\n\tPyArray_Descr *typecode;\n\ttypecode = PyArray_DescrFromScalar(scalar);\n\t\n\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\tvoid **newptr = (void **)ctypeptr;\n\t\tswitch(typecode->type_num) {\n\t\tcase PyArray_STRING:\n\t\t\t*newptr = (void *)PyString_AS_STRING(scalar);\n break;\n\t\tcase PyArray_UNICODE:\n\t\t\t*newptr = (void *)PyUnicode_AS_DATA(scalar);\n break;\n\t\tdefault:\n\t\t\t*newptr = ((PyVoidScalarObject *)scalar)->obval;\n break;\n\t\t}\n\t\treturn;\n\t}\n\tmemcpy(ctypeptr, _SOFFSET_(scalar, typecode->type_num),\n\t typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn;\n}\n\n/* The output buffer must be large-enough to receive the value */\n/* Even for flexible types which is different from ScalarAsCtype\n where only a reference for flexible types is returned \n*/\n\n/*OBJECT_API\n Cast Scalar to c-type\n*/\nstatic int\nPyArray_CastScalarToCtype(PyObject *scalar, void *ctypeptr, \n\t\t\t PyArray_Descr *outcode)\n{\n\tPyArray_Descr* descr;\n\t\n\tdescr = PyArray_DescrFromScalar(scalar);\n\tif (PyTypeNum_ISEXTENDED(descr->type_num) ||\n\t PyTypeNum_ISEXTENDED(outcode->type_num)) {\n\t\tPyArrayObject *ain, *aout;\n\n\t\tain = (PyArrayObject *)PyArray_FromScalar(scalar, NULL);\n\t\tif (ain == NULL) {Py_DECREF(descr); return -1;}\n\t\taout = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t outcode,\n\t\t\t\t\t 0, NULL, \n\t\t\t\t\t NULL, ctypeptr, \n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\t\tif (aout == NULL) {Py_DECREF(ain); return -1;}\n\t\tdescr->f->cast[outcode->type_num](ain->data, \n\t\t\t\t\t aout->data, 1, ain, aout);\n\t\tPy_DECREF(ain);\n\t\tPy_DECREF(aout);\n\t}\n\telse {\n\t\tdescr->f->cast[outcode->type_num](_SOFFSET_(scalar, \n\t\t\t\t\t\t\t descr->type_num), \n\t\t\t\t\t ctypeptr, 1, NULL, NULL);\n\t}\n\tPy_DECREF(descr);\n\treturn 0;\n}\n\n/* 0-dim array from array-scalar object */\n/* always contains a copy of the data \n unless outcode is NULL, it is of void type and the referrer does\n not own it either.\n*/\n\n/* steals reference to outcode */\n/*OBJECT_API\n Get 0-dim array from scalar\n*/\nstatic PyObject *\nPyArray_FromScalar(PyObject *scalar, PyArray_Descr *outcode)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *r;\n\tchar *memptr;\n\tPyObject *ret;\n\n\t/* convert to 0-dim array of scalar typecode */\n\ttypecode = PyArray_DescrFromScalar(scalar);\n\tif ((typecode->type_num == PyArray_VOID) &&\t\t\t\\\n\t !(((PyVoidScalarObject *)scalar)->flags & OWNDATA) &&\t\\\n\t outcode == NULL) {\n\t\tr = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t typecode,\n\t\t\t\t\t 0, NULL, NULL,\n\t\t\t\t\t ((PyVoidScalarObject *)scalar)->obval,\n\t\t\t\t\t ((PyVoidScalarObject *)scalar)->flags,\n\t\t\t\t\t NULL);\n\t\tPyArray_BASE(r) = (PyObject *)scalar;\n\t\tPy_INCREF(scalar);\n\t\treturn r;\n\t}\n\tr = PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t typecode,\n\t\t\t\t 0, NULL, \n\t\t\t\t NULL, NULL, 0, NULL);\n\tif (r==NULL) {Py_XDECREF(outcode); return NULL;}\n\n\tswitch(typecode->type_num) {\n\tcase PyArray_STRING:\n\t\tmemptr = PyString_AS_STRING(scalar);\n\t\tbreak;\n\tcase PyArray_UNICODE:\n\t\tmemptr = (char *)PyUnicode_AS_DATA(scalar);\n#ifdef Py_UNICODE_WIDE\n\t\tbreak;\n#else\n\t\tPyUCS2Buffer_AsUCS4((Py_UNICODE *)memptr, \n\t\t\t\t (PyArray_UCS4 *)PyArray_DATA(r),\n\t\t\t\t PyUnicode_GET_SIZE(scalar),\n\t\t\t\t PyArray_ITEMSIZE(r) >> 2);\n goto finish;\n#endif\n\tdefault:\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tmemptr = (((PyVoidScalarObject *)scalar)->obval);\n\t\t}\n\t\telse {\n\t\t\tmemptr = _SOFFSET_(scalar, typecode->type_num);\n\t\t}\n\t\tbreak;\n\t}\n\n\tmemcpy(PyArray_DATA(r), memptr, PyArray_ITEMSIZE(r));\n\tif (PyArray_ISOBJECT(r)) {\n\t\tPy_INCREF(*((PyObject **)memptr));\n\t}\n#ifndef Py_UNICODE_WIDE\n finish:\t\n#endif\n\tif (outcode == NULL) return r;\n\t\n\tif (outcode->type_num == typecode->type_num) {\n\t\tif (!PyTypeNum_ISEXTENDED(typecode->type_num))\n\t\t\treturn r;\n\t\tif (outcode->elsize == typecode->elsize);\n\t\treturn r;\t\t\t\n\t}\n\t\n\t/* cast if necessary to desired output typecode */\n\tret = PyArray_CastToType((PyArrayObject *)r, outcode, 0);\n\tPy_DECREF(r);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n const size_t size = _PyObject_VAR_SIZE(type, nitems+1);\n\n obj = (PyObject *)_pya_malloc(size);\n\tmemset(obj, 0, size);\n\tif (type->tp_itemsize == 0)\n PyObject_INIT(obj, type);\n else\n (void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems);\n return obj;\n}\n\nstatic void\ngentype_dealloc(PyObject *v) \n{\n\tv->ob_type->tp_free(v);\n}\n\n\nstatic PyObject *\ngentype_power(PyObject *m1, PyObject *m2, PyObject *m3)\n{\n\tPyObject *arr, *ret, *arg2;\n\tchar *msg=\"unsupported operand type(s) for ** or pow()\";\n\t\n\tif (!PyArray_IsScalar(m1,Generic)) {\n\t\tif (PyArray_Check(m1)) {\n\t\t\tret = m1->ob_type->tp_as_number->nb_power(m1,m2, \n\t\t\t\t\t\t\t\t Py_None);\n\t\t}\n\t\telse {\n\t\t\tif (!PyArray_IsScalar(m2,Generic)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tarr = PyArray_FromScalar(m2, NULL);\n\t\t\tif (arr == NULL) return NULL;\n\t\t\tret = arr->ob_type->tp_as_number->nb_power(m1, arr,\n\t\t\t\t\t\t\t\t Py_None);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t\treturn ret;\n\t}\n\tif (!PyArray_IsScalar(m2, Generic)) {\n\t\tif (PyArray_Check(m2)) {\n\t\t\tret = m2->ob_type->tp_as_number->nb_power(m1,m2, \n\t\t\t\t\t\t\t\t Py_None);\n\t\t}\n\t\telse {\n\t\t\tif (!PyArray_IsScalar(m1, Generic)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tarr = PyArray_FromScalar(m1, NULL);\n\t\t\tif (arr == NULL) return NULL;\n\t\t\tret = arr->ob_type->tp_as_number->nb_power(arr, m2,\n\t\t\t\t\t\t\t\t Py_None);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t\treturn ret;\n\t}\n\tarr=arg2=NULL;\n\tarr = PyArray_FromScalar(m1, NULL);\n\targ2 = PyArray_FromScalar(m2, NULL);\t\n\tif (arr == NULL || arg2 == NULL) {\n\t\tPy_XDECREF(arr); Py_XDECREF(arg2); return NULL;\n\t}\n\tret = arr->ob_type->tp_as_number->nb_power(arr, arg2, Py_None);\n\tPy_DECREF(arr);\n\tPy_DECREF(arg2);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_generic_method(PyObject *self, PyObject *args, PyObject *kwds, \n\t\t char *str)\n{\n\tPyObject *arr, *meth, *ret;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tmeth = PyObject_GetAttrString(arr, str);\n\tif (meth == NULL) {Py_DECREF(arr); return NULL;}\n\tif (kwds == NULL) \n\t\tret = PyObject_CallObject(meth, args);\n\telse\n\t\tret = PyObject_Call(meth, args, kwds);\n\tPy_DECREF(meth);\n\tPy_DECREF(arr);\n if (ret && PyArray_Check(ret))\n return PyArray_Return((PyArrayObject *)ret);\n else\n return ret;\n}\n\n/**begin repeat\n\n#name=add, subtract, divide, remainder, divmod, lshift, rshift, and, xor, or, floor_divide, true_divide#\n#PYNAME=Add, Subtract, Divide, Remainder, Divmod, Lshift, Rshift, And, Xor, Or, FloorDivide, TrueDivide#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *m1, PyObject *m2)\n{\n\treturn PyArray_Type.tp_as_number->nb_@name@(m1, m2);\n}\n/**end repeat**/\n\n\nstatic PyObject *\ngentype_multiply(PyObject *m1, PyObject *m2)\n{\n\tPyObject *ret=NULL;\n\tlong repeat;\n\n\tif (!PyArray_IsScalar(m1, Generic) && \n\t ((m1->ob_type->tp_as_number == NULL) ||\n\t (m1->ob_type->tp_as_number->nb_multiply == NULL))) {\n\t\t/* Try to convert m2 to an int and try sequence\n\t\t repeat */\n\t\trepeat = PyInt_AsLong(m2);\n\t\tif (repeat == -1 && PyErr_Occurred()) return NULL;\n\t\tret = PySequence_Repeat(m1, (int) repeat);\n\t}\n\telse if (!PyArray_IsScalar(m2, Generic) && \n\t\t ((m2->ob_type->tp_as_number == NULL) ||\n\t\t (m2->ob_type->tp_as_number->nb_multiply == NULL))) {\n\t\t/* Try to convert m1 to an int and try sequence\n\t\t repeat */\n\t\trepeat = PyInt_AsLong(m1);\n\t\tif (repeat == -1 && PyErr_Occurred()) return NULL;\n\t\tret = PySequence_Repeat(m2, (int) repeat);\n\t}\n\tif (ret==NULL) {\n\t\tPyErr_Clear(); /* no effect if not set */\n\t\tret = PyArray_Type.tp_as_number->nb_multiply(m1, m2);\n\t}\n\treturn ret;\n}\n\n/**begin repeat\n\n#name=positive, negative, absolute, invert, int, long, float, oct, hex#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *m1)\n{\n\tPyObject *arr, *ret;\n\n\tarr = PyArray_FromScalar(m1, NULL);\n\tif (arr == NULL) return NULL;\n\tret = arr->ob_type->tp_as_number->nb_@name@(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n/**end repeat**/\n\nstatic int\ngentype_nonzero_number(PyObject *m1)\n{\n\tPyObject *arr;\n\tint ret;\n\n\tarr = PyArray_FromScalar(m1, NULL);\n\tif (arr == NULL) return -1;\n\tret = arr->ob_type->tp_as_number->nb_nonzero(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_str(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret, *tmp;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tif (arr==NULL) return NULL;\n\tret = PyObject_Str((tmp=arr->descr->f->getitem(arr->data, arr)));\n\tPy_DECREF(arr);\n\tPy_XDECREF(tmp);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_repr(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret, *tmp ;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tif (arr==NULL) return NULL;\n\tret = PyObject_Repr((tmp=arr->descr->f->getitem(arr->data, arr)));\n\tPy_DECREF(arr);\n\tPy_XDECREF(tmp);\n\treturn ret;\n}\n\nstatic void\nformat_longdouble(char *buf, size_t buflen, longdouble val, int precision)\n{\n register char *cp;\n\n PyOS_snprintf(buf, buflen, \"%.*\" LONGDOUBLE_FMT, precision, val);\n cp = buf;\n if (*cp == '-')\n cp++;\n for (; *cp != '\\0'; cp++) {\n if (!isdigit(Py_CHARMASK(*cp)))\n break;\n }\n if (*cp == '\\0') {\n *cp++ = '.';\n *cp++ = '0';\n *cp++ = '\\0';\n }\n}\n\n/* over-ride repr and str of array-scalar strings and unicode to \n remove NULL bytes and then call the corresponding functions \n of string and unicode. \n */\n\n/**begin repeat\n#name=string*2,unicode*2#\n#form=(repr,str)*2#\n#Name=String*2,Unicode*2#\n#NAME=STRING*2,UNICODE*2#\n#extra=AndSize*2,,#\n#type=char*2, Py_UNICODE*2#\n*/\nstatic PyObject *\n@name@type_@form@(PyObject *self)\n{\n\tconst @type@ *dptr, *ip;\n\tint len;\n\tPyObject *new;\n\tPyObject *ret;\n\n\tip = dptr = Py@Name@_AS_@NAME@(self);\n\tlen = Py@Name@_GET_SIZE(self);\n\tdptr += len-1;\n\twhile(len > 0 && *dptr-- == 0) len--;\n\tnew = Py@Name@_From@Name@@extra@(ip, len);\n\tif (new == NULL) return PyString_FromString(\"\");\n\tret = Py@Name@_Type.tp_@form@(new);\n\tPy_DECREF(new);\n\treturn ret;\n}\n/**end repeat**/\n\n\n\n#if SIZEOF_LONGDOUBLE == SIZEOF_DOUBLE\n#define PREC_REPR 17\n#define PREC_STR 17\n#else\n#define PREC_REPR 21\n#define PREC_STR 21\n#endif\n\nstatic PyObject *\nlongdoubletype_repr(PyObject *self)\n{\n static char buf[100];\n format_longdouble(buf, sizeof(buf), ((PyLongDoubleScalarObject *)self)->obval, PREC_REPR);\n return PyString_FromString(buf);\n}\n\nstatic PyObject *\nclongdoubletype_repr(PyObject *self)\n{\n static char buf1[100];\n static char buf2[100];\n\tstatic char buf3[202];\n clongdouble x;\n x = ((PyCLongDoubleScalarObject *)self)->obval;\n format_longdouble(buf1, sizeof(buf1), x.real, PREC_REPR);\n format_longdouble(buf2, sizeof(buf2), x.imag, PREC_REPR);\n\n\tsnprintf(buf3, sizeof(buf3), \"(%s+%sj)\", buf1, buf2);\n\treturn PyString_FromString(buf3);\n}\n\n#define longdoubletype_str longdoubletype_repr\n#define clongdoubletype_str clongdoubletype_repr\n\n/** Could improve this with a PyLong_FromLongDouble(longdouble ldval)\n but this would need some more work...\n**/\n\n/**begin repeat\n\n#name=(int, long, hex, oct, float)*2#\n#KIND=(Long*4, Float)*2#\n#char=,,,,,c*5#\n#CHAR=,,,,,C*5#\n#POST=,,,,,.real*5#\n*/\nstatic PyObject *\n@char@longdoubletype_@name@(PyObject *self)\n{\n\tdouble dval;\n\tPyObject *obj, *ret;\n\t\n\tdval = (double)(((Py@CHAR@LongDoubleScalarObject *)self)->obval)@POST@;\n\tobj = Py@KIND@_FromDouble(dval);\n\tret = obj->ob_type->tp_as_number->nb_@name@(obj);\n\tPy_DECREF(obj);\n\treturn ret;\n}\n/**end repeat**/\n\n#if PY_VERSION_HEX >= 0x02050000\n/* This needs a better implementation */\nstatic Py_ssize_t\ngentype_index(PyObject *self)\n{\n\tPyObject *obj;\n\tif (!(PyArray_IsScalar(self, Integer))) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"not an integer type.\");\n\t\treturn -1;\n\t}\n\tobj = gentype_int(self);\n\tif (obj == NULL) return -1;\n\treturn PyInt_AsSsize_t(obj);\t\n}\n#endif\n\n\nstatic PyNumberMethods gentype_as_number = {\n (binaryfunc)gentype_add,\t\t /*nb_add*/\n (binaryfunc)gentype_subtract,\t\t /*nb_subtract*/\n (binaryfunc)gentype_multiply,\t\t /*nb_multiply*/\n (binaryfunc)gentype_divide,\t\t /*nb_divide*/\n (binaryfunc)gentype_remainder,\t /*nb_remainder*/\n (binaryfunc)gentype_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)gentype_power,\t\t /*nb_power*/\n (unaryfunc)gentype_negative,\t \n (unaryfunc)gentype_positive, \t /*nb_pos*/ \n (unaryfunc)gentype_absolute,\t\t /*(unaryfunc)gentype_abs,*/\n (inquiry)gentype_nonzero_number,\t\t /*nb_nonzero*/\n (unaryfunc)gentype_invert,\t\t /*nb_invert*/\n (binaryfunc)gentype_lshift,\t /*nb_lshift*/\n (binaryfunc)gentype_rshift,\t /*nb_rshift*/\n (binaryfunc)gentype_and,\t /*nb_and*/\n (binaryfunc)gentype_xor,\t /*nb_xor*/\n (binaryfunc)gentype_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)gentype_int,\t\t /*nb_int*/\n (unaryfunc)gentype_long,\t\t /*nb_long*/\n (unaryfunc)gentype_float,\t\t /*nb_float*/\n (unaryfunc)gentype_oct,\t\t /*nb_oct*/\n (unaryfunc)gentype_hex,\t\t /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)gentype_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)gentype_true_divide,\t /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n\t(lenfunc)gentype_index, /* nb_index */\n#endif\n};\n\n\nstatic PyObject *\ngentype_richcompare(PyObject *self, PyObject *other, int cmp_op) \n{\n\n\tPyObject *arr, *ret;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tret = arr->ob_type->tp_richcompare(arr, other, cmp_op);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_ndim_get(PyObject *self)\n{\n\treturn PyInt_FromLong(0);\n}\n\nstatic PyObject *\ngentype_flags_get(PyObject *self)\n{\n return PyArray_NewFlagsObject(NULL);\n}\n\nstatic PyObject *\nvoidtype_flags_get(PyVoidScalarObject *self)\n{\n\treturn PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 1);\n}\n\nstatic PyObject *\nvoidtype_dtypedescr_get(PyVoidScalarObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n\nstatic PyObject *\ngentype_shape_get(PyObject *self)\n{\n\treturn PyTuple_New(0);\n}\n\n/*\nstatic int\ngentype_shape_set(PyObject *self, PyObject *val)\n{\n\tif (!PyTuple_Check(val) || PyTuple_GET_SIZE(val) > 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \\\n\t\t\t\t\"invalid shape for scalar\");\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n*/\n\nstatic PyObject *\ngentype_dataptr_get(PyObject *self)\n{\n\treturn Py_BuildValue(\"NO\",PyString_FromString(\"\"),Py_True);\n}\n\n\nstatic PyObject *\ngentype_data_get(PyObject *self)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\n\ttypecode = PyArray_DescrFromScalar(self);\n\tret = PyBuffer_FromObject(self, 0, typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\n\nstatic PyObject *\ngentype_itemsize_get(PyObject *self)\n{\t\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\n\ttypecode = PyArray_DescrFromScalar(self);\n\tret = PyInt_FromLong((long) typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_size_get(PyObject *self)\n{\n\treturn PyInt_FromLong(1);\n}\n\nstatic void\ngentype_struct_free(void *ptr, void *arr)\n{\n Py_DECREF((PyObject *)arr);\n _pya_free(ptr);\n}\n\nstatic PyObject *\ngentype_struct_get(PyObject *self)\n{\n PyArrayObject *arr;\n PyArrayInterface *inter;\n \n arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = 0;\n inter->flags = arr->flags;\n inter->typekind = arr->descr->kind;\n inter->itemsize = arr->descr->elsize;\n inter->strides = NULL;\n inter->shape = NULL;\n inter->data = arr->data;\n return PyCObject_FromVoidPtrAndDesc(inter, arr, gentype_struct_free);\n}\n\nstatic PyObject *\ngentype_typestr_get(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tret = PyObject_GetAttrString((PyObject *)arr->descr, \"str\");\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_descr_get(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tret = PyObject_GetAttrString((PyObject *)arr, \"__array_descr__\");\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\n\nstatic PyObject *\ngentype_typedescr_get(PyObject *self)\n{\n\treturn (PyObject *)PyArray_DescrFromScalar(self);\n}\n\n\nstatic PyObject *\ngentype_base_get(PyObject *self)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic PyArray_Descr *\n_realdescr_fromcomplexscalar(PyObject *self, int *typenum)\n{\n\tif PyArray_IsScalar(self, CDouble) {\n\t\t*typenum = PyArray_CDOUBLE;\n\t\treturn PyArray_DescrFromType(PyArray_DOUBLE);\n\t}\n\tif PyArray_IsScalar(self, CFloat) {\n\t\t*typenum = PyArray_CFLOAT;\n\t\treturn PyArray_DescrFromType(PyArray_FLOAT);\n\t}\n\tif PyArray_IsScalar(self, CLongDouble) {\n\t\t*typenum = PyArray_CLONGDOUBLE;\n\t\treturn PyArray_DescrFromType(PyArray_LONGDOUBLE);\n\t}\n\treturn NULL;\n}\n\nstatic PyObject *\ngentype_real_get(PyObject *self)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\tint typenum;\n\n\tif (PyArray_IsScalar(self, ComplexFloating)) {\n\t\ttypecode = _realdescr_fromcomplexscalar(self, &typenum);\n\t\tret = PyArray_Scalar(_SOFFSET_(self, typenum), typecode,\n\t\t\t\t NULL);\n\t\tPy_DECREF(typecode);\n\t\treturn ret;\n\t}\n\telse if PyArray_IsScalar(self, Object) {\n\t\tPyObject *obj = ((PyObjectScalarObject *)self)->obval;\n\t\tret = PyObject_GetAttrString(obj, \"real\");\n\t\tif (ret != NULL) return ret;\n\t\tPyErr_Clear();\n\t}\n\tPy_INCREF(self);\n\treturn (PyObject *)self;\n}\n\nstatic PyObject *\ngentype_imag_get(PyObject *self)\n{\t\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\t\n\tint typenum;\n\t\n\ttypecode = _realdescr_fromcomplexscalar(self, &typenum);\n\tif (PyArray_IsScalar(self, ComplexFloating)) {\n\t\tret = PyArray_Scalar(_SOFFSET_(self, typenum)\t\t\\\n\t\t\t\t + typecode->elsize, typecode, NULL);\n\t}\n\telse if PyArray_IsScalar(self, Object) {\n\t\tPyObject *obj = ((PyObjectScalarObject *)self)->obval;\n\t\tPyArray_Descr *newtype;\n\t\tret = PyObject_GetAttrString(obj, \"imag\");\n\t\tif (ret == NULL) {\n\t\t\tPyErr_Clear();\n\t\t\tobj = PyInt_FromLong(0);\n\t\t\tnewtype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\t\tret = PyArray_Scalar((char *)&obj, newtype, NULL);\n\t\t\tPy_DECREF(newtype);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tchar *temp;\n\t\ttemp = PyDataMem_NEW(typecode->elsize);\n\t\tmemset(temp, '\\0', typecode->elsize);\n\t\tret = PyArray_Scalar(temp, typecode, NULL);\n\t\tPyDataMem_FREE(temp);\n\t}\n\t\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_flat_get(PyObject *self)\n{\n\tPyObject *ret, *arr;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tret = PyArray_IterNew(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyGetSetDef gentype_getsets[] = {\n {\"ndim\", \n\t (getter)gentype_ndim_get, \n\t (setter) 0, \n\t \"number of array dimensions\"},\n {\"flags\", \n\t (getter)gentype_flags_get, \n\t (setter)0, \n\t \"integer value of flags\"},\n {\"shape\", \n\t (getter)gentype_shape_get, \n\t (setter)0, \n\t \"tuple of array dimensions\"},\n {\"strides\", \n\t (getter)gentype_shape_get, \n\t (setter) 0, \n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)gentype_data_get, \n\t (setter) 0, \n\t \"pointer to start of data\"},\n {\"itemsize\", \n\t (getter)gentype_itemsize_get, \n\t (setter)0, \n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)gentype_size_get,\n (setter)0,\n \"number of elements in the gentype\"},\n {\"nbytes\",\n (getter)gentype_itemsize_get,\n (setter)0,\n \"length of item in bytes\"},\n\t{\"base\",\n\t (getter)gentype_base_get,\n\t (setter)0,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)gentype_typedescr_get,\n\t NULL,\n\t \"get array data-descriptor\"},\n {\"real\", \n\t (getter)gentype_real_get, \n\t (setter)0,\n\t \"real part of scalar\"},\n {\"imag\", \n\t (getter)gentype_imag_get, \n\t (setter)0, \n\t \"imaginary part of scalar\"},\n\t{\"flat\", \n\t (getter)gentype_flat_get, \n\t (setter)0, \n\t \"a 1-d view of scalar\"}, \n\t{\"__array_data__\", \n\t (getter)gentype_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)gentype_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)gentype_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)gentype_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)gentype_shape_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)gentype_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t/* Does not have __array_priority__ because it is not a subtype.\n\t */\n \t{NULL, NULL, NULL, NULL} /* Sentinel */\n};\n\n\n/* 0-dim array from scalar object */\n\nstatic char doc_getarray[] = \"sc.__array__(|type) return 0-dim array\";\n\nstatic PyObject *\ngentype_getarray(PyObject *scalar, PyObject *args) \n{\n\tPyArray_Descr *outcode=NULL;\n\tPyObject *ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", &PyArray_DescrConverter,\n\t\t\t &outcode)) return NULL;\n\tret = PyArray_FromScalar(scalar, outcode);\n\treturn ret;\n}\n\nstatic char doc_sc_wraparray[] = \"sc.__array_wrap__(obj) return scalar from array\";\n\nstatic PyObject *\ngentype_wraparray(PyObject *scalar, PyObject *args)\n{\n\tPyObject *arr;\n\n\tif (PyTuple_Size(args) < 1) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"only accepts 1 argument.\");\n\t\treturn NULL;\n\t}\n\tarr = PyTuple_GET_ITEM(args, 0);\n\tif (!PyArray_Check(arr)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"can only be called with ndarray object\");\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_Scalar(PyArray_DATA(arr), PyArray_DESCR(arr), arr);\n}\n\n\n/**begin repeat\n\n#name=tolist, item, tostring, astype, copy, __deepcopy__, choose, searchsorted, reshape, view, swapaxes, conj, conjugate, nonzero, flatten, ravel, fill, transpose, newbyteorder#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *self, PyObject *args)\n{\n\treturn gentype_generic_method(self, args, NULL, \"@name@\");\n}\n/**end repeat**/\n\nstatic PyObject *\ngentype_squeeze(PyObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\tPy_INCREF(self);\n\treturn self;\n}\n\nstatic int\ngentype_getreadbuf(PyObject *, int, void **);\n\nstatic PyObject *\ngentype_byteswap(PyObject *self, PyObject *args)\n{\n\tBool inplace=FALSE;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter, &inplace))\n\t\treturn NULL;\n\t\n\tif (inplace) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot byteswap a scalar in-place\");\n\t\treturn NULL;\n\t}\n\telse {\n\t\t/* get the data, copyswap it and pass it to a new Array scalar\n\t\t */\n\t\tchar *data;\n\t\tint numbytes;\n\t\tPyArray_Descr *descr;\n\t\tPyObject *new;\n\t\tchar *newmem;\n\n\t\tnumbytes = gentype_getreadbuf(self, 0, (void **)&data);\n\t\tdescr = PyArray_DescrFromScalar(self);\n\t\tnewmem = _pya_malloc(descr->elsize);\n\t\tif (newmem == NULL) {Py_DECREF(descr); return PyErr_NoMemory();}\n\t\telse memcpy(newmem, data, descr->elsize);\n\t\tdescr->f->copyswap(newmem, NULL, 1, descr->elsize);\n\t\tnew = PyArray_Scalar(newmem, descr, NULL);\n\t\t_pya_free(newmem);\n\t\tPy_DECREF(descr);\n\t\treturn new;\n\t}\n}\n\n\n/**begin repeat\n\n#name=take, getfield, put, putmask, repeat, tofile, mean, trace, diagonal, clip, std, var, sum, cumsum, prod, cumprod, compress, sort, argsort, round, argmax, argmin, max, min, ptp, any, all, resize#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\treturn gentype_generic_method(self, args, kwds, \"@name@\");\n}\n/**end repeat**/\n\nstatic PyObject *\nvoidtype_getfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyObject *ret;\n\n\tret = gentype_generic_method((PyObject *)self, args, kwds, \"getfield\");\n\tif (!ret) return ret;\n\tif (PyArray_IsScalar(ret, Generic) &&\t\\\n\t (!PyArray_IsScalar(ret, Void))) {\n\t\tPyArray_Descr *new;\n\t\tif (!PyArray_ISNBO(self->descr->byteorder)) {\n\t\t\tnew = PyArray_DescrFromScalar(ret);\n\t\t\tnew->f->copyswap(_SOFFSET_(ret, \n\t\t\t\t\t\t new->type_num),\n\t\t\t\t\t NULL, 1, new->elsize);\n\t\t\tPy_DECREF(new);\n\t\t}\n\t}\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_setfield(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\t\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"Can't set fields in a non-void array scalar.\");\n\treturn NULL;\n}\t\n\nstatic PyObject *\nvoidtype_setfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *typecode;\n\tint offset = 0;\n\tPyObject *value, *src;\n\tint mysize;\n\tchar *dptr;\n\tstatic char *kwlist[] = {\"value\", \"dtype\", \"offset\", 0};/* XXX ? */\n\t\n\tif ((self->flags & WRITEABLE) != WRITEABLE) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"Can't write to memory\");\n\t\treturn NULL;\n\t}\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO&|i\", kwlist,\n\t\t\t\t\t &value,\n\t\t\t\t\t PyArray_DescrConverter, \n\t\t\t\t\t &typecode, &offset)) return NULL;\n\n\tmysize = self->ob_size;\n\t\n\tif (offset < 0 || (offset + typecode->elsize) > mysize) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need 0 <= offset <= %d for requested type \" \\\n\t\t\t \"but received offset = %d\",\n\t\t\t mysize-typecode->elsize, offset);\n\t\tPy_DECREF(typecode);\n\t\treturn NULL;\n\t}\t\n\n\tdptr = self->obval + offset;\n\n\t/* Copy data from value to correct place in dptr */\n src = PyArray_FromAny(value, typecode, 0, 0, CARRAY_FLAGS, NULL);\n if (src == NULL) return NULL;\n\ttypecode->f->copyswap(dptr, PyArray_DATA(src), \n\t\t\t !PyArray_ISNBO(self->descr->byteorder),\n\t\t\t PyArray_ITEMSIZE(src));\n\tPy_DECREF(src);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic PyObject *\ngentype_reduce(PyObject *self, PyObject *args)\n{\n\tPyObject *ret=NULL, *obj=NULL, *mod=NULL;\n\tconst char *buffer; \n\tint buflen;\n\n\t/* Return a tuple of (callable object, arguments) */\n\n\tret = PyTuple_New(2);\n\tif (ret == NULL) return NULL;\t\n\tif (PyObject_AsReadBuffer(self, (const void **)&buffer, &buflen)<0) {\n\t\tPy_DECREF(ret); return NULL;\n\t}\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) return NULL;\n\tobj = PyObject_GetAttrString(mod, \"scalar\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) return NULL;\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tobj = PyObject_GetAttrString((PyObject *)self, \"dtype\");\n\tif PyArray_IsScalar(self, Object) {\n\t\tmod = ((PyObjectScalarObject *)self)->obval;\n\t\tPyTuple_SET_ITEM(ret, 1,\n\t\t\t\t Py_BuildValue(\"NO\", obj, mod));\n\t}\n\telse {\n\t\tmod = PyString_FromStringAndSize(buffer, buflen);\n\t\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t\t Py_BuildValue(\"NN\", obj, mod));\n\t}\n\treturn ret;\n}\n\n/* ignores everything */\nstatic PyObject *\ngentype_setstate(PyObject *self, PyObject *args)\n{\n\tPy_INCREF(Py_None);\n\treturn (Py_None);\n}\n\nstatic PyObject *\ngentype_dump(PyObject *self, PyObject *args)\n{\n\tPyObject *file=NULL;\n\tint ret;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &file))\n\t\treturn NULL;\n\tret = PyArray_Dump(self, file, 2);\n\tif (ret < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyObject *\ngentype_dumps(PyObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\"))\n\t\treturn NULL;\n\treturn PyArray_Dumps(self, 2);\n}\n\n\n/* setting flags cannot be done for scalars */\nstatic PyObject *\ngentype_setflags(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* need to fill in doc-strings for these methods on import -- copy from \n array docstrings \n*/\nstatic PyMethodDef gentype_methods[] = {\n {\"tolist\",\t (PyCFunction)gentype_tolist,\t1, NULL},\n {\"item\", (PyCFunction)gentype_item, METH_VARARGS, NULL},\n\t{\"tofile\", (PyCFunction)gentype_tofile, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"tostring\", (PyCFunction)gentype_tostring, METH_VARARGS, NULL},\n {\"byteswap\", (PyCFunction)gentype_byteswap,1, NULL},\n {\"astype\", (PyCFunction)gentype_astype, 1, NULL},\n\t{\"getfield\", (PyCFunction)gentype_getfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{\"setfield\", (PyCFunction)gentype_setfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n {\"copy\", (PyCFunction)gentype_copy, 1, NULL}, \n {\"resize\", (PyCFunction)gentype_resize, 1, NULL}, \n\n\t{\"__array__\", (PyCFunction)gentype_getarray, 1, doc_getarray},\n\t{\"__array_wrap__\", (PyCFunction)gentype_wraparray, 1, doc_sc_wraparray},\n\n /* for the copy module */\n {\"__copy__\", (PyCFunction)gentype_copy, 1, NULL},\n {\"__deepcopy__\", (PyCFunction)gentype___deepcopy__, 1, NULL},\n\n\n {\"__reduce__\", (PyCFunction) gentype_reduce, 1, NULL},\t\n\t/* For consistency does nothing */\n\t{\"__setstate__\", (PyCFunction) gentype_setstate, 1, NULL},\n\n\t{\"dumps\", (PyCFunction) gentype_dumps, 1, NULL},\n\t{\"dump\", (PyCFunction) gentype_dump, 1, NULL},\n\n\t/* Methods for array */\n\t{\"fill\", (PyCFunction)gentype_fill,\n\t METH_VARARGS, NULL},\n\t{\"transpose\",\t(PyCFunction)gentype_transpose, \n\t METH_VARARGS, NULL},\n\t{\"take\",\t(PyCFunction)gentype_take, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"put\",\t(PyCFunction)gentype_put, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"putmask\",\t(PyCFunction)gentype_putmask, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"repeat\",\t(PyCFunction)gentype_repeat, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"choose\",\t(PyCFunction)gentype_choose, \n\t METH_VARARGS, NULL},\t\n\t{\"sort\",\t(PyCFunction)gentype_sort, \n\t METH_VARARGS, NULL},\n\t{\"argsort\",\t(PyCFunction)gentype_argsort, \n\t METH_VARARGS, NULL},\n\t{\"searchsorted\", (PyCFunction)gentype_searchsorted, \n\t METH_VARARGS, NULL},\t\n\t{\"argmax\",\t(PyCFunction)gentype_argmax, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"argmin\", (PyCFunction)gentype_argmin,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"reshape\",\t(PyCFunction)gentype_reshape, \n\t METH_VARARGS, NULL},\n\t{\"squeeze\",\t(PyCFunction)gentype_squeeze, \n\t METH_VARARGS, NULL},\n\t{\"view\", (PyCFunction)gentype_view, \n\t METH_VARARGS, NULL},\n\t{\"swapaxes\", (PyCFunction)gentype_swapaxes,\n\t METH_VARARGS, NULL},\n\t{\"max\", (PyCFunction)gentype_max,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"min\", (PyCFunction)gentype_min,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"ptp\", (PyCFunction)gentype_ptp,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"mean\", (PyCFunction)gentype_mean,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"trace\", (PyCFunction)gentype_trace,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"diagonal\", (PyCFunction)gentype_diagonal,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"clip\", (PyCFunction)gentype_clip,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"conj\", (PyCFunction)gentype_conj,\n\t METH_VARARGS, NULL},\n\t{\"conjugate\", (PyCFunction)gentype_conjugate,\n\t METH_VARARGS, NULL},\n\t{\"nonzero\", (PyCFunction)gentype_nonzero,\n\t METH_VARARGS, NULL},\n\t{\"std\", (PyCFunction)gentype_std,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"var\", (PyCFunction)gentype_var,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"sum\", (PyCFunction)gentype_sum,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"cumsum\", (PyCFunction)gentype_cumsum,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"prod\", (PyCFunction)gentype_prod,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"cumprod\", (PyCFunction)gentype_cumprod,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"all\", (PyCFunction)gentype_all,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"any\", (PyCFunction)gentype_any,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"compress\", (PyCFunction)gentype_compress,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"flatten\", (PyCFunction)gentype_flatten,\n\t METH_VARARGS, NULL},\n\t{\"ravel\", (PyCFunction)gentype_ravel,\n\t METH_VARARGS, NULL},\n\t{\"round\", (PyCFunction)gentype_round,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"setflags\", (PyCFunction)gentype_setflags,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"newbyteorder\", (PyCFunction)gentype_newbyteorder,\n\t METH_VARARGS, NULL},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\nstatic PyGetSetDef voidtype_getsets[] = {\n {\"flags\", \n\t (getter)voidtype_flags_get, \n\t (setter)0, \n\t \"integer value of flags\"},\n\t{\"dtype\",\n\t (getter)voidtype_dtypedescr_get,\n\t (setter)0,\n\t \"dtype object\"},\n\t{NULL, NULL}\n};\n\nstatic PyMethodDef voidtype_methods[] = {\n\t{\"getfield\", (PyCFunction)voidtype_getfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{\"setfield\", (PyCFunction)voidtype_setfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{NULL, NULL}\n};\n\n/************* As_mapping functions for void array scalar ************/\n\nstatic int\nvoidtype_length(PyVoidScalarObject *self) \n{\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\treturn 0;\n\t}\n\telse { /* return the number of fields */\n\t\tPyObject *key;\n\t\tPyObject *flist;\n\t\tkey = PyInt_FromLong(-1);\n\t\tflist = PyDict_GetItem(self->descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!flist) return 0;\n\t\treturn PyTuple_GET_SIZE(flist);\n\t}\n}\n\n/* get field by name or number */\nstatic PyObject *\nvoidtype_subscript(PyVoidScalarObject *self, PyObject *ind)\n{\n\tint n, m;\n\tchar *msg = \"invalid index\";\n\tPyObject *flist=NULL, *key, *fieldinfo;\n\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"can't index void scalar without fields\");\n\t\treturn NULL;\n\t}\n\n\tif (PyString_Check(ind) || PyUnicode_Check(ind)) {\n\t\t/* look up in fields */\n\t\tfieldinfo = PyDict_GetItem(self->descr->fields, ind);\n\t\tif (!fieldinfo) {\n\t\t\tPyErr_SetString(PyExc_IndexError, msg);\n\t\t\treturn NULL;\n\t\t}\n\t\treturn voidtype_getfield(self, fieldinfo, NULL);\n\t}\n\t\n\t/* try to convert it to a number */\n\tn = PyArray_PyIntAsIntp(ind);\n\tif (error_converting(n)) {\n\t\tPyErr_Clear();\n\t\tgoto fail;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tflist = PyDict_GetItem(self->descr->fields, key);\n\tPy_DECREF(key);\n\tif (!flist) m = 0; \n\tm = PyTuple_GET_SIZE(flist);\n\tif (n < 0) n += m;\n\tif (n < 0 || n >= m) goto fail;\n\tfieldinfo = PyDict_GetItem(self->descr->fields, \n\t\t\t\t PyTuple_GET_ITEM(flist, n));\n\treturn voidtype_getfield(self, fieldinfo, NULL);\n\n fail:\n\tPyErr_SetString(PyExc_IndexError, msg);\n\treturn NULL;\n}\n\nstatic int\nvoidtype_ass_subscript(PyVoidScalarObject *self, PyObject *ind, PyObject *val) \n{\n\tint n, m;\n\tchar *msg = \"invalid index\";\n\tPyObject *flist=NULL, *key, *fieldinfo, *newtup;\n\tPyObject *res;\n\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"can't index void scalar without fields\");\n\t\treturn -1;\n\t}\n\n\tif (PyString_Check(ind) || PyUnicode_Check(ind)) {\n\t\t/* look up in fields */\n\t\tfieldinfo = PyDict_GetItem(self->descr->fields, ind);\n\t\tif (!fieldinfo) {\n\t\t\tPyErr_SetString(PyExc_IndexError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tnewtup = Py_BuildValue(\"(OOO)\", val, \n\t\t\t\t PyTuple_GET_ITEM(fieldinfo, 0),\n\t\t\t\t PyTuple_GET_ITEM(fieldinfo, 1));\n\t\tres = voidtype_setfield(self, newtup, NULL);\n\t\tPy_DECREF(newtup);\n\t\tif (!res) return -1;\n\t\tPy_DECREF(res);\n\t\treturn 0;\n\t}\n\t\n\t/* try to convert it to a number */\n\tn = PyArray_PyIntAsIntp(ind);\n\tif (error_converting(n)) {\n\t\tPyErr_Clear();\n\t\tgoto fail;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tflist = PyDict_GetItem(self->descr->fields, key);\n\tPy_DECREF(key);\n\tif (!flist) m = 0; \n\tm = PyTuple_GET_SIZE(flist);\n\tif (n < 0) n += m;\n\tif (n < 0 || n >= m) goto fail;\n\tfieldinfo = PyDict_GetItem(self->descr->fields, \n\t\t\t\t PyTuple_GET_ITEM(flist, n));\n\tnewtup = Py_BuildValue(\"(OOO)\", val, \n\t\t\t PyTuple_GET_ITEM(fieldinfo, 0),\n\t\t\t PyTuple_GET_ITEM(fieldinfo, 1));\n\tres = voidtype_setfield(self, fieldinfo, NULL);\n\tPy_DECREF(newtup);\n\tif (!res) return -1;\n\tPy_DECREF(res);\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_IndexError, msg);\n\treturn -1;\n}\n\nstatic PyMappingMethods voidtype_as_mapping = {\n (inquiry)voidtype_length,\t\t /*mp_length*/\n (binaryfunc)voidtype_subscript,\t /*mp_subscript*/\n (objobjargproc)voidtype_ass_subscript,\t /*mp_ass_subscript*/\n};\n\n\nstatic int\ngentype_getreadbuf(PyObject *self, int segment, void **ptrptr)\n{\n\tint numbytes;\n\tPyArray_Descr *outcode;\n\t\n\tif (segment != 0) {\n\t\tPyErr_SetString(PyExc_SystemError, \n\t\t\t\t\"Accessing non-existent array segment\");\n\t\treturn -1;\n\t}\n\n\toutcode = PyArray_DescrFromScalar(self);\n\tnumbytes = outcode->elsize;\n\tif PyArray_IsScalar(self, Flexible) {\n\t\tif PyArray_IsScalar(self, String)\n\t\t\t*ptrptr = PyString_AS_STRING(self);\n\t\telse if PyArray_IsScalar(self, Unicode)\n\t\t\t*ptrptr = (char *)PyUnicode_AS_DATA(self);\n\t\telse if PyArray_IsScalar(self, Void)\n\t\t\t*ptrptr = ((PyVoidScalarObject *)self)->obval;\n\t}\n\telse \n\t\t*ptrptr = (void *)_SOFFSET_(self, outcode->type_num);\n\n\tPy_DECREF(outcode);\n\treturn numbytes;\n}\n\nstatic int\ngentype_getsegcount(PyObject *self, int *lenp)\n{\n\tPyArray_Descr *outcode;\n\n\toutcode = PyArray_DescrFromScalar(self);\n\tif (lenp)\n\t\t*lenp = outcode->elsize;\n\tPy_DECREF(outcode);\n\treturn 1;\n}\n\nstatic int\ngentype_getcharbuf(PyObject *self, int segment, const char **ptrptr)\n{\n\tif (PyArray_IsScalar(self, String) ||\t\\\n\t PyArray_IsScalar(self, Unicode))\n\t\treturn gentype_getreadbuf(self, segment, (void **)ptrptr);\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"Non-character array cannot be interpreted \"\\\n\t\t\t\t\"as character buffer.\");\n\t\treturn -1;\n\t}\n}\n\n\nstatic PyBufferProcs gentype_as_buffer = {\n (getreadbufferproc)gentype_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)0, /*bf_getwritebuffer*/\n (getsegcountproc)gentype_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)gentype_getcharbuf, /*bf_getcharbuffer*/\n};\n\n\n#define BASEFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES\n#define LEAFFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES\n\nstatic PyTypeObject PyGenericArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"genericscalar\",\t /*tp_name*/\n sizeof(PyObject),\t\t /*tp_basicsize*/\n};\n\nstatic void\nunicode_dealloc(PyObject *v) \n{\n\tPyDataMem_FREE(((PyVoidScalarObject *)v)->obval);\n\tv->ob_type->tp_free(v);\n}\n\nstatic void\nvoid_dealloc(PyVoidScalarObject *v) \n{\n\tif (v->flags & OWNDATA)\n\t\tPyDataMem_FREE(v->obval);\n\tPy_XDECREF(v->descr);\n\tPy_XDECREF(v->base);\n\tv->ob_type->tp_free(v);\n}\n\nstatic void\nobject_arrtype_dealloc(PyObject *v)\n{\n\tPy_XDECREF(((PyObjectScalarObject *)v)->obval);\n\tv->ob_type->tp_free(v);\n}\n\n/* string and unicode inherit from Python Type first and so GET_ITEM is different to\n get to the Python Type.\n */\n\n/**begin repeat \n#name=byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, object#\n#TYPE=BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, STRING, UNICODE, OBJECT#\n#num=1*16,0,0,1#\n*/\nstatic PyObject *\n@name@_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj=NULL;\n\tPyObject *arr;\n\tPyArray_Descr *typecode;\n\n\tif (type->tp_bases && (PyTuple_GET_SIZE(type->tp_bases)==2)) {\n\t\tPyTypeObject *sup;\n\t\tPyObject *ret;\n\t\t/* We are inheriting from a Python type as well so\n\t\t give it first dibs on conversion */\n\t\tsup = (PyTypeObject *)PyTuple_GET_ITEM(type->tp_bases, @num@);\n\t\tret = sup->tp_new(type, args, kwds);\n\t\tif (ret) return ret;\n\t\tPyErr_Clear();\n\t\t/* now do default conversion */\n\t}\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\n\ttypecode = PyArray_DescrFromType(PyArray_@TYPE@);\n\tarr = PyArray_FromAny(obj, typecode, 0, 0, FORCECAST, NULL);\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n/**end repeat**/\n\n/* bool->tp_new only returns Py_True or Py_False */\nstatic PyObject *\nbool_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj=NULL;\n\tPyObject *arr;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\tif (obj == Py_False)\n\t\tPyArrayScalar_RETURN_FALSE;\n\tif (obj == Py_True)\n\t\tPyArrayScalar_RETURN_TRUE;\n\tarr = PyArray_FROM_OTF(obj, PyArray_BOOL, FORCECAST);\n\tif (arr && 0 == PyArray_NDIM(arr)) {\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)PyArray_DATA(arr));\n\t}\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n\nstatic PyObject *\nbool_arrtype_and(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)&(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_and(a, b);\n}\n\nstatic PyObject *\nbool_arrtype_or(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)|(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_or(a, b);\n}\n\nstatic PyObject *\nbool_arrtype_xor(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)^(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_xor(a, b);\n}\n\nstatic int\nbool_arrtype_nonzero(PyObject *a)\n{\n\treturn a == PyArrayScalar_True;\n}\n\n/* Arithmetic methods -- only so we can override &, |, ^. */\nstatic PyNumberMethods bool_arrtype_as_number = {\n\tbool_arrtype_or,\t\t\t/* nb_add */\n\t0,\t\t\t\t\t/* nb_subtract */\n\tbool_arrtype_and,\t\t\t/* nb_multiply */\n\t0,\t\t\t\t\t/* nb_divide */\n\t0,\t\t\t\t\t/* nb_remainder */\n\t0,\t\t\t\t\t/* nb_divmod */\n\t0,\t\t\t\t\t/* nb_power */\n\t0,\t\t\t\t\t/* nb_negative */\n\t0,\t\t\t\t\t/* nb_positive */\n\t0,\t\t\t\t\t/* nb_absolute */\n\t(inquiry)bool_arrtype_nonzero,\t\t/* nb_nonzero */\n\t0,\t\t\t\t\t/* nb_invert */\n\t0,\t\t\t\t\t/* nb_lshift */\n\t0,\t\t\t\t\t/* nb_rshift */\n\t(binaryfunc)bool_arrtype_and,\t\t/* nb_and */\n\t(binaryfunc)bool_arrtype_xor,\t\t/* nb_xor */\n\t(binaryfunc)bool_arrtype_or,\t\t/* nb_or */\n};\n\nstatic PyObject *\nvoid_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj, *arr;\n\tulonglong memu=1;\n\tPyObject *new=NULL;\n\tchar *destptr;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\t/* For a VOID scalar first see if obj is an integer or long \n\t and create new memory of that size (filled with 0) for the scalar\n\t*/\n\n\tif (PyLong_Check(obj) || PyInt_Check(obj) || \\\n\t PyArray_IsScalar(obj, Integer) ||\n\t (PyArray_Check(obj) && PyArray_NDIM(obj)==0 &&\t\\\n\t PyArray_ISINTEGER(obj))) {\n\t\tnew = obj->ob_type->tp_as_number->nb_long(obj);\n\t}\n\tif (new && PyLong_Check(new)) {\n\t\tPyObject *ret;\n\t\tmemu = PyLong_AsUnsignedLongLong(new);\n\t\tPy_DECREF(new);\n\t\tif (PyErr_Occurred() || (memu > MAX_INT)) {\n\t\t\tPyErr_Clear();\n\t\t\tPyErr_Format(PyExc_OverflowError, \n\t\t\t\t \"size must be smaller than %d\",\n\t\t\t\t (int) MAX_INT);\n\t\t\treturn NULL;\n\t\t}\n\t\tdestptr = PyDataMem_NEW((int) memu);\n\t\tif (destptr == NULL) return PyErr_NoMemory();\n\t\tret = type->tp_alloc(type, 0);\n\t\tif (ret == NULL) {\n\t\t\tPyDataMem_FREE(destptr);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\t((PyVoidScalarObject *)ret)->obval = destptr;\n\t\t((PyVoidScalarObject *)ret)->ob_size = (int) memu;\n\t\t((PyVoidScalarObject *)ret)->descr = \\\n\t\t\tPyArray_DescrNewFromType(PyArray_VOID);\n\t\t((PyVoidScalarObject *)ret)->descr->elsize = (int) memu;\n\t\t((PyVoidScalarObject *)ret)->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t((PyVoidScalarObject *)ret)->base = NULL;\n\t\tmemset(destptr, '\\0', (size_t) memu);\n\t\treturn ret;\n\t}\n\n\tarr = PyArray_FROM_OTF(obj, PyArray_VOID, FORCECAST);\n return PyArray_Return((PyArrayObject *)arr);\n}\n\n\n/**************** Define Hash functions ********************/\n\n/**begin repeat\n#lname=bool,ubyte,ushort#\n#name=Bool,UByte, UShort#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n return (long)(((Py@name@ScalarObject *)obj)->obval);\n}\n/**end repeat**/\n\n/**begin repeat\n#lname=byte,short,uint,ulong#\n#name=Byte,Short,UInt,ULong#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((Py@name@ScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n/**end repeat**/\n\n#if SIZEOF_INT != SIZEOF_LONG\nstatic long\nint_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((PyIntScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n#endif\n\n/**begin repeat\n#char=,u#\n#Char=,U#\n#ext=&& (x >= LONG_MIN),#\n*/\n#if SIZEOF_LONG != SIZEOF_LONGLONG\n/* we assume SIZEOF_LONGLONG=2*SIZEOF_LONG */\nstatic long\n@char@longlong_arrtype_hash(PyObject *obj)\n{\n long y;\n @char@longlong x = (((Py@Char@LongLongScalarObject *)obj)->obval);\n\n if ((x <= LONG_MAX)@ext@) {\n y = (long) x;\n }\n else {\n union Mask {\n long hashvals[2];\n @char@longlong v;\n } both;\n\n both.v = x;\n y = both.hashvals[0] + (1000003)*both.hashvals[1];\n }\n if (y == -1) y = -2;\n return y;\n}\n#endif\n/**end repeat**/\n\n#if SIZEOF_LONG==SIZEOF_LONGLONG\nstatic long\nulonglong_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((PyULongLongScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n#endif\n\n\n\n/* Wrong thing to do for longdouble, but....*/\n/**begin repeat\n#lname=float, longdouble#\n#name=Float, LongDouble#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n return _Py_HashDouble((double) ((Py@name@ScalarObject *)obj)->obval);\n}\n\n/* borrowed from complex_hash */\nstatic long\nc@lname@_arrtype_hash(PyObject *obj)\n{\n long hashreal, hashimag, combined;\n hashreal = _Py_HashDouble((double) \\\n (((PyC@name@ScalarObject *)obj)->obval).real);\n\n if (hashreal == -1) return -1;\n hashimag = _Py_HashDouble((double) \\\n (((PyC@name@ScalarObject *)obj)->obval).imag);\n if (hashimag == -1) return -1;\n\n combined = hashreal + 1000003 * hashimag;\n if (combined == -1) combined = -2;\n return combined;\n}\n/**end repeat**/\n\nstatic long\nobject_arrtype_hash(PyObject *obj)\n{\n return PyObject_Hash(((PyObjectScalarObject *)obj)->obval);\n}\n\n/* just hash the pointer */\nstatic long\nvoid_arrtype_hash(PyObject *obj)\n{\n return _Py_HashPointer((void *)(((PyVoidScalarObject *)obj)->obval));\n}\n\n/*object arrtype getattro and setattro */\nstatic PyObject *\nobject_arrtype_getattro(PyObjectScalarObject *obj, PyObject *attr) {\n\tPyObject *res;\n\n\t/* first look in object and then hand off to generic type */\n\n\tres = PyObject_GenericGetAttr(obj->obval, attr);\t\n\tif (res) return res;\n\tPyErr_Clear();\n\treturn \tPyObject_GenericGetAttr((PyObject *)obj, attr);\n}\n\nstatic int\nobject_arrtype_setattro(PyObjectScalarObject *obj, PyObject *attr, PyObject *val) {\n\tint res;\n\t/* first look in object and then hand off to generic type */\n\n\tres = PyObject_GenericSetAttr(obj->obval, attr, val);\n\tif (res >= 0) return res;\n\tPyErr_Clear();\n\treturn PyObject_GenericSetAttr((PyObject *)obj, attr, val);\n}\n\nstatic PyObject *\nobject_arrtype_concat(PyObjectScalarObject *self, PyObject *other)\n{\n\treturn PySequence_Concat(self->obval, other);\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_length(PyObjectScalarObject *self) \n{\n\treturn PyObject_Length(self->obval);\n}\n\nstatic PyObject *\nobject_arrtype_repeat(PyObjectScalarObject *self, _int_or_ssize_t count)\n{\n\treturn PySequence_Repeat(self->obval, count);\n}\n\nstatic PyObject *\nobject_arrtype_subscript(PyObjectScalarObject *self, PyObject *key)\n{\n\treturn PyObject_GetItem(self->obval, key);\n}\n\nstatic int\nobject_arrtype_ass_subscript(PyObjectScalarObject *self, PyObject *key, \n\t\t\t PyObject *value)\n{\n\treturn PyObject_SetItem(self->obval, key, value);\n}\n\nstatic int\nobject_arrtype_contains(PyObjectScalarObject *self, PyObject *ob)\n{\n\treturn PySequence_Contains(self->obval, ob);\n}\n\nstatic PyObject *\nobject_arrtype_inplace_concat(PyObjectScalarObject *self, PyObject *o)\n{\n\treturn PySequence_InPlaceConcat(self->obval, o);\n}\n\nstatic PyObject *\nobject_arrtype_inplace_repeat(PyObjectScalarObject *self, _int_or_ssize_t count)\n{\n\treturn PySequence_InPlaceRepeat(self->obval, count);\n}\n\nstatic PySequenceMethods object_arrtype_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)object_arrtype_length, /*sq_length*/\n (binaryfunc)object_arrtype_concat, /*sq_concat*/\n (ssizeargfunc)object_arrtype_repeat, /*sq_repeat*/\n 0, /*sq_item*/\n 0, /*sq_slice*/\n 0, /* sq_ass_item */\n 0, /* sq_ass_slice */\n (objobjproc)object_arrtype_contains, /* sq_contains */\n (binaryfunc)object_arrtype_inplace_concat, /* sq_inplace_concat */\n (ssizeargfunc)object_arrtype_inplace_repeat, /* sq_inplace_repeat */\n#else\n (inquiry)object_arrtype_length, /*sq_length*/\n (binaryfunc)object_arrtype_concat, /*sq_concat*/\n (intargfunc)object_arrtype_repeat, /*sq_repeat*/\n 0, /*sq_item*/\n 0, /*sq_slice*/\n 0, /* sq_ass_item */\n 0, /* sq_ass_slice */\n (objobjproc)object_arrtype_contains, /* sq_contains */\n (binaryfunc)object_arrtype_inplace_concat, /* sq_inplace_concat */\n (intargfunc)object_arrtype_inplace_repeat, /* sq_inplace_repeat */\n#endif\n};\n\nstatic PyMappingMethods object_arrtype_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)object_arrtype_length,\n (binaryfunc)object_arrtype_subscript,\n (objobjargproc)object_arrtype_ass_subscript,\n#else\n (inquiry)object_arrtype_length,\n (binaryfunc)object_arrtype_subscript,\n (objobjargproc)object_arrtype_ass_subscript,\n#endif\n};\n\nstatic _int_or_ssize_t\nobject_arrtype_getsegcount(PyObjectScalarObject *self, _int_or_ssize_t *lenp) \n{\n\tint newlen;\n\tint cnt;\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\t\n\tif (pb == NULL || \\\n\t pb->bf_getsegcount == NULL || \\\n\t (cnt = (*pb->bf_getsegcount)(self->obval, &newlen)) != 1) \n\t\treturn 0;\n\t\n\tif (lenp) \n\t\t*lenp = newlen;\n\t\n\treturn cnt;\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_getreadbuf(PyObjectScalarObject *self, _int_or_ssize_t segment, void **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getreadbuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a readable buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getreadbuffer)(self->obval, segment, ptrptr);\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_getwritebuf(PyObjectScalarObject *self, _int_or_ssize_t segment, void **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getwritebuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a writeable buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getwritebuffer)(self->obval, segment, ptrptr);\n}\n\nstatic _int_or_ssize_t \nobject_arrtype_getcharbuf(PyObjectScalarObject *self, _int_or_ssize_t segment, \n\t\t\t const char **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getcharbuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a character buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getcharbuffer)(self->obval, segment, ptrptr);\n}\n\nstatic PyBufferProcs object_arrtype_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)object_arrtype_getreadbuf,\n (writebufferproc)object_arrtype_getwritebuf,\n (segcountproc)object_arrtype_getsegcount,\n (charbufferproc)object_arrtype_getcharbuf,\n#else\n (getreadbufferproc)object_arrtype_getreadbuf,\n (getwritebufferproc)object_arrtype_getwritebuf,\n (getsegcountproc)object_arrtype_getsegcount,\n (getcharbufferproc)object_arrtype_getcharbuf,\n#endif\n};\n\nstatic PyObject *\nobject_arrtype_call(PyObjectScalarObject *obj, PyObject *args, PyObject *kwds)\n{\n\treturn PyObject_Call(obj->obval, args, kwds);\n}\n\nstatic PyTypeObject PyObjectArrType_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"objectscalar\",\t /*tp_name*/\n sizeof(PyObjectScalarObject),\t /*tp_basicsize*/\n 0, /* tp_itemsize */\n (destructor)object_arrtype_dealloc, /* tp_dealloc */\n 0, /* tp_print */\n 0, /* tp_getattr */\n 0, /* tp_setattr */\n 0, /* tp_compare */\n 0, /* tp_repr */\n 0, /* tp_as_number */\n &object_arrtype_as_sequence, /* tp_as_sequence */\n &object_arrtype_as_mapping, /* tp_as_mapping */\n 0, /* tp_hash */\n (ternaryfunc)object_arrtype_call, /* tp_call */\n 0, /* tp_str */\n (getattrofunc)object_arrtype_getattro, /* tp_getattro */\n (setattrofunc)object_arrtype_setattro, /* tp_setattro */\n &object_arrtype_as_buffer, /* tp_as_buffer */\n 0, /* tp_flags */\n};\n\n/**begin repeat\n#name=bool, string, unicode, void#\n#NAME=Bool, String, Unicode, Void#\n*/\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@scalar\",\t /*tp_name*/\n sizeof(Py@NAME@ScalarObject),\t /*tp_basicsize*/\n};\n/**end repeat**/\n\n/**begin repeat\n#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n#name=int*5, uint*5, float*3, complex*3#\n#CNAME=(CHAR, SHORT, INT, LONG, LONGLONG)*2, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n*/\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@\" STRBITSOF_@CNAME@ \"scalar\",\t /*tp_name*/\n sizeof(Py@NAME@ScalarObject),\t /*tp_basicsize*/\n};\n\n/**end repeat**/\n\n\nstatic PyNumberMethods longdoubletype_as_number;\nstatic PyNumberMethods clongdoubletype_as_number;\n\n\nstatic void\ninitialize_numeric_types(void)\n{\n\tPyGenericArrType_Type.tp_dealloc = (destructor)gentype_dealloc;\n\tPyGenericArrType_Type.tp_as_number = &gentype_as_number;\n\tPyGenericArrType_Type.tp_as_buffer = &gentype_as_buffer;\n\tPyGenericArrType_Type.tp_flags = BASEFLAGS;\n\tPyGenericArrType_Type.tp_methods = gentype_methods;\n\tPyGenericArrType_Type.tp_getset = gentype_getsets;\n\tPyGenericArrType_Type.tp_new = NULL;\n PyGenericArrType_Type.tp_alloc = gentype_alloc;\n\tPyGenericArrType_Type.tp_free = _pya_free;\n\tPyGenericArrType_Type.tp_repr = gentype_repr;\n\tPyGenericArrType_Type.tp_str = gentype_str;\n\tPyGenericArrType_Type.tp_richcompare = gentype_richcompare;\n\n\tPyBoolArrType_Type.tp_as_number = &bool_arrtype_as_number;\n\n\tPyStringArrType_Type.tp_alloc = NULL;\n\tPyStringArrType_Type.tp_free = NULL;\n\t\n\tPyStringArrType_Type.tp_repr = stringtype_repr;\n\tPyStringArrType_Type.tp_str = stringtype_str;\n\n\tPyUnicodeArrType_Type.tp_repr = unicodetype_repr;\n\tPyUnicodeArrType_Type.tp_str = unicodetype_str;\n\n\tPyVoidArrType_Type.tp_methods = voidtype_methods;\n\tPyVoidArrType_Type.tp_getset = voidtype_getsets;\n\tPyVoidArrType_Type.tp_as_mapping = &voidtype_as_mapping;\n\t\n\t/**begin repeat\n#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating, \nComplexFloating, Flexible, Character#\n\t*/\n Py@NAME@ArrType_Type.tp_flags = BASEFLAGS;\n\t/**end repeat**/\n\n\t/**begin repeat\n#name=bool, byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, void, object#\n#NAME=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, String, Unicode, Void, Object#\n\t*/\n\tPy@NAME@ArrType_Type.tp_flags = LEAFFLAGS;\n\tPy@NAME@ArrType_Type.tp_new = @name@_arrtype_new;\n\tPy@NAME@ArrType_Type.tp_richcompare = gentype_richcompare;\n\t/**end repeat**/\n\t/* Allow the Void type to be subclassed -- for adding new types */\n\tPyVoidArrType_Type.tp_flags = BASEFLAGS;\n\n /**begin repeat\n#name=bool, byte, short, ubyte, ushort, uint, ulong, ulonglong, float, longdouble, cfloat, clongdouble, void, object#\n#NAME=Bool, Byte, Short, UByte, UShort, UInt, ULong, ULongLong, Float, LongDouble, CFloat, CLongDouble, Void, Object#\n */\n Py@NAME@ArrType_Type.tp_hash = @name@_arrtype_hash;\n /**end repeat**/\n\n#if SIZEOF_INT != SIZEOF_LONG\n /* We won't be inheriting from Python Int type. */\n PyIntArrType_Type.tp_hash = int_arrtype_hash;\n#endif\n\n#if SIZEOF_LONG != SIZEOF_LONGLONG\n /* We won't be inheriting from Python Int type. */\n PyLongLongArrType_Type.tp_hash = longlong_arrtype_hash;\n#endif\n\n\t/* These need to be coded specially because getitem does not\n\t return a normal Python type\n\t*/\n\tPyLongDoubleArrType_Type.tp_as_number = &longdoubletype_as_number;\n\tPyCLongDoubleArrType_Type.tp_as_number = &clongdoubletype_as_number;\n\n\t/**begin repeat\n#name=int, long, hex, oct, float, repr, str#\n#kind=tp_as_number->nb*5, tp*2#\n\t*/\n\tPyLongDoubleArrType_Type.@kind@_@name@ = longdoubletype_@name@;\n\tPyCLongDoubleArrType_Type.@kind@_@name@ = clongdoubletype_@name@;\n\t/**end repeat**/\n\n\tPyStringArrType_Type.tp_itemsize = sizeof(char);\n\tPyVoidArrType_Type.tp_dealloc = (destructor) void_dealloc;\n\tPyUnicodeArrType_Type.tp_dealloc = unicode_dealloc;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMapIter_Type.tp_iter = PyObject_SelfIter;\n\n/**begin repeat\n#name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,#\n#num=BOOL, BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, OBJECT, NTYPES#\n**/\n PyArrayScalar_Offset[PyArray_@num@] = (int) offsetof(Py@name@ScalarObject, obval);\n/**end repeat**/\n}\n\n\n/* the order of this table is important */\nstatic PyTypeObject *typeobjects[] = {\n &PyBoolArrType_Type,\n &PyByteArrType_Type,\n\t&PyUByteArrType_Type,\n &PyShortArrType_Type,\n &PyUShortArrType_Type,\n\t&PyIntArrType_Type,\n\t&PyUIntArrType_Type,\n\t&PyLongArrType_Type,\n\t&PyULongArrType_Type,\n\t&PyLongLongArrType_Type,\n\t&PyULongLongArrType_Type,\n\t&PyFloatArrType_Type,\n\t&PyDoubleArrType_Type,\n\t&PyLongDoubleArrType_Type,\n\t&PyCFloatArrType_Type,\n\t&PyCDoubleArrType_Type,\n\t&PyCLongDoubleArrType_Type,\n\t&PyObjectArrType_Type,\n\t&PyStringArrType_Type,\n\t&PyUnicodeArrType_Type,\n\t&PyVoidArrType_Type\n};\n\nstatic int\n_typenum_fromtypeobj(PyObject *type, int user)\n{\n\tint typenum, i;\n\n\ttypenum = PyArray_NOTYPE;\n i = 0;\n\twhile(i < PyArray_NTYPES) {\n\t\tif (type == (PyObject *)typeobjects[i]) {\n\t\t\ttypenum = i;\n\t\t\tbreak;\n\t\t}\n i++;\n\t}\n\t\n\tif (!user) return typenum;\n\n\t/* Search any registered types */\n\ti = 0;\n\twhile (i < PyArray_NUMUSERTYPES) {\n\t\tif (type == (PyObject *)(userdescrs[i]->typeobj)) {\n\t\t\ttypenum = i + PyArray_USERDEF;\n\t\t\tbreak;\n\t\t}\n\t\ti++;\n\t}\n\treturn typenum;\n}\n\n/* new reference */\nstatic PyArray_Descr *\nPyArray_DescrFromTypeObject(PyObject *type)\n{\t\n\tint typenum;\n\tPyArray_Descr *new, *conv=NULL;\n\n\t/* if it's a builtin type, then use the typenumber */\n\ttypenum = _typenum_fromtypeobj(type,1);\t\n\tif (typenum != PyArray_NOTYPE) {\n\t\tnew = PyArray_DescrFromType(typenum);\n\t\tif (PyTypeNum_ISUSERDEF(typenum)) goto finish;\n\t\treturn new;\n\t}\n\n\t/* Check the generic types */\n\tif ((type == (PyObject *) &PyNumberArrType_Type) ||\t\t\\\n\t (type == (PyObject *) &PyInexactArrType_Type) ||\t\t\\\n\t (type == (PyObject *) &PyFloatingArrType_Type))\n\t\ttypenum = PyArray_DOUBLE;\n\telse if (type == (PyObject *)&PyComplexFloatingArrType_Type)\n\t\ttypenum = PyArray_CDOUBLE;\n\telse if ((type == (PyObject *)&PyIntegerArrType_Type) ||\t\\\n\t\t (type == (PyObject *)&PySignedIntegerArrType_Type))\n\t\ttypenum = PyArray_LONG;\n\telse if (type == (PyObject *) &PyUnsignedIntegerArrType_Type)\n\t\ttypenum = PyArray_ULONG;\n\telse if (type == (PyObject *) &PyCharacterArrType_Type)\n\t\ttypenum = PyArray_STRING;\n\telse if ((type == (PyObject *) &PyGenericArrType_Type) || \\\n\t\t (type == (PyObject *) &PyFlexibleArrType_Type))\n\t\ttypenum = PyArray_VOID;\n\n\tif (typenum != PyArray_NOTYPE) {\n\t\treturn PyArray_DescrFromType(typenum);\n\t}\n\t\n\t/* Otherwise --- type is a sub-type of an array scalar\n\t currently only VOID allows it -- use it as the type-object.\n\t*/\n\t/* look for a dtypedescr attribute */\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\n finish:\n\tconv = _arraydescr_fromobj(type);\n\tif (conv) {\n\t\tnew->fields = conv->fields;\n\t\tPy_INCREF(new->fields);\n\t\tnew->elsize = conv->elsize;\n\t\tnew->subarray = conv->subarray;\n\t\tconv->subarray = NULL;\n\t\tPy_DECREF(conv);\n\t}\n Py_DECREF(new->typeobj);\n new->typeobj = (PyTypeObject *)type;\n Py_INCREF(type);\n\treturn new;\n}\n\n/* New reference */\n/*OBJECT_API\n Return descr object from array scalar.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromScalar(PyObject *sc)\n{\n\tint type_num;\n\tPyArray_Descr *descr;\n\n\tif PyArray_IsScalar(sc, Void) {\n\t\tdescr = ((PyVoidScalarObject *)sc)->descr;\n\t\tPy_INCREF(descr);\n\t\treturn descr;\n\t}\n descr = PyArray_DescrFromTypeObject((PyObject *)sc->ob_type);\n if (descr->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(descr);\n type_num = descr->type_num;\n\t\tif (type_num == PyArray_STRING) \n\t\t\tdescr->elsize = PyString_GET_SIZE(sc);\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tdescr->elsize = PyUnicode_GET_DATA_SIZE(sc);\n#ifndef Py_UNICODE_WIDE\n\t\t\tdescr->elsize <<= 1;\n#endif\t\t\n\t\t}\n\t\telse {\n\t\t\tdescr->elsize =\t\t\t\t\t\\\n\t\t\t\t((PyVoidScalarObject *)sc)->ob_size;\n\t\t\tdescr->fields = PyObject_GetAttrString(sc, \"fields\");\n\t\t\tif (!descr->fields || !PyDict_Check(descr->fields) || \\\n\t\t\t (descr->fields == Py_None)) {\n\t\t\t\tPy_XDECREF(descr->fields);\n\t\t\t\tdescr->fields = NULL;\n\t\t\t}\n\t\t\tPyErr_Clear();\n\t\t}\n }\n\treturn descr;\n}\n\n/* New reference */\n/*OBJECT_API\n Get a typeobject from a type-number\n*/\nstatic PyObject *\nPyArray_TypeObjectFromType(int type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr == NULL) return NULL;\n\tobj = (PyObject *)descr->typeobj;\n\tPy_INCREF(obj);\n\tPy_DECREF(descr);\n\treturn obj;\n}\n\n", + "source_code_before": "/* -*- c -*- */\n\nstatic int PyArrayScalar_Offset[PyArray_NTYPES+1];\n/* to be exposed in C-API */\n#define PyArrayScalar_False ((PyObject *)&_PyArrayScalar_BoolValues[0])\n#define PyArrayScalar_True ((PyObject *)&_PyArrayScalar_BoolValues[1])\n#define PyArrayScalar_RETURN_BOOL_FROM_LONG(i)\t\t\t\\\n\treturn Py_INCREF(&_PyArrayScalar_BoolValues[((i)!=0)]),\t\\\n\t\t(PyObject *)&_PyArrayScalar_BoolValues[((i)!=0)]\n#define PyArrayScalar_RETURN_FALSE\t\t\\\n\treturn Py_INCREF(PyArrayScalar_False),\t\\\n\t\tPyArrayScalar_False\n#define PyArrayScalar_RETURN_TRUE\t\t\\\n\treturn Py_INCREF(PyArrayScalar_True),\t\\\n\t\tPyArrayScalar_True\n/* end to be exposed in C-API */\n\n#define _SOFFSET_(obj, type_num) ((char *)(obj) + PyArrayScalar_Offset[(type_num)])\n\n/**begin repeat\n#name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,#\n#type=Bool, signed char, short, int, long, longlong, unsigned char, unsigned short, unsigned int, unsigned long, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, PyObject *,char#\n*/\ntypedef struct {\n\tPyObject_HEAD\n\t@type@ obval;\n} Py@name@ScalarObject;\n/**end repeat**/\n\nstatic PyBoolScalarObject _PyArrayScalar_BoolValues[] = {\n\t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 0},\n\t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 1},\n};\n\n/* Inheritance established later when tp_bases is set (or tp_base for \n single inheritance) */\n\n/**begin repeat\n\n#name=number, integer, signedinteger, unsignedinteger, inexact, floating, complexfloating, flexible, \ncharacter#\n#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating, ComplexFloating, Flexible, Character#\n*/\n\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@scalar\",\t\t /*tp_name*/\n sizeof(PyObject),\t\t /*tp_basicsize*/\n};\n/**end repeat**/\n\n\n#define PyStringScalarObject PyStringObject\n#define PyUnicodeScalarObject PyUnicodeObject\n\ntypedef struct {\n\tPyObject_VAR_HEAD\n\tchar *obval;\n\tPyArray_Descr *descr;\n\tint flags;\n\tPyObject *base;\n} PyVoidScalarObject;\n\n/* no error checking is performed -- ctypeptr must be same type as scalar */\n/* in case of flexible type, the data is not copied \n into ctypeptr which is expected to be a pointer to pointer */\n/*OBJECT_API\n Convert to c-type\n*/\nstatic void\nPyArray_ScalarAsCtype(PyObject *scalar, void *ctypeptr)\n{\n\tPyArray_Descr *typecode;\n\ttypecode = PyArray_DescrFromScalar(scalar);\n\t\n\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\tvoid **newptr = (void **)ctypeptr;\n\t\tswitch(typecode->type_num) {\n\t\tcase PyArray_STRING:\n\t\t\t*newptr = (void *)PyString_AS_STRING(scalar);\n break;\n\t\tcase PyArray_UNICODE:\n\t\t\t*newptr = (void *)PyUnicode_AS_DATA(scalar);\n break;\n\t\tdefault:\n\t\t\t*newptr = ((PyVoidScalarObject *)scalar)->obval;\n break;\n\t\t}\n\t\treturn;\n\t}\n\tmemcpy(ctypeptr, _SOFFSET_(scalar, typecode->type_num),\n\t typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn;\n}\n\n/* The output buffer must be large-enough to receive the value */\n/* Even for flexible types which is different from ScalarAsCtype\n where only a reference for flexible types is returned \n*/\n\n/*OBJECT_API\n Cast Scalar to c-type\n*/\nstatic int\nPyArray_CastScalarToCtype(PyObject *scalar, void *ctypeptr, \n\t\t\t PyArray_Descr *outcode)\n{\n\tPyArray_Descr* descr;\n\t\n\tdescr = PyArray_DescrFromScalar(scalar);\n\tif (PyTypeNum_ISEXTENDED(descr->type_num) ||\n\t PyTypeNum_ISEXTENDED(outcode->type_num)) {\n\t\tPyArrayObject *ain, *aout;\n\n\t\tain = (PyArrayObject *)PyArray_FromScalar(scalar, NULL);\n\t\tif (ain == NULL) {Py_DECREF(descr); return -1;}\n\t\taout = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t outcode,\n\t\t\t\t\t 0, NULL, \n\t\t\t\t\t NULL, ctypeptr, \n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\t\tif (aout == NULL) {Py_DECREF(ain); return -1;}\n\t\tdescr->f->cast[outcode->type_num](ain->data, \n\t\t\t\t\t aout->data, 1, ain, aout);\n\t\tPy_DECREF(ain);\n\t\tPy_DECREF(aout);\n\t}\n\telse {\n\t\tdescr->f->cast[outcode->type_num](_SOFFSET_(scalar, \n\t\t\t\t\t\t\t descr->type_num), \n\t\t\t\t\t ctypeptr, 1, NULL, NULL);\n\t}\n\tPy_DECREF(descr);\n\treturn 0;\n}\n\n/* 0-dim array from array-scalar object */\n/* always contains a copy of the data \n unless outcode is NULL, it is of void type and the referrer does\n not own it either.\n*/\n\n/* steals reference to outcode */\n/*OBJECT_API\n Get 0-dim array from scalar\n*/\nstatic PyObject *\nPyArray_FromScalar(PyObject *scalar, PyArray_Descr *outcode)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *r;\n\tchar *memptr;\n\tPyObject *ret;\n\n\t/* convert to 0-dim array of scalar typecode */\n\ttypecode = PyArray_DescrFromScalar(scalar);\n\tif ((typecode->type_num == PyArray_VOID) &&\t\t\t\\\n\t !(((PyVoidScalarObject *)scalar)->flags & OWNDATA) &&\t\\\n\t outcode == NULL) {\n\t\tr = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t typecode,\n\t\t\t\t\t 0, NULL, NULL,\n\t\t\t\t\t ((PyVoidScalarObject *)scalar)->obval,\n\t\t\t\t\t ((PyVoidScalarObject *)scalar)->flags,\n\t\t\t\t\t NULL);\n\t\tPyArray_BASE(r) = (PyObject *)scalar;\n\t\tPy_INCREF(scalar);\n\t\treturn r;\n\t}\n\tr = PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t typecode,\n\t\t\t\t 0, NULL, \n\t\t\t\t NULL, NULL, 0, NULL);\n\tif (r==NULL) {Py_XDECREF(outcode); return NULL;}\n\n\tswitch(typecode->type_num) {\n\tcase PyArray_STRING:\n\t\tmemptr = PyString_AS_STRING(scalar);\n\t\tbreak;\n\tcase PyArray_UNICODE:\n\t\tmemptr = (char *)PyUnicode_AS_DATA(scalar);\n#ifdef Py_UNICODE_WIDE\n\t\tbreak;\n#else\n\t\tPyUCS2Buffer_AsUCS4((Py_UNICODE *)memptr, \n\t\t\t\t (PyArray_UCS4 *)PyArray_DATA(r),\n\t\t\t\t PyUnicode_GET_SIZE(scalar),\n\t\t\t\t PyArray_ITEMSIZE(r) >> 2);\n goto finish;\n#endif\n\tdefault:\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tmemptr = (((PyVoidScalarObject *)scalar)->obval);\n\t\t}\n\t\telse {\n\t\t\tmemptr = _SOFFSET_(scalar, typecode->type_num);\n\t\t}\n\t\tbreak;\n\t}\n\n\tmemcpy(PyArray_DATA(r), memptr, PyArray_ITEMSIZE(r));\n\tif (PyArray_ISOBJECT(r)) {\n\t\tPy_INCREF(*((PyObject **)memptr));\n\t}\n#ifndef Py_UNICODE_WIDE\n finish:\t\n#endif\n\tif (outcode == NULL) return r;\n\t\n\tif (outcode->type_num == typecode->type_num) {\n\t\tif (!PyTypeNum_ISEXTENDED(typecode->type_num))\n\t\t\treturn r;\n\t\tif (outcode->elsize == typecode->elsize);\n\t\treturn r;\t\t\t\n\t}\n\t\n\t/* cast if necessary to desired output typecode */\n\tret = PyArray_CastToType((PyArrayObject *)r, outcode, 0);\n\tPy_DECREF(r);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n const size_t size = _PyObject_VAR_SIZE(type, nitems+1);\n\n obj = (PyObject *)_pya_malloc(size);\n\tmemset(obj, 0, size);\n\tif (type->tp_itemsize == 0)\n PyObject_INIT(obj, type);\n else\n (void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems);\n return obj;\n}\n\nstatic void\ngentype_dealloc(PyObject *v) \n{\n\tv->ob_type->tp_free(v);\n}\n\n\nstatic PyObject *\ngentype_power(PyObject *m1, PyObject *m2, PyObject *m3)\n{\n\tPyObject *arr, *ret, *arg2;\n\tchar *msg=\"unsupported operand type(s) for ** or pow()\";\n\t\n\tif (!PyArray_IsScalar(m1,Generic)) {\n\t\tif (PyArray_Check(m1)) {\n\t\t\tret = m1->ob_type->tp_as_number->nb_power(m1,m2, \n\t\t\t\t\t\t\t\t Py_None);\n\t\t}\n\t\telse {\n\t\t\tif (!PyArray_IsScalar(m2,Generic)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tarr = PyArray_FromScalar(m2, NULL);\n\t\t\tif (arr == NULL) return NULL;\n\t\t\tret = arr->ob_type->tp_as_number->nb_power(m1, arr,\n\t\t\t\t\t\t\t\t Py_None);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t\treturn ret;\n\t}\n\tif (!PyArray_IsScalar(m2, Generic)) {\n\t\tif (PyArray_Check(m2)) {\n\t\t\tret = m2->ob_type->tp_as_number->nb_power(m1,m2, \n\t\t\t\t\t\t\t\t Py_None);\n\t\t}\n\t\telse {\n\t\t\tif (!PyArray_IsScalar(m1, Generic)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tarr = PyArray_FromScalar(m1, NULL);\n\t\t\tif (arr == NULL) return NULL;\n\t\t\tret = arr->ob_type->tp_as_number->nb_power(arr, m2,\n\t\t\t\t\t\t\t\t Py_None);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t\treturn ret;\n\t}\n\tarr=arg2=NULL;\n\tarr = PyArray_FromScalar(m1, NULL);\n\targ2 = PyArray_FromScalar(m2, NULL);\t\n\tif (arr == NULL || arg2 == NULL) {\n\t\tPy_XDECREF(arr); Py_XDECREF(arg2); return NULL;\n\t}\n\tret = arr->ob_type->tp_as_number->nb_power(arr, arg2, Py_None);\n\tPy_DECREF(arr);\n\tPy_DECREF(arg2);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_generic_method(PyObject *self, PyObject *args, PyObject *kwds, \n\t\t char *str)\n{\n\tPyObject *arr, *meth, *ret;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tmeth = PyObject_GetAttrString(arr, str);\n\tif (meth == NULL) {Py_DECREF(arr); return NULL;}\n\tif (kwds == NULL) \n\t\tret = PyObject_CallObject(meth, args);\n\telse\n\t\tret = PyObject_Call(meth, args, kwds);\n\tPy_DECREF(meth);\n\tPy_DECREF(arr);\n if (ret && PyArray_Check(ret))\n return PyArray_Return((PyArrayObject *)ret);\n else\n return ret;\n}\n\n/**begin repeat\n\n#name=add, subtract, divide, remainder, divmod, lshift, rshift, and, xor, or, floor_divide, true_divide#\n#PYNAME=Add, Subtract, Divide, Remainder, Divmod, Lshift, Rshift, And, Xor, Or, FloorDivide, TrueDivide#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *m1, PyObject *m2)\n{\n\treturn PyArray_Type.tp_as_number->nb_@name@(m1, m2);\n}\n/**end repeat**/\n\n\nstatic PyObject *\ngentype_multiply(PyObject *m1, PyObject *m2)\n{\n\tPyObject *ret=NULL;\n\tlong repeat;\n\n\tif (!PyArray_IsScalar(m1, Generic) && \n\t ((m1->ob_type->tp_as_number == NULL) ||\n\t (m1->ob_type->tp_as_number->nb_multiply == NULL))) {\n\t\t/* Try to convert m2 to an int and try sequence\n\t\t repeat */\n\t\trepeat = PyInt_AsLong(m2);\n\t\tif (repeat == -1 && PyErr_Occurred()) return NULL;\n\t\tret = PySequence_Repeat(m1, (int) repeat);\n\t}\n\telse if (!PyArray_IsScalar(m2, Generic) && \n\t\t ((m2->ob_type->tp_as_number == NULL) ||\n\t\t (m2->ob_type->tp_as_number->nb_multiply == NULL))) {\n\t\t/* Try to convert m1 to an int and try sequence\n\t\t repeat */\n\t\trepeat = PyInt_AsLong(m1);\n\t\tif (repeat == -1 && PyErr_Occurred()) return NULL;\n\t\tret = PySequence_Repeat(m2, (int) repeat);\n\t}\n\tif (ret==NULL) {\n\t\tPyErr_Clear(); /* no effect if not set */\n\t\tret = PyArray_Type.tp_as_number->nb_multiply(m1, m2);\n\t}\n\treturn ret;\n}\n\n/**begin repeat\n\n#name=positive, negative, absolute, invert, int, long, float, oct, hex#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *m1)\n{\n\tPyObject *arr, *ret;\n\n\tarr = PyArray_FromScalar(m1, NULL);\n\tif (arr == NULL) return NULL;\n\tret = arr->ob_type->tp_as_number->nb_@name@(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n/**end repeat**/\n\nstatic int\ngentype_nonzero_number(PyObject *m1)\n{\n\tPyObject *arr;\n\tint ret;\n\n\tarr = PyArray_FromScalar(m1, NULL);\n\tif (arr == NULL) return -1;\n\tret = arr->ob_type->tp_as_number->nb_nonzero(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_str(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret, *tmp;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tif (arr==NULL) return NULL;\n\tret = PyObject_Str((tmp=arr->descr->f->getitem(arr->data, arr)));\n\tPy_DECREF(arr);\n\tPy_XDECREF(tmp);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_repr(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret, *tmp ;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tif (arr==NULL) return NULL;\n\tret = PyObject_Repr((tmp=arr->descr->f->getitem(arr->data, arr)));\n\tPy_DECREF(arr);\n\tPy_XDECREF(tmp);\n\treturn ret;\n}\n\nstatic void\nformat_longdouble(char *buf, size_t buflen, longdouble val, int precision)\n{\n register char *cp;\n\n PyOS_snprintf(buf, buflen, \"%.*\" LONGDOUBLE_FMT, precision, val);\n cp = buf;\n if (*cp == '-')\n cp++;\n for (; *cp != '\\0'; cp++) {\n if (!isdigit(Py_CHARMASK(*cp)))\n break;\n }\n if (*cp == '\\0') {\n *cp++ = '.';\n *cp++ = '0';\n *cp++ = '\\0';\n }\n}\n\n/* over-ride repr and str of array-scalar strings and unicode to \n remove NULL bytes and then call the corresponding functions \n of string and unicode. \n */\n\n/**begin repeat\n#name=string*2,unicode*2#\n#form=(repr,str)*2#\n#Name=String*2,Unicode*2#\n#NAME=STRING*2,UNICODE*2#\n#extra=AndSize*2,,#\n#type=char*2, Py_UNICODE*2#\n*/\nstatic PyObject *\n@name@type_@form@(PyObject *self)\n{\n\tconst @type@ *dptr, *ip;\n\tint len;\n\tPyObject *new;\n\tPyObject *ret;\n\n\tip = dptr = Py@Name@_AS_@NAME@(self);\n\tlen = Py@Name@_GET_SIZE(self);\n\tdptr += len-1;\n\twhile(len > 0 && *dptr-- == 0) len--;\n\tnew = Py@Name@_From@Name@@extra@(ip, len);\n\tif (new == NULL) return PyString_FromString(\"\");\n\tret = Py@Name@_Type.tp_@form@(new);\n\tPy_DECREF(new);\n\treturn ret;\n}\n/**end repeat**/\n\n\n\n#if SIZEOF_LONGDOUBLE == SIZEOF_DOUBLE\n#define PREC_REPR 17\n#define PREC_STR 17\n#else\n#define PREC_REPR 21\n#define PREC_STR 21\n#endif\n\nstatic PyObject *\nlongdoubletype_repr(PyObject *self)\n{\n static char buf[100];\n format_longdouble(buf, sizeof(buf), ((PyLongDoubleScalarObject *)self)->obval, PREC_REPR);\n return PyString_FromString(buf);\n}\n\nstatic PyObject *\nclongdoubletype_repr(PyObject *self)\n{\n static char buf1[100];\n static char buf2[100];\n\tstatic char buf3[202];\n clongdouble x;\n x = ((PyCLongDoubleScalarObject *)self)->obval;\n format_longdouble(buf1, sizeof(buf1), x.real, PREC_REPR);\n format_longdouble(buf2, sizeof(buf2), x.imag, PREC_REPR);\n\n\tsnprintf(buf3, sizeof(buf3), \"(%s+%sj)\", buf1, buf2);\n\treturn PyString_FromString(buf3);\n}\n\n#define longdoubletype_str longdoubletype_repr\n#define clongdoubletype_str clongdoubletype_repr\n\n/** Could improve this with a PyLong_FromLongDouble(longdouble ldval)\n but this would need some more work...\n**/\n\n/**begin repeat\n\n#name=(int, long, hex, oct, float)*2#\n#KIND=(Long*4, Float)*2#\n#char=,,,,,c*5#\n#CHAR=,,,,,C*5#\n#POST=,,,,,.real*5#\n*/\nstatic PyObject *\n@char@longdoubletype_@name@(PyObject *self)\n{\n\tdouble dval;\n\tPyObject *obj, *ret;\n\t\n\tdval = (double)(((Py@CHAR@LongDoubleScalarObject *)self)->obval)@POST@;\n\tobj = Py@KIND@_FromDouble(dval);\n\tret = obj->ob_type->tp_as_number->nb_@name@(obj);\n\tPy_DECREF(obj);\n\treturn ret;\n}\n/**end repeat**/\n\n#if PY_VERSION_HEX >= 0x02050000\n/* This needs a better implementation */\nstatic Py_ssize_t\ngentype_index(PyObject *self)\n{\n\tPyObject *obj;\n\tif (!(PyArray_IsScalar(self, Integer))) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"not an integer type.\");\n\t\treturn -1;\n\t}\n\tobj = gentype_int(self);\n\tif (obj == NULL) return -1;\n\treturn PyInt_AsSsize_t(obj);\t\n}\n#endif\n\n\nstatic PyNumberMethods gentype_as_number = {\n (binaryfunc)gentype_add,\t\t /*nb_add*/\n (binaryfunc)gentype_subtract,\t\t /*nb_subtract*/\n (binaryfunc)gentype_multiply,\t\t /*nb_multiply*/\n (binaryfunc)gentype_divide,\t\t /*nb_divide*/\n (binaryfunc)gentype_remainder,\t /*nb_remainder*/\n (binaryfunc)gentype_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)gentype_power,\t\t /*nb_power*/\n (unaryfunc)gentype_negative,\t \n (unaryfunc)gentype_positive, \t /*nb_pos*/ \n (unaryfunc)gentype_absolute,\t\t /*(unaryfunc)gentype_abs,*/\n (inquiry)gentype_nonzero_number,\t\t /*nb_nonzero*/\n (unaryfunc)gentype_invert,\t\t /*nb_invert*/\n (binaryfunc)gentype_lshift,\t /*nb_lshift*/\n (binaryfunc)gentype_rshift,\t /*nb_rshift*/\n (binaryfunc)gentype_and,\t /*nb_and*/\n (binaryfunc)gentype_xor,\t /*nb_xor*/\n (binaryfunc)gentype_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)gentype_int,\t\t /*nb_int*/\n (unaryfunc)gentype_long,\t\t /*nb_long*/\n (unaryfunc)gentype_float,\t\t /*nb_float*/\n (unaryfunc)gentype_oct,\t\t /*nb_oct*/\n (unaryfunc)gentype_hex,\t\t /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)gentype_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)gentype_true_divide,\t /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n\t(lenfunc)gentype_index, /* nb_index */\n#endif\n};\n\n\nstatic PyObject *\ngentype_richcompare(PyObject *self, PyObject *other, int cmp_op) \n{\n\n\tPyObject *arr, *ret;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tret = arr->ob_type->tp_richcompare(arr, other, cmp_op);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_ndim_get(PyObject *self)\n{\n\treturn PyInt_FromLong(0);\n}\n\nstatic PyObject *\ngentype_flags_get(PyObject *self)\n{\n return PyArray_NewFlagsObject(NULL);\n}\n\nstatic PyObject *\nvoidtype_flags_get(PyVoidScalarObject *self)\n{\n\treturn PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 1);\n}\n\nstatic PyObject *\nvoidtype_dtypedescr_get(PyVoidScalarObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n\nstatic PyObject *\ngentype_shape_get(PyObject *self)\n{\n\treturn PyTuple_New(0);\n}\n\n/*\nstatic int\ngentype_shape_set(PyObject *self, PyObject *val)\n{\n\tif (!PyTuple_Check(val) || PyTuple_GET_SIZE(val) > 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \\\n\t\t\t\t\"invalid shape for scalar\");\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n*/\n\nstatic PyObject *\ngentype_dataptr_get(PyObject *self)\n{\n\treturn Py_BuildValue(\"NO\",PyString_FromString(\"\"),Py_True);\n}\n\n\nstatic PyObject *\ngentype_data_get(PyObject *self)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\n\ttypecode = PyArray_DescrFromScalar(self);\n\tret = PyBuffer_FromObject(self, 0, typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\n\nstatic PyObject *\ngentype_itemsize_get(PyObject *self)\n{\t\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\n\ttypecode = PyArray_DescrFromScalar(self);\n\tret = PyInt_FromLong((long) typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_size_get(PyObject *self)\n{\n\treturn PyInt_FromLong(1);\n}\n\nstatic void\ngentype_struct_free(void *ptr, void *arr)\n{\n Py_DECREF((PyObject *)arr);\n _pya_free(ptr);\n}\n\nstatic PyObject *\ngentype_struct_get(PyObject *self)\n{\n PyArrayObject *arr;\n PyArrayInterface *inter;\n \n arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = 0;\n inter->flags = arr->flags;\n inter->typekind = arr->descr->kind;\n inter->itemsize = arr->descr->elsize;\n inter->strides = NULL;\n inter->shape = NULL;\n inter->data = arr->data;\n return PyCObject_FromVoidPtrAndDesc(inter, arr, gentype_struct_free);\n}\n\nstatic PyObject *\ngentype_typestr_get(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tret = PyObject_GetAttrString((PyObject *)arr->descr, \"str\");\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_descr_get(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tret = PyObject_GetAttrString((PyObject *)arr, \"__array_descr__\");\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\n\nstatic PyObject *\ngentype_typedescr_get(PyObject *self)\n{\n\treturn (PyObject *)PyArray_DescrFromScalar(self);\n}\n\n\nstatic PyObject *\ngentype_base_get(PyObject *self)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic PyArray_Descr *\n_realdescr_fromcomplexscalar(PyObject *self, int *typenum)\n{\n\tif PyArray_IsScalar(self, CDouble) {\n\t\t*typenum = PyArray_CDOUBLE;\n\t\treturn PyArray_DescrFromType(PyArray_DOUBLE);\n\t}\n\tif PyArray_IsScalar(self, CFloat) {\n\t\t*typenum = PyArray_CFLOAT;\n\t\treturn PyArray_DescrFromType(PyArray_FLOAT);\n\t}\n\tif PyArray_IsScalar(self, CLongDouble) {\n\t\t*typenum = PyArray_CLONGDOUBLE;\n\t\treturn PyArray_DescrFromType(PyArray_LONGDOUBLE);\n\t}\n\treturn NULL;\n}\n\nstatic PyObject *\ngentype_real_get(PyObject *self)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\tint typenum;\n\n\tif (PyArray_IsScalar(self, ComplexFloating)) {\n\t\ttypecode = _realdescr_fromcomplexscalar(self, &typenum);\n\t\tret = PyArray_Scalar(_SOFFSET_(self, typenum), typecode,\n\t\t\t\t NULL);\n\t\tPy_DECREF(typecode);\n\t\treturn ret;\n\t}\n\telse if PyArray_IsScalar(self, Object) {\n\t\tPyObject *obj = ((PyObjectScalarObject *)self)->obval;\n\t\tret = PyObject_GetAttrString(obj, \"real\");\n\t\tif (ret != NULL) return ret;\n\t\tPyErr_Clear();\n\t}\n\tPy_INCREF(self);\n\treturn (PyObject *)self;\n}\n\nstatic PyObject *\ngentype_imag_get(PyObject *self)\n{\t\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\t\n\tint typenum;\n\t\n\ttypecode = _realdescr_fromcomplexscalar(self, &typenum);\n\tif (PyArray_IsScalar(self, ComplexFloating)) {\n\t\tret = PyArray_Scalar(_SOFFSET_(self, typenum)\t\t\\\n\t\t\t\t + typecode->elsize, typecode, NULL);\n\t}\n\telse if PyArray_IsScalar(self, Object) {\n\t\tPyObject *obj = ((PyObjectScalarObject *)self)->obval;\n\t\tPyArray_Descr *newtype;\n\t\tret = PyObject_GetAttrString(obj, \"imag\");\n\t\tif (ret == NULL) {\n\t\t\tPyErr_Clear();\n\t\t\tobj = PyInt_FromLong(0);\n\t\t\tnewtype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\t\tret = PyArray_Scalar((char *)&obj, newtype, NULL);\n\t\t\tPy_DECREF(newtype);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tchar *temp;\n\t\ttemp = PyDataMem_NEW(typecode->elsize);\n\t\tmemset(temp, '\\0', typecode->elsize);\n\t\tret = PyArray_Scalar(temp, typecode, NULL);\n\t\tPyDataMem_FREE(temp);\n\t}\n\t\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_flat_get(PyObject *self)\n{\n\tPyObject *ret, *arr;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tret = PyArray_IterNew(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyGetSetDef gentype_getsets[] = {\n {\"ndim\", \n\t (getter)gentype_ndim_get, \n\t (setter) 0, \n\t \"number of array dimensions\"},\n {\"flags\", \n\t (getter)gentype_flags_get, \n\t (setter)0, \n\t \"integer value of flags\"},\n {\"shape\", \n\t (getter)gentype_shape_get, \n\t (setter)0, \n\t \"tuple of array dimensions\"},\n {\"strides\", \n\t (getter)gentype_shape_get, \n\t (setter) 0, \n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)gentype_data_get, \n\t (setter) 0, \n\t \"pointer to start of data\"},\n {\"itemsize\", \n\t (getter)gentype_itemsize_get, \n\t (setter)0, \n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)gentype_size_get,\n (setter)0,\n \"number of elements in the gentype\"},\n {\"nbytes\",\n (getter)gentype_itemsize_get,\n (setter)0,\n \"length of item in bytes\"},\n\t{\"base\",\n\t (getter)gentype_base_get,\n\t (setter)0,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)gentype_typedescr_get,\n\t NULL,\n\t \"get array data-descriptor\"},\n {\"real\", \n\t (getter)gentype_real_get, \n\t (setter)0,\n\t \"real part of scalar\"},\n {\"imag\", \n\t (getter)gentype_imag_get, \n\t (setter)0, \n\t \"imaginary part of scalar\"},\n\t{\"flat\", \n\t (getter)gentype_flat_get, \n\t (setter)0, \n\t \"a 1-d view of scalar\"}, \n\t{\"__array_data__\", \n\t (getter)gentype_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)gentype_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)gentype_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)gentype_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)gentype_shape_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)gentype_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t/* Does not have __array_priority__ because it is not a subtype.\n\t */\n \t{NULL, NULL, NULL, NULL} /* Sentinel */\n};\n\n\n/* 0-dim array from scalar object */\n\nstatic char doc_getarray[] = \"sc.__array__(|type) return 0-dim array\";\n\nstatic PyObject *\ngentype_getarray(PyObject *scalar, PyObject *args) \n{\n\tPyArray_Descr *outcode=NULL;\n\tPyObject *ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", &PyArray_DescrConverter,\n\t\t\t &outcode)) return NULL;\n\tret = PyArray_FromScalar(scalar, outcode);\n\treturn ret;\n}\n\nstatic char doc_sc_wraparray[] = \"sc.__array_wrap__(obj) return scalar from array\";\n\nstatic PyObject *\ngentype_wraparray(PyObject *scalar, PyObject *args)\n{\n\tPyObject *arr;\n\n\tif (PyTuple_Size(args) < 1) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"only accepts 1 argument.\");\n\t\treturn NULL;\n\t}\n\tarr = PyTuple_GET_ITEM(args, 0);\n\tif (!PyArray_Check(arr)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"can only be called with ndarray object\");\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_Scalar(PyArray_DATA(arr), PyArray_DESCR(arr), arr);\n}\n\n\n/**begin repeat\n\n#name=tolist, item, tostring, astype, copy, __deepcopy__, choose, searchsorted, reshape, view, swapaxes, conj, conjugate, nonzero, flatten, ravel, fill, transpose, newbyteorder#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *self, PyObject *args)\n{\n\treturn gentype_generic_method(self, args, NULL, \"@name@\");\n}\n/**end repeat**/\n\nstatic PyObject *\ngentype_squeeze(PyObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\tPy_INCREF(self);\n\treturn self;\n}\n\nstatic int\ngentype_getreadbuf(PyObject *, int, void **);\n\nstatic PyObject *\ngentype_byteswap(PyObject *self, PyObject *args)\n{\n\tBool inplace=FALSE;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter, &inplace))\n\t\treturn NULL;\n\t\n\tif (inplace) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot byteswap a scalar in-place\");\n\t\treturn NULL;\n\t}\n\telse {\n\t\t/* get the data, copyswap it and pass it to a new Array scalar\n\t\t */\n\t\tchar *data;\n\t\tint numbytes;\n\t\tPyArray_Descr *descr;\n\t\tPyObject *new;\n\t\tchar *newmem;\n\n\t\tnumbytes = gentype_getreadbuf(self, 0, (void **)&data);\n\t\tdescr = PyArray_DescrFromScalar(self);\n\t\tnewmem = _pya_malloc(descr->elsize);\n\t\tif (newmem == NULL) {Py_DECREF(descr); return PyErr_NoMemory();}\n\t\telse memcpy(newmem, data, descr->elsize);\n\t\tdescr->f->copyswap(newmem, NULL, 1, descr->elsize);\n\t\tnew = PyArray_Scalar(newmem, descr, NULL);\n\t\t_pya_free(newmem);\n\t\tPy_DECREF(descr);\n\t\treturn new;\n\t}\n}\n\n\n/**begin repeat\n\n#name=take, getfield, put, putmask, repeat, tofile, mean, trace, diagonal, clip, std, var, sum, cumsum, prod, cumprod, compress, sort, argsort, round, argmax, argmin, max, min, ptp, any, all, resize#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\treturn gentype_generic_method(self, args, kwds, \"@name@\");\n}\n/**end repeat**/\n\nstatic PyObject *\nvoidtype_getfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyObject *ret;\n\n\tret = gentype_generic_method((PyObject *)self, args, kwds, \"getfield\");\n\tif (!ret) return ret;\n\tif (PyArray_IsScalar(ret, Generic) &&\t\\\n\t (!PyArray_IsScalar(ret, Void))) {\n\t\tPyArray_Descr *new;\n\t\tif (!PyArray_ISNBO(self->descr->byteorder)) {\n\t\t\tnew = PyArray_DescrFromScalar(ret);\n\t\t\tnew->f->copyswap(_SOFFSET_(ret, \n\t\t\t\t\t\t new->type_num),\n\t\t\t\t\t NULL, 1, new->elsize);\n\t\t\tPy_DECREF(new);\n\t\t}\n\t}\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_setfield(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\t\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"Can't set fields in a non-void array scalar.\");\n\treturn NULL;\n}\t\n\nstatic PyObject *\nvoidtype_setfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *typecode;\n\tint offset = 0;\n\tPyObject *value, *src;\n\tint mysize;\n\tchar *dptr;\n\tstatic char *kwlist[] = {\"value\", \"dtype\", \"offset\", 0};/* XXX ? */\n\t\n\tif ((self->flags & WRITEABLE) != WRITEABLE) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"Can't write to memory\");\n\t\treturn NULL;\n\t}\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO&|i\", kwlist,\n\t\t\t\t\t &value,\n\t\t\t\t\t PyArray_DescrConverter, \n\t\t\t\t\t &typecode, &offset)) return NULL;\n\n\tmysize = self->ob_size;\n\t\n\tif (offset < 0 || (offset + typecode->elsize) > mysize) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need 0 <= offset <= %d for requested type \" \\\n\t\t\t \"but received offset = %d\",\n\t\t\t mysize-typecode->elsize, offset);\n\t\tPy_DECREF(typecode);\n\t\treturn NULL;\n\t}\t\n\n\tdptr = self->obval + offset;\n\n\t/* Copy data from value to correct place in dptr */\n src = PyArray_FromAny(value, typecode, 0, 0, CARRAY_FLAGS, NULL);\n if (src == NULL) return NULL;\n\ttypecode->f->copyswap(dptr, PyArray_DATA(src), \n\t\t\t !PyArray_ISNBO(self->descr->byteorder),\n\t\t\t PyArray_ITEMSIZE(src));\n\tPy_DECREF(src);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic PyObject *\ngentype_reduce(PyObject *self, PyObject *args)\n{\n\tPyObject *ret=NULL, *obj=NULL, *mod=NULL;\n\tconst char *buffer; \n\tint buflen;\n\n\t/* Return a tuple of (callable object, arguments) */\n\n\tret = PyTuple_New(2);\n\tif (ret == NULL) return NULL;\t\n\tif (PyObject_AsReadBuffer(self, (const void **)&buffer, &buflen)<0) {\n\t\tPy_DECREF(ret); return NULL;\n\t}\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) return NULL;\n\tobj = PyObject_GetAttrString(mod, \"scalar\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) return NULL;\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tobj = PyObject_GetAttrString((PyObject *)self, \"dtype\");\n\tif PyArray_IsScalar(self, Object) {\n\t\tmod = ((PyObjectScalarObject *)self)->obval;\n\t\tPyTuple_SET_ITEM(ret, 1,\n\t\t\t\t Py_BuildValue(\"NO\", obj, mod));\n\t}\n\telse {\n\t\tmod = PyString_FromStringAndSize(buffer, buflen);\n\t\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t\t Py_BuildValue(\"NN\", obj, mod));\n\t}\n\treturn ret;\n}\n\n/* ignores everything */\nstatic PyObject *\ngentype_setstate(PyObject *self, PyObject *args)\n{\n\tPy_INCREF(Py_None);\n\treturn (Py_None);\n}\n\nstatic PyObject *\ngentype_dump(PyObject *self, PyObject *args)\n{\n\tPyObject *file=NULL;\n\tint ret;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &file))\n\t\treturn NULL;\n\tret = PyArray_Dump(self, file, 2);\n\tif (ret < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyObject *\ngentype_dumps(PyObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\"))\n\t\treturn NULL;\n\treturn PyArray_Dumps(self, 2);\n}\n\n\n/* setting flags cannot be done for scalars */\nstatic PyObject *\ngentype_setflags(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* need to fill in doc-strings for these methods on import -- copy from \n array docstrings \n*/\nstatic PyMethodDef gentype_methods[] = {\n {\"tolist\",\t (PyCFunction)gentype_tolist,\t1, NULL},\n {\"item\", (PyCFunction)gentype_item, METH_VARARGS, NULL},\n\t{\"tofile\", (PyCFunction)gentype_tofile, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"tostring\", (PyCFunction)gentype_tostring, METH_VARARGS, NULL},\n {\"byteswap\", (PyCFunction)gentype_byteswap,1, NULL},\n {\"astype\", (PyCFunction)gentype_astype, 1, NULL},\n\t{\"getfield\", (PyCFunction)gentype_getfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{\"setfield\", (PyCFunction)gentype_setfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n {\"copy\", (PyCFunction)gentype_copy, 1, NULL}, \n {\"resize\", (PyCFunction)gentype_resize, 1, NULL}, \n\n\t{\"__array__\", (PyCFunction)gentype_getarray, 1, doc_getarray},\n\t{\"__array_wrap__\", (PyCFunction)gentype_wraparray, 1, doc_sc_wraparray},\n\n /* for the copy module */\n {\"__copy__\", (PyCFunction)gentype_copy, 1, NULL},\n {\"__deepcopy__\", (PyCFunction)gentype___deepcopy__, 1, NULL},\n\n\n {\"__reduce__\", (PyCFunction) gentype_reduce, 1, NULL},\t\n\t/* For consistency does nothing */\n\t{\"__setstate__\", (PyCFunction) gentype_setstate, 1, NULL},\n\n\t{\"dumps\", (PyCFunction) gentype_dumps, 1, NULL},\n\t{\"dump\", (PyCFunction) gentype_dump, 1, NULL},\n\n\t/* Methods for array */\n\t{\"fill\", (PyCFunction)gentype_fill,\n\t METH_VARARGS, NULL},\n\t{\"transpose\",\t(PyCFunction)gentype_transpose, \n\t METH_VARARGS, NULL},\n\t{\"take\",\t(PyCFunction)gentype_take, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"put\",\t(PyCFunction)gentype_put, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"putmask\",\t(PyCFunction)gentype_putmask, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"repeat\",\t(PyCFunction)gentype_repeat, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"choose\",\t(PyCFunction)gentype_choose, \n\t METH_VARARGS, NULL},\t\n\t{\"sort\",\t(PyCFunction)gentype_sort, \n\t METH_VARARGS, NULL},\n\t{\"argsort\",\t(PyCFunction)gentype_argsort, \n\t METH_VARARGS, NULL},\n\t{\"searchsorted\", (PyCFunction)gentype_searchsorted, \n\t METH_VARARGS, NULL},\t\n\t{\"argmax\",\t(PyCFunction)gentype_argmax, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"argmin\", (PyCFunction)gentype_argmin,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"reshape\",\t(PyCFunction)gentype_reshape, \n\t METH_VARARGS, NULL},\n\t{\"squeeze\",\t(PyCFunction)gentype_squeeze, \n\t METH_VARARGS, NULL},\n\t{\"view\", (PyCFunction)gentype_view, \n\t METH_VARARGS, NULL},\n\t{\"swapaxes\", (PyCFunction)gentype_swapaxes,\n\t METH_VARARGS, NULL},\n\t{\"max\", (PyCFunction)gentype_max,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"min\", (PyCFunction)gentype_min,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"ptp\", (PyCFunction)gentype_ptp,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"mean\", (PyCFunction)gentype_mean,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"trace\", (PyCFunction)gentype_trace,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"diagonal\", (PyCFunction)gentype_diagonal,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"clip\", (PyCFunction)gentype_clip,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"conj\", (PyCFunction)gentype_conj,\n\t METH_VARARGS, NULL},\n\t{\"conjugate\", (PyCFunction)gentype_conjugate,\n\t METH_VARARGS, NULL},\n\t{\"nonzero\", (PyCFunction)gentype_nonzero,\n\t METH_VARARGS, NULL},\n\t{\"std\", (PyCFunction)gentype_std,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"var\", (PyCFunction)gentype_var,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"sum\", (PyCFunction)gentype_sum,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"cumsum\", (PyCFunction)gentype_cumsum,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"prod\", (PyCFunction)gentype_prod,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"cumprod\", (PyCFunction)gentype_cumprod,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"all\", (PyCFunction)gentype_all,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"any\", (PyCFunction)gentype_any,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"compress\", (PyCFunction)gentype_compress,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"flatten\", (PyCFunction)gentype_flatten,\n\t METH_VARARGS, NULL},\n\t{\"ravel\", (PyCFunction)gentype_ravel,\n\t METH_VARARGS, NULL},\n\t{\"round\", (PyCFunction)gentype_round,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"setflags\", (PyCFunction)gentype_setflags,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"newbyteorder\", (PyCFunction)gentype_newbyteorder,\n\t METH_VARARGS, NULL},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\nstatic PyGetSetDef voidtype_getsets[] = {\n {\"flags\", \n\t (getter)voidtype_flags_get, \n\t (setter)0, \n\t \"integer value of flags\"},\n\t{\"dtype\",\n\t (getter)voidtype_dtypedescr_get,\n\t (setter)0,\n\t \"dtype object\"},\n\t{NULL, NULL}\n};\n\nstatic PyMethodDef voidtype_methods[] = {\n\t{\"getfield\", (PyCFunction)voidtype_getfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{\"setfield\", (PyCFunction)voidtype_setfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{NULL, NULL}\n};\n\n/************* As_mapping functions for void array scalar ************/\n\nstatic int\nvoidtype_length(PyVoidScalarObject *self) \n{\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\treturn 0;\n\t}\n\telse { /* return the number of fields */\n\t\tPyObject *key;\n\t\tPyObject *flist;\n\t\tkey = PyInt_FromLong(-1);\n\t\tflist = PyDict_GetItem(self->descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!flist) return 0;\n\t\treturn PyTuple_GET_SIZE(flist);\n\t}\n}\n\n/* get field by name or number */\nstatic PyObject *\nvoidtype_subscript(PyVoidScalarObject *self, PyObject *ind)\n{\n\tint n, m;\n\tchar *msg = \"invalid index\";\n\tPyObject *flist=NULL, *key, *fieldinfo;\n\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"can't index void scalar without fields\");\n\t\treturn NULL;\n\t}\n\n\tif (PyString_Check(ind) || PyUnicode_Check(ind)) {\n\t\t/* look up in fields */\n\t\tfieldinfo = PyDict_GetItem(self->descr->fields, ind);\n\t\tif (!fieldinfo) {\n\t\t\tPyErr_SetString(PyExc_IndexError, msg);\n\t\t\treturn NULL;\n\t\t}\n\t\treturn voidtype_getfield(self, fieldinfo, NULL);\n\t}\n\t\n\t/* try to convert it to a number */\n\tn = PyArray_PyIntAsIntp(ind);\n\tif (error_converting(n)) {\n\t\tPyErr_Clear();\n\t\tgoto fail;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tflist = PyDict_GetItem(self->descr->fields, key);\n\tPy_DECREF(key);\n\tif (!flist) m = 0; \n\tm = PyTuple_GET_SIZE(flist);\n\tif (n < 0) n += m;\n\tif (n < 0 || n >= m) goto fail;\n\tfieldinfo = PyDict_GetItem(self->descr->fields, \n\t\t\t\t PyTuple_GET_ITEM(flist, n));\n\treturn voidtype_getfield(self, fieldinfo, NULL);\n\n fail:\n\tPyErr_SetString(PyExc_IndexError, msg);\n\treturn NULL;\n}\n\nstatic int\nvoidtype_ass_subscript(PyVoidScalarObject *self, PyObject *ind, PyObject *val) \n{\n\tint n, m;\n\tchar *msg = \"invalid index\";\n\tPyObject *flist=NULL, *key, *fieldinfo, *newtup;\n\tPyObject *res;\n\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"can't index void scalar without fields\");\n\t\treturn -1;\n\t}\n\n\tif (PyString_Check(ind) || PyUnicode_Check(ind)) {\n\t\t/* look up in fields */\n\t\tfieldinfo = PyDict_GetItem(self->descr->fields, ind);\n\t\tif (!fieldinfo) {\n\t\t\tPyErr_SetString(PyExc_IndexError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tnewtup = Py_BuildValue(\"(OOO)\", val, \n\t\t\t\t PyTuple_GET_ITEM(fieldinfo, 0),\n\t\t\t\t PyTuple_GET_ITEM(fieldinfo, 1));\n\t\tres = voidtype_setfield(self, newtup, NULL);\n\t\tPy_DECREF(newtup);\n\t\tif (!res) return -1;\n\t\tPy_DECREF(res);\n\t\treturn 0;\n\t}\n\t\n\t/* try to convert it to a number */\n\tn = PyArray_PyIntAsIntp(ind);\n\tif (error_converting(n)) {\n\t\tPyErr_Clear();\n\t\tgoto fail;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tflist = PyDict_GetItem(self->descr->fields, key);\n\tPy_DECREF(key);\n\tif (!flist) m = 0; \n\tm = PyTuple_GET_SIZE(flist);\n\tif (n < 0) n += m;\n\tif (n < 0 || n >= m) goto fail;\n\tfieldinfo = PyDict_GetItem(self->descr->fields, \n\t\t\t\t PyTuple_GET_ITEM(flist, n));\n\tnewtup = Py_BuildValue(\"(OOO)\", val, \n\t\t\t PyTuple_GET_ITEM(fieldinfo, 0),\n\t\t\t PyTuple_GET_ITEM(fieldinfo, 1));\n\tres = voidtype_setfield(self, fieldinfo, NULL);\n\tPy_DECREF(newtup);\n\tif (!res) return -1;\n\tPy_DECREF(res);\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_IndexError, msg);\n\treturn -1;\n}\n\nstatic PyMappingMethods voidtype_as_mapping = {\n (inquiry)voidtype_length,\t\t /*mp_length*/\n (binaryfunc)voidtype_subscript,\t /*mp_subscript*/\n (objobjargproc)voidtype_ass_subscript,\t /*mp_ass_subscript*/\n};\n\n\nstatic int\ngentype_getreadbuf(PyObject *self, int segment, void **ptrptr)\n{\n\tint numbytes;\n\tPyArray_Descr *outcode;\n\t\n\tif (segment != 0) {\n\t\tPyErr_SetString(PyExc_SystemError, \n\t\t\t\t\"Accessing non-existent array segment\");\n\t\treturn -1;\n\t}\n\n\toutcode = PyArray_DescrFromScalar(self);\n\tnumbytes = outcode->elsize;\n\tif PyArray_IsScalar(self, Flexible) {\n\t\tif PyArray_IsScalar(self, String)\n\t\t\t*ptrptr = PyString_AS_STRING(self);\n\t\telse if PyArray_IsScalar(self, Unicode)\n\t\t\t*ptrptr = (char *)PyUnicode_AS_DATA(self);\n\t\telse if PyArray_IsScalar(self, Void)\n\t\t\t*ptrptr = ((PyVoidScalarObject *)self)->obval;\n\t}\n\telse \n\t\t*ptrptr = (void *)_SOFFSET_(self, outcode->type_num);\n\n\tPy_DECREF(outcode);\n\treturn numbytes;\n}\n\nstatic int\ngentype_getsegcount(PyObject *self, int *lenp)\n{\n\tPyArray_Descr *outcode;\n\n\toutcode = PyArray_DescrFromScalar(self);\n\tif (lenp)\n\t\t*lenp = outcode->elsize;\n\tPy_DECREF(outcode);\n\treturn 1;\n}\n\nstatic int\ngentype_getcharbuf(PyObject *self, int segment, const char **ptrptr)\n{\n\tif (PyArray_IsScalar(self, String) ||\t\\\n\t PyArray_IsScalar(self, Unicode))\n\t\treturn gentype_getreadbuf(self, segment, (void **)ptrptr);\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"Non-character array cannot be interpreted \"\\\n\t\t\t\t\"as character buffer.\");\n\t\treturn -1;\n\t}\n}\n\n\nstatic PyBufferProcs gentype_as_buffer = {\n (getreadbufferproc)gentype_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)0, /*bf_getwritebuffer*/\n (getsegcountproc)gentype_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)gentype_getcharbuf, /*bf_getcharbuffer*/\n};\n\n\n#define BASEFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES\n#define LEAFFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES\n\nstatic PyTypeObject PyGenericArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"genericscalar\",\t /*tp_name*/\n sizeof(PyObject),\t\t /*tp_basicsize*/\n};\n\nstatic void\nunicode_dealloc(PyObject *v) \n{\n\tPyDataMem_FREE(((PyVoidScalarObject *)v)->obval);\n\tv->ob_type->tp_free(v);\n}\n\nstatic void\nvoid_dealloc(PyVoidScalarObject *v) \n{\n\tif (v->flags & OWNDATA)\n\t\tPyDataMem_FREE(v->obval);\n\tPy_XDECREF(v->descr);\n\tPy_XDECREF(v->base);\n\tv->ob_type->tp_free(v);\n}\n\nstatic void\nobject_arrtype_dealloc(PyObject *v)\n{\n\tPy_XDECREF(((PyObjectScalarObject *)v)->obval);\n\tv->ob_type->tp_free(v);\n}\n\n/* string and unicode inherit from Python Type first and so GET_ITEM is different to\n get to the Python Type.\n */\n\n/**begin repeat \n#name=byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, object#\n#TYPE=BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, STRING, UNICODE, OBJECT#\n#num=1*16,0,0,1#\n*/\nstatic PyObject *\n@name@_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj=NULL;\n\tPyObject *arr;\n\tPyArray_Descr *typecode;\n\n\tif (type->tp_bases && (PyTuple_GET_SIZE(type->tp_bases)==2)) {\n\t\tPyTypeObject *sup;\n\t\tPyObject *ret;\n\t\t/* We are inheriting from a Python type as well so\n\t\t give it first dibs on conversion */\n\t\tsup = (PyTypeObject *)PyTuple_GET_ITEM(type->tp_bases, @num@);\n\t\tret = sup->tp_new(type, args, kwds);\n\t\tif (ret) return ret;\n\t\tPyErr_Clear();\n\t\t/* now do default conversion */\n\t}\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\n\ttypecode = PyArray_DescrFromType(PyArray_@TYPE@);\n\tarr = PyArray_FromAny(obj, typecode, 0, 0, FORCECAST, NULL);\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n/**end repeat**/\n\n/* bool->tp_new only returns Py_True or Py_False */\nstatic PyObject *\nbool_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj=NULL;\n\tPyObject *arr;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\tif (obj == Py_False)\n\t\tPyArrayScalar_RETURN_FALSE;\n\tif (obj == Py_True)\n\t\tPyArrayScalar_RETURN_TRUE;\n\tarr = PyArray_FROM_OTF(obj, PyArray_BOOL, FORCECAST);\n\tif (arr && 0 == PyArray_NDIM(arr)) {\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)PyArray_DATA(arr));\n\t}\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n\nstatic PyObject *\nbool_arrtype_and(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)&(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_and(a, b);\n}\n\nstatic PyObject *\nbool_arrtype_or(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)|(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_or(a, b);\n}\n\nstatic PyObject *\nbool_arrtype_xor(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)^(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_xor(a, b);\n}\n\nstatic int\nbool_arrtype_nonzero(PyObject *a)\n{\n\treturn a == PyArrayScalar_True;\n}\n\n/* Arithmetic methods -- only so we can override &, |, ^. */\nstatic PyNumberMethods bool_arrtype_as_number = {\n\t0,\t\t\t\t\t/* nb_add */\n\t0,\t\t\t\t\t/* nb_subtract */\n\t0,\t\t\t\t\t/* nb_multiply */\n\t0,\t\t\t\t\t/* nb_divide */\n\t0,\t\t\t\t\t/* nb_remainder */\n\t0,\t\t\t\t\t/* nb_divmod */\n\t0,\t\t\t\t\t/* nb_power */\n\t0,\t\t\t\t\t/* nb_negative */\n\t0,\t\t\t\t\t/* nb_positive */\n\t0,\t\t\t\t\t/* nb_absolute */\n\t(inquiry)bool_arrtype_nonzero,\t\t/* nb_nonzero */\n\t0,\t\t\t\t\t/* nb_invert */\n\t0,\t\t\t\t\t/* nb_lshift */\n\t0,\t\t\t\t\t/* nb_rshift */\n\t(binaryfunc)bool_arrtype_and,\t\t/* nb_and */\n\t(binaryfunc)bool_arrtype_xor,\t\t/* nb_xor */\n\t(binaryfunc)bool_arrtype_or,\t\t/* nb_or */\n};\n\nstatic PyObject *\nvoid_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj, *arr;\n\tulonglong memu=1;\n\tPyObject *new=NULL;\n\tchar *destptr;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\t/* For a VOID scalar first see if obj is an integer or long \n\t and create new memory of that size (filled with 0) for the scalar\n\t*/\n\n\tif (PyLong_Check(obj) || PyInt_Check(obj) || \\\n\t PyArray_IsScalar(obj, Integer) ||\n\t (PyArray_Check(obj) && PyArray_NDIM(obj)==0 &&\t\\\n\t PyArray_ISINTEGER(obj))) {\n\t\tnew = obj->ob_type->tp_as_number->nb_long(obj);\n\t}\n\tif (new && PyLong_Check(new)) {\n\t\tPyObject *ret;\n\t\tmemu = PyLong_AsUnsignedLongLong(new);\n\t\tPy_DECREF(new);\n\t\tif (PyErr_Occurred() || (memu > MAX_INT)) {\n\t\t\tPyErr_Clear();\n\t\t\tPyErr_Format(PyExc_OverflowError, \n\t\t\t\t \"size must be smaller than %d\",\n\t\t\t\t (int) MAX_INT);\n\t\t\treturn NULL;\n\t\t}\n\t\tdestptr = PyDataMem_NEW((int) memu);\n\t\tif (destptr == NULL) return PyErr_NoMemory();\n\t\tret = type->tp_alloc(type, 0);\n\t\tif (ret == NULL) {\n\t\t\tPyDataMem_FREE(destptr);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\t((PyVoidScalarObject *)ret)->obval = destptr;\n\t\t((PyVoidScalarObject *)ret)->ob_size = (int) memu;\n\t\t((PyVoidScalarObject *)ret)->descr = \\\n\t\t\tPyArray_DescrNewFromType(PyArray_VOID);\n\t\t((PyVoidScalarObject *)ret)->descr->elsize = (int) memu;\n\t\t((PyVoidScalarObject *)ret)->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t((PyVoidScalarObject *)ret)->base = NULL;\n\t\tmemset(destptr, '\\0', (size_t) memu);\n\t\treturn ret;\n\t}\n\n\tarr = PyArray_FROM_OTF(obj, PyArray_VOID, FORCECAST);\n return PyArray_Return((PyArrayObject *)arr);\n}\n\n\n/**************** Define Hash functions ********************/\n\n/**begin repeat\n#lname=bool,ubyte,ushort#\n#name=Bool,UByte, UShort#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n return (long)(((Py@name@ScalarObject *)obj)->obval);\n}\n/**end repeat**/\n\n/**begin repeat\n#lname=byte,short,uint,ulong#\n#name=Byte,Short,UInt,ULong#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((Py@name@ScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n/**end repeat**/\n\n#if SIZEOF_INT != SIZEOF_LONG\nstatic long\nint_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((PyIntScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n#endif\n\n/**begin repeat\n#char=,u#\n#Char=,U#\n#ext=&& (x >= LONG_MIN),#\n*/\n#if SIZEOF_LONG != SIZEOF_LONGLONG\n/* we assume SIZEOF_LONGLONG=2*SIZEOF_LONG */\nstatic long\n@char@longlong_arrtype_hash(PyObject *obj)\n{\n long y;\n @char@longlong x = (((Py@Char@LongLongScalarObject *)obj)->obval);\n\n if ((x <= LONG_MAX)@ext@) {\n y = (long) x;\n }\n else {\n union Mask {\n long hashvals[2];\n @char@longlong v;\n } both;\n\n both.v = x;\n y = both.hashvals[0] + (1000003)*both.hashvals[1];\n }\n if (y == -1) y = -2;\n return y;\n}\n#endif\n/**end repeat**/\n\n#if SIZEOF_LONG==SIZEOF_LONGLONG\nstatic long\nulonglong_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((PyULongLongScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n#endif\n\n\n\n/* Wrong thing to do for longdouble, but....*/\n/**begin repeat\n#lname=float, longdouble#\n#name=Float, LongDouble#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n return _Py_HashDouble((double) ((Py@name@ScalarObject *)obj)->obval);\n}\n\n/* borrowed from complex_hash */\nstatic long\nc@lname@_arrtype_hash(PyObject *obj)\n{\n long hashreal, hashimag, combined;\n hashreal = _Py_HashDouble((double) \\\n (((PyC@name@ScalarObject *)obj)->obval).real);\n\n if (hashreal == -1) return -1;\n hashimag = _Py_HashDouble((double) \\\n (((PyC@name@ScalarObject *)obj)->obval).imag);\n if (hashimag == -1) return -1;\n\n combined = hashreal + 1000003 * hashimag;\n if (combined == -1) combined = -2;\n return combined;\n}\n/**end repeat**/\n\nstatic long\nobject_arrtype_hash(PyObject *obj)\n{\n return PyObject_Hash(((PyObjectScalarObject *)obj)->obval);\n}\n\n/* just hash the pointer */\nstatic long\nvoid_arrtype_hash(PyObject *obj)\n{\n return _Py_HashPointer((void *)(((PyVoidScalarObject *)obj)->obval));\n}\n\n/*object arrtype getattro and setattro */\nstatic PyObject *\nobject_arrtype_getattro(PyObjectScalarObject *obj, PyObject *attr) {\n\tPyObject *res;\n\n\t/* first look in object and then hand off to generic type */\n\n\tres = PyObject_GenericGetAttr(obj->obval, attr);\t\n\tif (res) return res;\n\tPyErr_Clear();\n\treturn \tPyObject_GenericGetAttr((PyObject *)obj, attr);\n}\n\nstatic int\nobject_arrtype_setattro(PyObjectScalarObject *obj, PyObject *attr, PyObject *val) {\n\tint res;\n\t/* first look in object and then hand off to generic type */\n\n\tres = PyObject_GenericSetAttr(obj->obval, attr, val);\n\tif (res >= 0) return res;\n\tPyErr_Clear();\n\treturn PyObject_GenericSetAttr((PyObject *)obj, attr, val);\n}\n\nstatic PyObject *\nobject_arrtype_concat(PyObjectScalarObject *self, PyObject *other)\n{\n\treturn PySequence_Concat(self->obval, other);\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_length(PyObjectScalarObject *self) \n{\n\treturn PyObject_Length(self->obval);\n}\n\nstatic PyObject *\nobject_arrtype_repeat(PyObjectScalarObject *self, _int_or_ssize_t count)\n{\n\treturn PySequence_Repeat(self->obval, count);\n}\n\nstatic PyObject *\nobject_arrtype_subscript(PyObjectScalarObject *self, PyObject *key)\n{\n\treturn PyObject_GetItem(self->obval, key);\n}\n\nstatic int\nobject_arrtype_ass_subscript(PyObjectScalarObject *self, PyObject *key, \n\t\t\t PyObject *value)\n{\n\treturn PyObject_SetItem(self->obval, key, value);\n}\n\nstatic int\nobject_arrtype_contains(PyObjectScalarObject *self, PyObject *ob)\n{\n\treturn PySequence_Contains(self->obval, ob);\n}\n\nstatic PyObject *\nobject_arrtype_inplace_concat(PyObjectScalarObject *self, PyObject *o)\n{\n\treturn PySequence_InPlaceConcat(self->obval, o);\n}\n\nstatic PyObject *\nobject_arrtype_inplace_repeat(PyObjectScalarObject *self, _int_or_ssize_t count)\n{\n\treturn PySequence_InPlaceRepeat(self->obval, count);\n}\n\nstatic PySequenceMethods object_arrtype_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)object_arrtype_length, /*sq_length*/\n (binaryfunc)object_arrtype_concat, /*sq_concat*/\n (ssizeargfunc)object_arrtype_repeat, /*sq_repeat*/\n 0, /*sq_item*/\n 0, /*sq_slice*/\n 0, /* sq_ass_item */\n 0, /* sq_ass_slice */\n (objobjproc)object_arrtype_contains, /* sq_contains */\n (binaryfunc)object_arrtype_inplace_concat, /* sq_inplace_concat */\n (ssizeargfunc)object_arrtype_inplace_repeat, /* sq_inplace_repeat */\n#else\n (inquiry)object_arrtype_length, /*sq_length*/\n (binaryfunc)object_arrtype_concat, /*sq_concat*/\n (intargfunc)object_arrtype_repeat, /*sq_repeat*/\n 0, /*sq_item*/\n 0, /*sq_slice*/\n 0, /* sq_ass_item */\n 0, /* sq_ass_slice */\n (objobjproc)object_arrtype_contains, /* sq_contains */\n (binaryfunc)object_arrtype_inplace_concat, /* sq_inplace_concat */\n (intargfunc)object_arrtype_inplace_repeat, /* sq_inplace_repeat */\n#endif\n};\n\nstatic PyMappingMethods object_arrtype_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)object_arrtype_length,\n (binaryfunc)object_arrtype_subscript,\n (objobjargproc)object_arrtype_ass_subscript,\n#else\n (inquiry)object_arrtype_length,\n (binaryfunc)object_arrtype_subscript,\n (objobjargproc)object_arrtype_ass_subscript,\n#endif\n};\n\nstatic _int_or_ssize_t\nobject_arrtype_getsegcount(PyObjectScalarObject *self, _int_or_ssize_t *lenp) \n{\n\tint newlen;\n\tint cnt;\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\t\n\tif (pb == NULL || \\\n\t pb->bf_getsegcount == NULL || \\\n\t (cnt = (*pb->bf_getsegcount)(self->obval, &newlen)) != 1) \n\t\treturn 0;\n\t\n\tif (lenp) \n\t\t*lenp = newlen;\n\t\n\treturn cnt;\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_getreadbuf(PyObjectScalarObject *self, _int_or_ssize_t segment, void **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getreadbuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a readable buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getreadbuffer)(self->obval, segment, ptrptr);\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_getwritebuf(PyObjectScalarObject *self, _int_or_ssize_t segment, void **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getwritebuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a writeable buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getwritebuffer)(self->obval, segment, ptrptr);\n}\n\nstatic _int_or_ssize_t \nobject_arrtype_getcharbuf(PyObjectScalarObject *self, _int_or_ssize_t segment, \n\t\t\t const char **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getcharbuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a character buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getcharbuffer)(self->obval, segment, ptrptr);\n}\n\nstatic PyBufferProcs object_arrtype_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)object_arrtype_getreadbuf,\n (writebufferproc)object_arrtype_getwritebuf,\n (segcountproc)object_arrtype_getsegcount,\n (charbufferproc)object_arrtype_getcharbuf,\n#else\n (getreadbufferproc)object_arrtype_getreadbuf,\n (getwritebufferproc)object_arrtype_getwritebuf,\n (getsegcountproc)object_arrtype_getsegcount,\n (getcharbufferproc)object_arrtype_getcharbuf,\n#endif\n};\n\nstatic PyObject *\nobject_arrtype_call(PyObjectScalarObject *obj, PyObject *args, PyObject *kwds)\n{\n\treturn PyObject_Call(obj->obval, args, kwds);\n}\n\nstatic PyTypeObject PyObjectArrType_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"objectscalar\",\t /*tp_name*/\n sizeof(PyObjectScalarObject),\t /*tp_basicsize*/\n 0, /* tp_itemsize */\n (destructor)object_arrtype_dealloc, /* tp_dealloc */\n 0, /* tp_print */\n 0, /* tp_getattr */\n 0, /* tp_setattr */\n 0, /* tp_compare */\n 0, /* tp_repr */\n 0, /* tp_as_number */\n &object_arrtype_as_sequence, /* tp_as_sequence */\n &object_arrtype_as_mapping, /* tp_as_mapping */\n 0, /* tp_hash */\n (ternaryfunc)object_arrtype_call, /* tp_call */\n 0, /* tp_str */\n (getattrofunc)object_arrtype_getattro, /* tp_getattro */\n (setattrofunc)object_arrtype_setattro, /* tp_setattro */\n &object_arrtype_as_buffer, /* tp_as_buffer */\n 0, /* tp_flags */\n};\n\n/**begin repeat\n#name=bool, string, unicode, void#\n#NAME=Bool, String, Unicode, Void#\n*/\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@scalar\",\t /*tp_name*/\n sizeof(Py@NAME@ScalarObject),\t /*tp_basicsize*/\n};\n/**end repeat**/\n\n/**begin repeat\n#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n#name=int*5, uint*5, float*3, complex*3#\n#CNAME=(CHAR, SHORT, INT, LONG, LONGLONG)*2, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n*/\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@\" STRBITSOF_@CNAME@ \"scalar\",\t /*tp_name*/\n sizeof(Py@NAME@ScalarObject),\t /*tp_basicsize*/\n};\n\n/**end repeat**/\n\n\nstatic PyNumberMethods longdoubletype_as_number;\nstatic PyNumberMethods clongdoubletype_as_number;\n\n\nstatic void\ninitialize_numeric_types(void)\n{\n\tPyGenericArrType_Type.tp_dealloc = (destructor)gentype_dealloc;\n\tPyGenericArrType_Type.tp_as_number = &gentype_as_number;\n\tPyGenericArrType_Type.tp_as_buffer = &gentype_as_buffer;\n\tPyGenericArrType_Type.tp_flags = BASEFLAGS;\n\tPyGenericArrType_Type.tp_methods = gentype_methods;\n\tPyGenericArrType_Type.tp_getset = gentype_getsets;\n\tPyGenericArrType_Type.tp_new = NULL;\n PyGenericArrType_Type.tp_alloc = gentype_alloc;\n\tPyGenericArrType_Type.tp_free = _pya_free;\n\tPyGenericArrType_Type.tp_repr = gentype_repr;\n\tPyGenericArrType_Type.tp_str = gentype_str;\n\tPyGenericArrType_Type.tp_richcompare = gentype_richcompare;\n\n\tPyBoolArrType_Type.tp_as_number = &bool_arrtype_as_number;\n\n\tPyStringArrType_Type.tp_alloc = NULL;\n\tPyStringArrType_Type.tp_free = NULL;\n\t\n\tPyStringArrType_Type.tp_repr = stringtype_repr;\n\tPyStringArrType_Type.tp_str = stringtype_str;\n\n\tPyUnicodeArrType_Type.tp_repr = unicodetype_repr;\n\tPyUnicodeArrType_Type.tp_str = unicodetype_str;\n\n\tPyVoidArrType_Type.tp_methods = voidtype_methods;\n\tPyVoidArrType_Type.tp_getset = voidtype_getsets;\n\tPyVoidArrType_Type.tp_as_mapping = &voidtype_as_mapping;\n\t\n\t/**begin repeat\n#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating, \nComplexFloating, Flexible, Character#\n\t*/\n Py@NAME@ArrType_Type.tp_flags = BASEFLAGS;\n\t/**end repeat**/\n\n\t/**begin repeat\n#name=bool, byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, void, object#\n#NAME=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, String, Unicode, Void, Object#\n\t*/\n\tPy@NAME@ArrType_Type.tp_flags = LEAFFLAGS;\n\tPy@NAME@ArrType_Type.tp_new = @name@_arrtype_new;\n\tPy@NAME@ArrType_Type.tp_richcompare = gentype_richcompare;\n\t/**end repeat**/\n\t/* Allow the Void type to be subclassed -- for adding new types */\n\tPyVoidArrType_Type.tp_flags = BASEFLAGS;\n\n /**begin repeat\n#name=bool, byte, short, ubyte, ushort, uint, ulong, ulonglong, float, longdouble, cfloat, clongdouble, void, object#\n#NAME=Bool, Byte, Short, UByte, UShort, UInt, ULong, ULongLong, Float, LongDouble, CFloat, CLongDouble, Void, Object#\n */\n Py@NAME@ArrType_Type.tp_hash = @name@_arrtype_hash;\n /**end repeat**/\n\n#if SIZEOF_INT != SIZEOF_LONG\n /* We won't be inheriting from Python Int type. */\n PyIntArrType_Type.tp_hash = int_arrtype_hash;\n#endif\n\n#if SIZEOF_LONG != SIZEOF_LONGLONG\n /* We won't be inheriting from Python Int type. */\n PyLongLongArrType_Type.tp_hash = longlong_arrtype_hash;\n#endif\n\n\t/* These need to be coded specially because getitem does not\n\t return a normal Python type\n\t*/\n\tPyLongDoubleArrType_Type.tp_as_number = &longdoubletype_as_number;\n\tPyCLongDoubleArrType_Type.tp_as_number = &clongdoubletype_as_number;\n\n\t/**begin repeat\n#name=int, long, hex, oct, float, repr, str#\n#kind=tp_as_number->nb*5, tp*2#\n\t*/\n\tPyLongDoubleArrType_Type.@kind@_@name@ = longdoubletype_@name@;\n\tPyCLongDoubleArrType_Type.@kind@_@name@ = clongdoubletype_@name@;\n\t/**end repeat**/\n\n\tPyStringArrType_Type.tp_itemsize = sizeof(char);\n\tPyVoidArrType_Type.tp_dealloc = (destructor) void_dealloc;\n\tPyUnicodeArrType_Type.tp_dealloc = unicode_dealloc;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMapIter_Type.tp_iter = PyObject_SelfIter;\n\n/**begin repeat\n#name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,#\n#num=BOOL, BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, OBJECT, NTYPES#\n**/\n PyArrayScalar_Offset[PyArray_@num@] = (int) offsetof(Py@name@ScalarObject, obval);\n/**end repeat**/\n}\n\n\n/* the order of this table is important */\nstatic PyTypeObject *typeobjects[] = {\n &PyBoolArrType_Type,\n &PyByteArrType_Type,\n\t&PyUByteArrType_Type,\n &PyShortArrType_Type,\n &PyUShortArrType_Type,\n\t&PyIntArrType_Type,\n\t&PyUIntArrType_Type,\n\t&PyLongArrType_Type,\n\t&PyULongArrType_Type,\n\t&PyLongLongArrType_Type,\n\t&PyULongLongArrType_Type,\n\t&PyFloatArrType_Type,\n\t&PyDoubleArrType_Type,\n\t&PyLongDoubleArrType_Type,\n\t&PyCFloatArrType_Type,\n\t&PyCDoubleArrType_Type,\n\t&PyCLongDoubleArrType_Type,\n\t&PyObjectArrType_Type,\n\t&PyStringArrType_Type,\n\t&PyUnicodeArrType_Type,\n\t&PyVoidArrType_Type\n};\n\nstatic int\n_typenum_fromtypeobj(PyObject *type, int user)\n{\n\tint typenum, i;\n\n\ttypenum = PyArray_NOTYPE;\n i = 0;\n\twhile(i < PyArray_NTYPES) {\n\t\tif (type == (PyObject *)typeobjects[i]) {\n\t\t\ttypenum = i;\n\t\t\tbreak;\n\t\t}\n i++;\n\t}\n\t\n\tif (!user) return typenum;\n\n\t/* Search any registered types */\n\ti = 0;\n\twhile (i < PyArray_NUMUSERTYPES) {\n\t\tif (type == (PyObject *)(userdescrs[i]->typeobj)) {\n\t\t\ttypenum = i + PyArray_USERDEF;\n\t\t\tbreak;\n\t\t}\n\t\ti++;\n\t}\n\treturn typenum;\n}\n\n/* new reference */\nstatic PyArray_Descr *\nPyArray_DescrFromTypeObject(PyObject *type)\n{\t\n\tint typenum;\n\tPyArray_Descr *new, *conv=NULL;\n\n\t/* if it's a builtin type, then use the typenumber */\n\ttypenum = _typenum_fromtypeobj(type,1);\t\n\tif (typenum != PyArray_NOTYPE) {\n\t\tnew = PyArray_DescrFromType(typenum);\n\t\tif (PyTypeNum_ISUSERDEF(typenum)) goto finish;\n\t\treturn new;\n\t}\n\n\t/* Check the generic types */\n\tif ((type == (PyObject *) &PyNumberArrType_Type) ||\t\t\\\n\t (type == (PyObject *) &PyInexactArrType_Type) ||\t\t\\\n\t (type == (PyObject *) &PyFloatingArrType_Type))\n\t\ttypenum = PyArray_DOUBLE;\n\telse if (type == (PyObject *)&PyComplexFloatingArrType_Type)\n\t\ttypenum = PyArray_CDOUBLE;\n\telse if ((type == (PyObject *)&PyIntegerArrType_Type) ||\t\\\n\t\t (type == (PyObject *)&PySignedIntegerArrType_Type))\n\t\ttypenum = PyArray_LONG;\n\telse if (type == (PyObject *) &PyUnsignedIntegerArrType_Type)\n\t\ttypenum = PyArray_ULONG;\n\telse if (type == (PyObject *) &PyCharacterArrType_Type)\n\t\ttypenum = PyArray_STRING;\n\telse if ((type == (PyObject *) &PyGenericArrType_Type) || \\\n\t\t (type == (PyObject *) &PyFlexibleArrType_Type))\n\t\ttypenum = PyArray_VOID;\n\n\tif (typenum != PyArray_NOTYPE) {\n\t\treturn PyArray_DescrFromType(typenum);\n\t}\n\t\n\t/* Otherwise --- type is a sub-type of an array scalar\n\t currently only VOID allows it -- use it as the type-object.\n\t*/\n\t/* look for a dtypedescr attribute */\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\n finish:\n\tconv = _arraydescr_fromobj(type);\n\tif (conv) {\n\t\tnew->fields = conv->fields;\n\t\tPy_INCREF(new->fields);\n\t\tnew->elsize = conv->elsize;\n\t\tnew->subarray = conv->subarray;\n\t\tconv->subarray = NULL;\n\t\tPy_DECREF(conv);\n\t}\n Py_DECREF(new->typeobj);\n new->typeobj = (PyTypeObject *)type;\n Py_INCREF(type);\n\treturn new;\n}\n\n/* New reference */\n/*OBJECT_API\n Return descr object from array scalar.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromScalar(PyObject *sc)\n{\n\tint type_num;\n\tPyArray_Descr *descr;\n\n\tif PyArray_IsScalar(sc, Void) {\n\t\tdescr = ((PyVoidScalarObject *)sc)->descr;\n\t\tPy_INCREF(descr);\n\t\treturn descr;\n\t}\n descr = PyArray_DescrFromTypeObject((PyObject *)sc->ob_type);\n if (descr->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(descr);\n type_num = descr->type_num;\n\t\tif (type_num == PyArray_STRING) \n\t\t\tdescr->elsize = PyString_GET_SIZE(sc);\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tdescr->elsize = PyUnicode_GET_DATA_SIZE(sc);\n#ifndef Py_UNICODE_WIDE\n\t\t\tdescr->elsize <<= 1;\n#endif\t\t\n\t\t}\n\t\telse {\n\t\t\tdescr->elsize =\t\t\t\t\t\\\n\t\t\t\t((PyVoidScalarObject *)sc)->ob_size;\n\t\t\tdescr->fields = PyObject_GetAttrString(sc, \"fields\");\n\t\t\tif (!descr->fields || !PyDict_Check(descr->fields) || \\\n\t\t\t (descr->fields == Py_None)) {\n\t\t\t\tPy_XDECREF(descr->fields);\n\t\t\t\tdescr->fields = NULL;\n\t\t\t}\n\t\t\tPyErr_Clear();\n\t\t}\n }\n\treturn descr;\n}\n\n/* New reference */\n/*OBJECT_API\n Get a typeobject from a type-number\n*/\nstatic PyObject *\nPyArray_TypeObjectFromType(int type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr == NULL) return NULL;\n\tobj = (PyObject *)descr->typeobj;\n\tPy_INCREF(obj);\n\tPy_DECREF(descr);\n\treturn obj;\n}\n\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "#ifndef _MULTIARRAYMODULE", + "#define _MULTIARRAYMODULE", + "#endif", + "#include \"numpy/arrayscalars.h\"", + "static PyBoolScalarObject _PyArrayScalar_BoolValues[2] = {", + "\tbool_arrtype_or,\t\t\t/* nb_add */", + "\tbool_arrtype_and,\t\t\t/* nb_multiply */" + ], + "deleted": [ + "/* to be exposed in C-API */", + "#define PyArrayScalar_False ((PyObject *)&_PyArrayScalar_BoolValues[0])", + "#define PyArrayScalar_True ((PyObject *)&_PyArrayScalar_BoolValues[1])", + "#define PyArrayScalar_RETURN_BOOL_FROM_LONG(i)\t\t\t\\", + "\treturn Py_INCREF(&_PyArrayScalar_BoolValues[((i)!=0)]),\t\\", + "\t\t(PyObject *)&_PyArrayScalar_BoolValues[((i)!=0)]", + "#define PyArrayScalar_RETURN_FALSE\t\t\\", + "\treturn Py_INCREF(PyArrayScalar_False),\t\\", + "\t\tPyArrayScalar_False", + "#define PyArrayScalar_RETURN_TRUE\t\t\\", + "\treturn Py_INCREF(PyArrayScalar_True),\t\\", + "\t\tPyArrayScalar_True", + "/* end to be exposed in C-API */", + "/**begin repeat", + "#name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,#", + "#type=Bool, signed char, short, int, long, longlong, unsigned char, unsigned short, unsigned int, unsigned long, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, PyObject *,char#", + "*/", + "typedef struct {", + "\tPyObject_HEAD", + "\t@type@ obval;", + "} Py@name@ScalarObject;", + "/**end repeat**/", + "", + "static PyBoolScalarObject _PyArrayScalar_BoolValues[] = {", + "#define PyStringScalarObject PyStringObject", + "#define PyUnicodeScalarObject PyUnicodeObject", + "", + "typedef struct {", + "\tPyObject_VAR_HEAD", + "\tchar *obval;", + "\tPyArray_Descr *descr;", + "\tint flags;", + "\tPyObject *base;", + "} PyVoidScalarObject;", + "", + "\t0,\t\t\t\t\t/* nb_add */", + "\t0,\t\t\t\t\t/* nb_multiply */" + ] + } + } + ] + }, + { + "hash": "959f36c04ce8ca0b7bc44bb6438bddf162ad2db9", + "msg": "Fix cov and corrcoef in numpy", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-16T17:36:38+00:00", + "author_timezone": 0, + "committer_date": "2006-03-16T17:36:38+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "4506c519cd88710615cb83810b7ddc96773985a4" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 26, + "insertions": 32, + "lines": 58, + "files": 1, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/lib/function_base.py", + "new_path": "numpy/lib/function_base.py", + "filename": "function_base.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -622,47 +622,53 @@ def __call__(self, *args):\n else:\n return tuple([x.astype(c) for x, c in zip(self.ufunc(*args), self.otypes)])\n \n-def cov(m,y=None, rowvar=0, bias=0):\n+def cov(m,y=None, rowvar=1, bias=0):\n \"\"\"Estimate the covariance matrix.\n \n- If m is a vector, return the variance. For matrices where each row\n- is an observation, and each column a variable, return the covariance\n- matrix. Note that in this case diag(cov(m)) is a vector of\n- variances for each column.\n+ If m is a vector, return the variance. For matrices return the\n+ covariance matrix.\n \n- cov(m) is the same as cov(m, m)\n+ If y is given it is treated as an additional (set of)\n+ variable(s). \n \n Normalization is by (N-1) where N is the number of observations\n (unbiased estimate). If bias is 1 then normalization is by N.\n \n- If rowvar is zero, then each row is a variable with\n- observations in the columns.\n+ If rowvar is non-zero (default), then each row is a variable with\n+ observations in the columns, otherwise each column\n+ is a variable and the observations are in the rows.\n \"\"\"\n- if y is None:\n- y = asarray(m)\n+\n+ X = asarray(m,ndmin=2)\n+ if X.shape[0] == 1:\n+ rowvar = 1\n+ if rowvar:\n+ axis = 0\n+ tup = (newaxis, slice(None))\n else:\n- y = asarray(y)\n- m = asarray(m)\n+ axis = 1\n+ tup = (slice(None),newaxis)\n+ \n+ if y is not None:\n+ y = asarray(y,ndmin=2)\n+ X = concatenate((X,y),axis)\n+\n+ X -= X.mean(axis=axis)[tup]\n if rowvar:\n- m = m.transpose()\n- y = y.transpose()\n- if (m.shape[0] == 1):\n- m = m.transpose()\n- if (y.shape[0] == 1):\n- y = y.transpose()\n- N = m.shape[0]\n- if (y.shape[0] != N):\n- raise ValueError, \"x and y must have the same number of observations.\"\n- m = m - m.mean(axis=0)\n- y = y - y.mean(axis=0)\n+ N = X.shape[1]\n+ else:\n+ N = X.shape[0]\n+\n if bias:\n fact = N*1.0\n else:\n fact = N-1.0\n \n- val = squeeze(dot(m.transpose(),y.conj()) / fact)\n- return val\n-\n+ if not rowvar:\n+ return (dot(X.transpose(), X.conj()) / fact).squeeze()\n+ else:\n+ return (dot(X,X.transpose().conj())/fact).squeeze()\n+ \n def corrcoef(x, y=None):\n \"\"\"The correlation coefficients\n \"\"\"\n", + "added_lines": 32, + "deleted_lines": 26, + "source_code": "\n__all__ = ['logspace', 'linspace',\n 'select', 'piecewise', 'trim_zeros',\n 'copy', 'iterable', #'base_repr', 'binary_repr',\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', 'cov', 'corrcoef', 'msort',\n 'median', 'sinc', 'hamming', 'hanning', 'bartlett', 'blackman',\n 'kaiser', 'trapz', 'i0', 'add_newdoc', 'add_docstring',\n ]\n\nimport types\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import ones, zeros, arange, concatenate, array, \\\n asarray, empty, empty_like, asanyarray\nfrom numpy.core.numeric import ScalarType, dot, where, newaxis\nfrom numpy.core.umath import pi, multiply, add, arctan2, \\\n frompyfunc, isnan, cos, less_equal, sqrt, sin, mod, exp\nfrom numpy.core.oldnumeric import ravel, nonzero, choose, \\\n typecodes, ArrayType, squeeze,\\\n sort\nfrom type_check import ScalarType\nfrom shape_base import atleast_1d\nfrom twodim_base import diag\nfrom _compiled_base import digitize, bincount, _insert, add_docstring\n\n#end Fernando's utilities\n\n\ndef linspace(start, stop, num=50, endpoint=True, retstep=False):\n \"\"\"Return evenly spaced numbers.\n\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 num = int(num)\n if num <= 0:\n return array([])\n if endpoint:\n if num == 1:\n return array([start])\n step = (stop-start)/float((num-1))\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 logspace(start,stop,num=50,endpoint=True,base=10.0):\n \"\"\"Evenly spaced numbers on a logarithmic scale.\n\n Computes int(num) evenly spaced exponents from start to stop.\n If endpoint=True, then last exponent is stop.\n Returns base**exponents.\n \"\"\"\n y = linspace(start,stop,num=num,endpoint=endpoint)\n return _nx.power(base,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 = [mi+0.0 for mi in range]\n if mn == mx:\n mn -= 0.5\n mx += 0.5\n bins = linspace(mn, mx, bins, endpoint=False)\n\n n = sort(a).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(n.shape) * 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\ndef asarray_chkfinite(a):\n \"\"\"Like asarray, but check that no NaNs or Infs are present.\n \"\"\"\n a = asarray(a)\n if (a.dtype.char 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\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 A constant may be used in funclist for a function that returns a\n constant (e.g. val and lambda x: val are equivalent in a funclist).\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 x = asanyarray(x)\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[k]\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\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.dtype.char\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.dtype.char)\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.type, _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 numpy\n >>> a = array((0, 0, 0, 1, 2, 3, 2, 1, 0))\n >>> numpy.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 _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.type, _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.type, _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.type, _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.type, _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.type, _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(object):\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 numpy arrays as inputs and returns a\n numpy 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 numpy.\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 = fcode.co_argcount\n if pyfunc.func_defaults:\n self.nin_wo_defaults = self.nin - len(pyfunc.func_defaults)\n else:\n self.nin_wo_defaults = self.nin\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 self.lastcallargs = 0\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 nargs = len(args)\n if (nargs > self.nin) or (nargs < self.nin_wo_defaults):\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]).dtype.char)\n self.otypes = ''.join(otypes)\n\n if (self.ufunc is None) or (self.lastcallargs != nargs):\n self.ufunc = frompyfunc(self.thefunc, nargs, self.nout)\n self.lastcallargs = nargs\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\ndef cov(m,y=None, rowvar=1, bias=0):\n \"\"\"Estimate the covariance matrix.\n\n If m is a vector, return the variance. For matrices return the\n covariance matrix.\n\n If y is given it is treated as an additional (set of)\n variable(s). \n\n Normalization is by (N-1) where N is the number of observations\n (unbiased estimate). If bias is 1 then normalization is by N.\n\n If rowvar is non-zero (default), then each row is a variable with\n observations in the columns, otherwise each column\n is a variable and the observations are in the rows.\n \"\"\"\n\n X = asarray(m,ndmin=2)\n if X.shape[0] == 1:\n rowvar = 1\n if rowvar:\n axis = 0\n tup = (newaxis, slice(None))\n else:\n axis = 1\n tup = (slice(None),newaxis)\n \n if y is not None:\n y = asarray(y,ndmin=2)\n X = concatenate((X,y),axis)\n\n X -= X.mean(axis=axis)[tup]\n if rowvar:\n N = X.shape[1]\n else:\n N = X.shape[0]\n\n if bias:\n fact = N*1.0\n else:\n fact = N-1.0\n\n if not rowvar:\n return (dot(X.transpose(), X.conj()) / fact).squeeze()\n else:\n return (dot(X,X.transpose().conj())/fact).squeeze()\n \ndef corrcoef(x, y=None):\n \"\"\"The correlation coefficients\n \"\"\"\n c = cov(x, y)\n d = diag(c)\n return c/sqrt(multiply.outer(d,d))\n\ndef blackman(M):\n \"\"\"blackman(M) returns the M-point Blackman window.\n \"\"\"\n n = arange(0,M)\n return 0.42-0.5*cos(2.0*pi*n/(M-1)) + 0.08*cos(4.0*pi*n/(M-1))\n\ndef bartlett(M):\n \"\"\"bartlett(M) returns the M-point Bartlett window.\n \"\"\"\n n = arange(0,M)\n return where(less_equal(n,(M-1)/2.0),2.0*n/(M-1),2.0-2.0*n/(M-1))\n\ndef hanning(M):\n \"\"\"hanning(M) returns the M-point Hanning window.\n \"\"\"\n n = arange(0,M)\n return 0.5-0.5*cos(2.0*pi*n/(M-1))\n\ndef hamming(M):\n \"\"\"hamming(M) returns the M-point Hamming window.\n \"\"\"\n n = arange(0,M)\n return 0.54-0.46*cos(2.0*pi*n/(M-1))\n\n## Code from cephes for i0\n\n_i0A = [\n-4.41534164647933937950E-18,\n 3.33079451882223809783E-17,\n-2.43127984654795469359E-16,\n 1.71539128555513303061E-15,\n-1.16853328779934516808E-14,\n 7.67618549860493561688E-14,\n-4.85644678311192946090E-13,\n 2.95505266312963983461E-12,\n-1.72682629144155570723E-11,\n 9.67580903537323691224E-11,\n-5.18979560163526290666E-10,\n 2.65982372468238665035E-9,\n-1.30002500998624804212E-8,\n 6.04699502254191894932E-8,\n-2.67079385394061173391E-7,\n 1.11738753912010371815E-6,\n-4.41673835845875056359E-6,\n 1.64484480707288970893E-5,\n-5.75419501008210370398E-5,\n 1.88502885095841655729E-4,\n-5.76375574538582365885E-4,\n 1.63947561694133579842E-3,\n-4.32430999505057594430E-3,\n 1.05464603945949983183E-2,\n-2.37374148058994688156E-2,\n 4.93052842396707084878E-2,\n-9.49010970480476444210E-2,\n 1.71620901522208775349E-1,\n-3.04682672343198398683E-1,\n 6.76795274409476084995E-1]\n\n_i0B = [\n-7.23318048787475395456E-18,\n-4.83050448594418207126E-18,\n 4.46562142029675999901E-17,\n 3.46122286769746109310E-17,\n-2.82762398051658348494E-16,\n-3.42548561967721913462E-16,\n 1.77256013305652638360E-15,\n 3.81168066935262242075E-15,\n-9.55484669882830764870E-15,\n-4.15056934728722208663E-14,\n 1.54008621752140982691E-14,\n 3.85277838274214270114E-13,\n 7.18012445138366623367E-13,\n-1.79417853150680611778E-12,\n-1.32158118404477131188E-11,\n-3.14991652796324136454E-11,\n 1.18891471078464383424E-11,\n 4.94060238822496958910E-10,\n 3.39623202570838634515E-9,\n 2.26666899049817806459E-8,\n 2.04891858946906374183E-7,\n 2.89137052083475648297E-6,\n 6.88975834691682398426E-5,\n 3.36911647825569408990E-3,\n 8.04490411014108831608E-1]\n\ndef _chbevl(x, vals):\n b0 = vals[0]\n b1 = 0.0\n\n for i in xrange(1,len(vals)):\n b2 = b1\n b1 = b0\n b0 = x*b1 - b2 + vals[i]\n\n return 0.5*(b0 - b2)\n\ndef _i0_1(x):\n return exp(x) * _chbevl(x/2.0-2, _i0A)\n\ndef _i0_2(x):\n return exp(x) * _chbevl(32.0/x - 2.0, _i0B) / sqrt(x)\n\ndef i0(x):\n x = atleast_1d(x).copy()\n y = empty_like(x)\n ind = (x<0)\n x[ind] = -x[ind]\n ind = (x<=8.0)\n y[ind] = _i0_1(x[ind])\n ind2 = ~ind\n y[ind2] = _i0_2(x[ind2])\n return y.squeeze()\n\n## End of cephes code for i0\n\ndef kaiser(M,beta):\n \"\"\"kaiser(M, beta) returns a Kaiser window of length M with shape parameter\n beta. It depends on numpy.special (in full numpy) for the modified bessel\n function i0.\n \"\"\"\n from numpy.dual import i0\n n = arange(0,M)\n alpha = (M-1)/2.0\n return i0(beta * sqrt(1-((n-alpha)/alpha)**2.0))/i0(beta)\n\ndef sinc(x):\n \"\"\"sinc(x) returns sin(pi*x)/(pi*x) at all points of array x.\n \"\"\"\n y = pi* where(x == 0, 1.0e-20, x)\n return sin(y)/y\n\ndef msort(a):\n b = array(a,copy=True)\n b.sort(0)\n return b\n\ndef median(m):\n \"\"\"median(m) returns a median of m along the first dimension of m.\n \"\"\"\n sorted = msort(m)\n if sorted.shape[0] % 2 == 1:\n return sorted[int(sorted.shape[0]/2)]\n else:\n sorted = msort(m)\n index=sorted.shape[0]/2\n return (sorted[index-1]+sorted[index])/2.0\n\ndef trapz(y, x=None, dx=1.0, axis=-1):\n \"\"\"Integrate y(x) using samples along the given axis and the composite\n trapezoidal rule. If x is None, spacing given by dx is assumed.\n \"\"\"\n y = asarray(y)\n if x is None:\n d = dx\n else:\n d = diff(x,axis=axis)\n nd = len(y.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n return add.reduce(d * (y[slice1]+y[slice2])/2.0,axis)\n\n#always succeed\ndef add_newdoc(place, obj, doc):\n try:\n new = {}\n exec 'from %s import %s' % (place, obj) in new\n if isinstance(doc, str):\n add_docstring(new[obj], doc.strip())\n elif isinstance(doc, tuple):\n add_docstring(getattr(new[obj], doc[0]), doc[1].strip())\n elif isinstance(doc, list):\n for val in doc:\n add_docstring(getattr(new[obj], val[0]), val[1].strip())\n except:\n pass\n", + "source_code_before": "\n__all__ = ['logspace', 'linspace',\n 'select', 'piecewise', 'trim_zeros',\n 'copy', 'iterable', #'base_repr', 'binary_repr',\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', 'cov', 'corrcoef', 'msort',\n 'median', 'sinc', 'hamming', 'hanning', 'bartlett', 'blackman',\n 'kaiser', 'trapz', 'i0', 'add_newdoc', 'add_docstring',\n ]\n\nimport types\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import ones, zeros, arange, concatenate, array, \\\n asarray, empty, empty_like, asanyarray\nfrom numpy.core.numeric import ScalarType, dot, where, newaxis\nfrom numpy.core.umath import pi, multiply, add, arctan2, \\\n frompyfunc, isnan, cos, less_equal, sqrt, sin, mod, exp\nfrom numpy.core.oldnumeric import ravel, nonzero, choose, \\\n typecodes, ArrayType, squeeze,\\\n sort\nfrom type_check import ScalarType\nfrom shape_base import atleast_1d\nfrom twodim_base import diag\nfrom _compiled_base import digitize, bincount, _insert, add_docstring\n\n#end Fernando's utilities\n\n\ndef linspace(start, stop, num=50, endpoint=True, retstep=False):\n \"\"\"Return evenly spaced numbers.\n\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 num = int(num)\n if num <= 0:\n return array([])\n if endpoint:\n if num == 1:\n return array([start])\n step = (stop-start)/float((num-1))\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 logspace(start,stop,num=50,endpoint=True,base=10.0):\n \"\"\"Evenly spaced numbers on a logarithmic scale.\n\n Computes int(num) evenly spaced exponents from start to stop.\n If endpoint=True, then last exponent is stop.\n Returns base**exponents.\n \"\"\"\n y = linspace(start,stop,num=num,endpoint=endpoint)\n return _nx.power(base,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 = [mi+0.0 for mi in range]\n if mn == mx:\n mn -= 0.5\n mx += 0.5\n bins = linspace(mn, mx, bins, endpoint=False)\n\n n = sort(a).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(n.shape) * 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\ndef asarray_chkfinite(a):\n \"\"\"Like asarray, but check that no NaNs or Infs are present.\n \"\"\"\n a = asarray(a)\n if (a.dtype.char 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\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 A constant may be used in funclist for a function that returns a\n constant (e.g. val and lambda x: val are equivalent in a funclist).\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 x = asanyarray(x)\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[k]\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\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.dtype.char\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.dtype.char)\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.type, _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 numpy\n >>> a = array((0, 0, 0, 1, 2, 3, 2, 1, 0))\n >>> numpy.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 _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.type, _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.type, _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.type, _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.type, _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.type, _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(object):\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 numpy arrays as inputs and returns a\n numpy 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 numpy.\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 = fcode.co_argcount\n if pyfunc.func_defaults:\n self.nin_wo_defaults = self.nin - len(pyfunc.func_defaults)\n else:\n self.nin_wo_defaults = self.nin\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 self.lastcallargs = 0\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 nargs = len(args)\n if (nargs > self.nin) or (nargs < self.nin_wo_defaults):\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]).dtype.char)\n self.otypes = ''.join(otypes)\n\n if (self.ufunc is None) or (self.lastcallargs != nargs):\n self.ufunc = frompyfunc(self.thefunc, nargs, self.nout)\n self.lastcallargs = nargs\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\ndef cov(m,y=None, rowvar=0, bias=0):\n \"\"\"Estimate the covariance matrix.\n\n If m is a vector, return the variance. For matrices where each row\n is an observation, and each column a variable, return the covariance\n matrix. Note that in this case diag(cov(m)) is a vector of\n variances for each column.\n\n cov(m) is the same as cov(m, m)\n\n Normalization is by (N-1) where N is the number of observations\n (unbiased estimate). If bias is 1 then normalization is by N.\n\n If rowvar is zero, then each row is a variable with\n observations in the columns.\n \"\"\"\n if y is None:\n y = asarray(m)\n else:\n y = asarray(y)\n m = asarray(m)\n if rowvar:\n m = m.transpose()\n y = y.transpose()\n if (m.shape[0] == 1):\n m = m.transpose()\n if (y.shape[0] == 1):\n y = y.transpose()\n N = m.shape[0]\n if (y.shape[0] != N):\n raise ValueError, \"x and y must have the same number of observations.\"\n m = m - m.mean(axis=0)\n y = y - y.mean(axis=0)\n if bias:\n fact = N*1.0\n else:\n fact = N-1.0\n\n val = squeeze(dot(m.transpose(),y.conj()) / fact)\n return val\n\ndef corrcoef(x, y=None):\n \"\"\"The correlation coefficients\n \"\"\"\n c = cov(x, y)\n d = diag(c)\n return c/sqrt(multiply.outer(d,d))\n\ndef blackman(M):\n \"\"\"blackman(M) returns the M-point Blackman window.\n \"\"\"\n n = arange(0,M)\n return 0.42-0.5*cos(2.0*pi*n/(M-1)) + 0.08*cos(4.0*pi*n/(M-1))\n\ndef bartlett(M):\n \"\"\"bartlett(M) returns the M-point Bartlett window.\n \"\"\"\n n = arange(0,M)\n return where(less_equal(n,(M-1)/2.0),2.0*n/(M-1),2.0-2.0*n/(M-1))\n\ndef hanning(M):\n \"\"\"hanning(M) returns the M-point Hanning window.\n \"\"\"\n n = arange(0,M)\n return 0.5-0.5*cos(2.0*pi*n/(M-1))\n\ndef hamming(M):\n \"\"\"hamming(M) returns the M-point Hamming window.\n \"\"\"\n n = arange(0,M)\n return 0.54-0.46*cos(2.0*pi*n/(M-1))\n\n## Code from cephes for i0\n\n_i0A = [\n-4.41534164647933937950E-18,\n 3.33079451882223809783E-17,\n-2.43127984654795469359E-16,\n 1.71539128555513303061E-15,\n-1.16853328779934516808E-14,\n 7.67618549860493561688E-14,\n-4.85644678311192946090E-13,\n 2.95505266312963983461E-12,\n-1.72682629144155570723E-11,\n 9.67580903537323691224E-11,\n-5.18979560163526290666E-10,\n 2.65982372468238665035E-9,\n-1.30002500998624804212E-8,\n 6.04699502254191894932E-8,\n-2.67079385394061173391E-7,\n 1.11738753912010371815E-6,\n-4.41673835845875056359E-6,\n 1.64484480707288970893E-5,\n-5.75419501008210370398E-5,\n 1.88502885095841655729E-4,\n-5.76375574538582365885E-4,\n 1.63947561694133579842E-3,\n-4.32430999505057594430E-3,\n 1.05464603945949983183E-2,\n-2.37374148058994688156E-2,\n 4.93052842396707084878E-2,\n-9.49010970480476444210E-2,\n 1.71620901522208775349E-1,\n-3.04682672343198398683E-1,\n 6.76795274409476084995E-1]\n\n_i0B = [\n-7.23318048787475395456E-18,\n-4.83050448594418207126E-18,\n 4.46562142029675999901E-17,\n 3.46122286769746109310E-17,\n-2.82762398051658348494E-16,\n-3.42548561967721913462E-16,\n 1.77256013305652638360E-15,\n 3.81168066935262242075E-15,\n-9.55484669882830764870E-15,\n-4.15056934728722208663E-14,\n 1.54008621752140982691E-14,\n 3.85277838274214270114E-13,\n 7.18012445138366623367E-13,\n-1.79417853150680611778E-12,\n-1.32158118404477131188E-11,\n-3.14991652796324136454E-11,\n 1.18891471078464383424E-11,\n 4.94060238822496958910E-10,\n 3.39623202570838634515E-9,\n 2.26666899049817806459E-8,\n 2.04891858946906374183E-7,\n 2.89137052083475648297E-6,\n 6.88975834691682398426E-5,\n 3.36911647825569408990E-3,\n 8.04490411014108831608E-1]\n\ndef _chbevl(x, vals):\n b0 = vals[0]\n b1 = 0.0\n\n for i in xrange(1,len(vals)):\n b2 = b1\n b1 = b0\n b0 = x*b1 - b2 + vals[i]\n\n return 0.5*(b0 - b2)\n\ndef _i0_1(x):\n return exp(x) * _chbevl(x/2.0-2, _i0A)\n\ndef _i0_2(x):\n return exp(x) * _chbevl(32.0/x - 2.0, _i0B) / sqrt(x)\n\ndef i0(x):\n x = atleast_1d(x).copy()\n y = empty_like(x)\n ind = (x<0)\n x[ind] = -x[ind]\n ind = (x<=8.0)\n y[ind] = _i0_1(x[ind])\n ind2 = ~ind\n y[ind2] = _i0_2(x[ind2])\n return y.squeeze()\n\n## End of cephes code for i0\n\ndef kaiser(M,beta):\n \"\"\"kaiser(M, beta) returns a Kaiser window of length M with shape parameter\n beta. It depends on numpy.special (in full numpy) for the modified bessel\n function i0.\n \"\"\"\n from numpy.dual import i0\n n = arange(0,M)\n alpha = (M-1)/2.0\n return i0(beta * sqrt(1-((n-alpha)/alpha)**2.0))/i0(beta)\n\ndef sinc(x):\n \"\"\"sinc(x) returns sin(pi*x)/(pi*x) at all points of array x.\n \"\"\"\n y = pi* where(x == 0, 1.0e-20, x)\n return sin(y)/y\n\ndef msort(a):\n b = array(a,copy=True)\n b.sort(0)\n return b\n\ndef median(m):\n \"\"\"median(m) returns a median of m along the first dimension of m.\n \"\"\"\n sorted = msort(m)\n if sorted.shape[0] % 2 == 1:\n return sorted[int(sorted.shape[0]/2)]\n else:\n sorted = msort(m)\n index=sorted.shape[0]/2\n return (sorted[index-1]+sorted[index])/2.0\n\ndef trapz(y, x=None, dx=1.0, axis=-1):\n \"\"\"Integrate y(x) using samples along the given axis and the composite\n trapezoidal rule. If x is None, spacing given by dx is assumed.\n \"\"\"\n y = asarray(y)\n if x is None:\n d = dx\n else:\n d = diff(x,axis=axis)\n nd = len(y.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n return add.reduce(d * (y[slice1]+y[slice2])/2.0,axis)\n\n#always succeed\ndef add_newdoc(place, obj, doc):\n try:\n new = {}\n exec 'from %s import %s' % (place, obj) in new\n if isinstance(doc, str):\n add_docstring(new[obj], doc.strip())\n elif isinstance(doc, tuple):\n add_docstring(getattr(new[obj], doc[0]), doc[1].strip())\n elif isinstance(doc, list):\n for val in doc:\n add_docstring(getattr(new[obj], val[0]), val[1].strip())\n except:\n pass\n", + "methods": [ + { + "name": "linspace", + "long_name": "linspace( start , stop , num = 50 , endpoint = True , retstep = False )", + "filename": "function_base.py", + "nloc": 15, + "complexity": 5, + "token_count": 107, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "retstep" + ], + "start_line": 31, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "logspace", + "long_name": "logspace( start , stop , num = 50 , endpoint = True , base = 10 . 0 )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 47, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "base" + ], + "start_line": 53, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 63, + "end_line": 66, + "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": 174, + "parameters": [ + "a", + "bins", + "range", + "normed" + ], + "start_line": 68, + "end_line": 87, + "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": 334, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 89, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 0 + }, + { + "name": "asarray_chkfinite", + "long_name": "asarray_chkfinite( a )", + "filename": "function_base.py", + "nloc": 6, + "complexity": 4, + "token_count": 59, + "parameters": [ + "a" + ], + "start_line": 161, + "end_line": 168, + "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": 22, + "complexity": 7, + "token_count": 172, + "parameters": [ + "x", + "condlist", + "funclist", + "args", + "kw" + ], + "start_line": 170, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "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": 226, + "end_line": 272, + "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": 274, + "end_line": 280, + "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": 282, + "end_line": 285, + "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": 329, + "parameters": [ + "f", + "varargs" + ], + "start_line": 289, + "end_line": 361, + "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": 364, + "end_line": 382, + "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": 74, + "parameters": [ + "z", + "deg" + ], + "start_line": 384, + "end_line": 398, + "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": 400, + "end_line": 415, + "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": 12, + "complexity": 4, + "token_count": 81, + "parameters": [ + "a" + ], + "start_line": 417, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 435, + "end_line": 455, + "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": 457, + "end_line": 464, + "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": 466, + "end_line": 472, + "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": 19, + "parameters": [ + "arr", + "mask", + "vals" + ], + "start_line": 474, + "end_line": 479, + "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": 48, + "parameters": [ + "a", + "axis" + ], + "start_line": 481, + "end_line": 487, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 489, + "end_line": 495, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 497, + "end_line": 503, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 505, + "end_line": 511, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 513, + "end_line": 519, + "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": 521, + "end_line": 533, + "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": 25, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self", + "pyfunc", + "otypes", + "doc" + ], + "start_line": 566, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "function_base.py", + "nloc": 27, + "complexity": 13, + "token_count": 256, + "parameters": [ + "self", + "args" + ], + "start_line": 593, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "cov", + "long_name": "cov( m , y = None , rowvar = 1 , bias = 0 )", + "filename": "function_base.py", + "nloc": 26, + "complexity": 7, + "token_count": 205, + "parameters": [ + "m", + "y", + "rowvar", + "bias" + ], + "start_line": 625, + "end_line": 670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "corrcoef", + "long_name": "corrcoef( x , y = None )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 38, + "parameters": [ + "x", + "y" + ], + "start_line": 672, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "blackman", + "long_name": "blackman( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 679, + "end_line": 683, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "bartlett", + "long_name": "bartlett( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 685, + "end_line": 689, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hanning", + "long_name": "hanning( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 691, + "end_line": 695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hamming", + "long_name": "hamming( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 697, + "end_line": 701, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_chbevl", + "long_name": "_chbevl( x , vals )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 59, + "parameters": [ + "x", + "vals" + ], + "start_line": 764, + "end_line": 773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_i0_1", + "long_name": "_i0_1( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 23, + "parameters": [ + "x" + ], + "start_line": 775, + "end_line": 776, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_i0_2", + "long_name": "_i0_2( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 30, + "parameters": [ + "x" + ], + "start_line": 778, + "end_line": 779, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "i0", + "long_name": "i0( x )", + "filename": "function_base.py", + "nloc": 10, + "complexity": 1, + "token_count": 81, + "parameters": [ + "x" + ], + "start_line": 781, + "end_line": 790, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "kaiser", + "long_name": "kaiser( M , beta )", + "filename": "function_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 62, + "parameters": [ + "M", + "beta" + ], + "start_line": 794, + "end_line": 802, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "sinc", + "long_name": "sinc( x )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "x" + ], + "start_line": 804, + "end_line": 808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "msort", + "long_name": "msort( a )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a" + ], + "start_line": 810, + "end_line": 813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "median", + "long_name": "median( m )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 75, + "parameters": [ + "m" + ], + "start_line": 815, + "end_line": 824, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "trapz", + "long_name": "trapz( y , x = None , dx = 1 . 0 , axis = - 1 )", + "filename": "function_base.py", + "nloc": 12, + "complexity": 2, + "token_count": 123, + "parameters": [ + "y", + "x", + "dx", + "axis" + ], + "start_line": 826, + "end_line": 840, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "add_newdoc", + "long_name": "add_newdoc( place , obj , doc )", + "filename": "function_base.py", + "nloc": 13, + "complexity": 6, + "token_count": 118, + "parameters": [ + "place", + "obj", + "doc" + ], + "start_line": 843, + "end_line": 855, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "linspace", + "long_name": "linspace( start , stop , num = 50 , endpoint = True , retstep = False )", + "filename": "function_base.py", + "nloc": 15, + "complexity": 5, + "token_count": 107, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "retstep" + ], + "start_line": 31, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "logspace", + "long_name": "logspace( start , stop , num = 50 , endpoint = True , base = 10 . 0 )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 47, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "base" + ], + "start_line": 53, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 63, + "end_line": 66, + "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": 174, + "parameters": [ + "a", + "bins", + "range", + "normed" + ], + "start_line": 68, + "end_line": 87, + "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": 334, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 89, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 0 + }, + { + "name": "asarray_chkfinite", + "long_name": "asarray_chkfinite( a )", + "filename": "function_base.py", + "nloc": 6, + "complexity": 4, + "token_count": 59, + "parameters": [ + "a" + ], + "start_line": 161, + "end_line": 168, + "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": 22, + "complexity": 7, + "token_count": 172, + "parameters": [ + "x", + "condlist", + "funclist", + "args", + "kw" + ], + "start_line": 170, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "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": 226, + "end_line": 272, + "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": 274, + "end_line": 280, + "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": 282, + "end_line": 285, + "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": 329, + "parameters": [ + "f", + "varargs" + ], + "start_line": 289, + "end_line": 361, + "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": 364, + "end_line": 382, + "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": 74, + "parameters": [ + "z", + "deg" + ], + "start_line": 384, + "end_line": 398, + "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": 400, + "end_line": 415, + "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": 12, + "complexity": 4, + "token_count": 81, + "parameters": [ + "a" + ], + "start_line": 417, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 435, + "end_line": 455, + "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": 457, + "end_line": 464, + "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": 466, + "end_line": 472, + "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": 19, + "parameters": [ + "arr", + "mask", + "vals" + ], + "start_line": 474, + "end_line": 479, + "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": 48, + "parameters": [ + "a", + "axis" + ], + "start_line": 481, + "end_line": 487, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 489, + "end_line": 495, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 497, + "end_line": 503, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 505, + "end_line": 511, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 513, + "end_line": 519, + "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": 521, + "end_line": 533, + "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": 25, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self", + "pyfunc", + "otypes", + "doc" + ], + "start_line": 566, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "function_base.py", + "nloc": 27, + "complexity": 13, + "token_count": 256, + "parameters": [ + "self", + "args" + ], + "start_line": 593, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "cov", + "long_name": "cov( m , y = None , rowvar = 0 , bias = 0 )", + "filename": "function_base.py", + "nloc": 24, + "complexity": 7, + "token_count": 188, + "parameters": [ + "m", + "y", + "rowvar", + "bias" + ], + "start_line": 625, + "end_line": 664, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "corrcoef", + "long_name": "corrcoef( x , y = None )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 38, + "parameters": [ + "x", + "y" + ], + "start_line": 666, + "end_line": 671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "blackman", + "long_name": "blackman( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 673, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "bartlett", + "long_name": "bartlett( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 679, + "end_line": 683, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hanning", + "long_name": "hanning( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 685, + "end_line": 689, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hamming", + "long_name": "hamming( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 691, + "end_line": 695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_chbevl", + "long_name": "_chbevl( x , vals )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 59, + "parameters": [ + "x", + "vals" + ], + "start_line": 758, + "end_line": 767, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_i0_1", + "long_name": "_i0_1( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 23, + "parameters": [ + "x" + ], + "start_line": 769, + "end_line": 770, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_i0_2", + "long_name": "_i0_2( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 30, + "parameters": [ + "x" + ], + "start_line": 772, + "end_line": 773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "i0", + "long_name": "i0( x )", + "filename": "function_base.py", + "nloc": 10, + "complexity": 1, + "token_count": 81, + "parameters": [ + "x" + ], + "start_line": 775, + "end_line": 784, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "kaiser", + "long_name": "kaiser( M , beta )", + "filename": "function_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 62, + "parameters": [ + "M", + "beta" + ], + "start_line": 788, + "end_line": 796, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "sinc", + "long_name": "sinc( x )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "x" + ], + "start_line": 798, + "end_line": 802, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "msort", + "long_name": "msort( a )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a" + ], + "start_line": 804, + "end_line": 807, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "median", + "long_name": "median( m )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 75, + "parameters": [ + "m" + ], + "start_line": 809, + "end_line": 818, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "trapz", + "long_name": "trapz( y , x = None , dx = 1 . 0 , axis = - 1 )", + "filename": "function_base.py", + "nloc": 12, + "complexity": 2, + "token_count": 123, + "parameters": [ + "y", + "x", + "dx", + "axis" + ], + "start_line": 820, + "end_line": 834, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "add_newdoc", + "long_name": "add_newdoc( place , obj , doc )", + "filename": "function_base.py", + "nloc": 13, + "complexity": 6, + "token_count": 118, + "parameters": [ + "place", + "obj", + "doc" + ], + "start_line": 837, + "end_line": 849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "cov", + "long_name": "cov( m , y = None , rowvar = 1 , bias = 0 )", + "filename": "function_base.py", + "nloc": 26, + "complexity": 7, + "token_count": 205, + "parameters": [ + "m", + "y", + "rowvar", + "bias" + ], + "start_line": 625, + "end_line": 670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "cov", + "long_name": "cov( m , y = None , rowvar = 0 , bias = 0 )", + "filename": "function_base.py", + "nloc": 24, + "complexity": 7, + "token_count": 188, + "parameters": [ + "m", + "y", + "rowvar", + "bias" + ], + "start_line": 625, + "end_line": 664, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + } + ], + "nloc": 563, + "complexity": 140, + "token_count": 4449, + "diff_parsed": { + "added": [ + "def cov(m,y=None, rowvar=1, bias=0):", + " If m is a vector, return the variance. For matrices return the", + " covariance matrix.", + " If y is given it is treated as an additional (set of)", + " variable(s).", + " If rowvar is non-zero (default), then each row is a variable with", + " observations in the columns, otherwise each column", + " is a variable and the observations are in the rows.", + "", + " X = asarray(m,ndmin=2)", + " if X.shape[0] == 1:", + " rowvar = 1", + " if rowvar:", + " axis = 0", + " tup = (newaxis, slice(None))", + " axis = 1", + " tup = (slice(None),newaxis)", + "", + " if y is not None:", + " y = asarray(y,ndmin=2)", + " X = concatenate((X,y),axis)", + "", + " X -= X.mean(axis=axis)[tup]", + " N = X.shape[1]", + " else:", + " N = X.shape[0]", + "", + " if not rowvar:", + " return (dot(X.transpose(), X.conj()) / fact).squeeze()", + " else:", + " return (dot(X,X.transpose().conj())/fact).squeeze()", + "" + ], + "deleted": [ + "def cov(m,y=None, rowvar=0, bias=0):", + " If m is a vector, return the variance. For matrices where each row", + " is an observation, and each column a variable, return the covariance", + " matrix. Note that in this case diag(cov(m)) is a vector of", + " variances for each column.", + " cov(m) is the same as cov(m, m)", + " If rowvar is zero, then each row is a variable with", + " observations in the columns.", + " if y is None:", + " y = asarray(m)", + " y = asarray(y)", + " m = asarray(m)", + " m = m.transpose()", + " y = y.transpose()", + " if (m.shape[0] == 1):", + " m = m.transpose()", + " if (y.shape[0] == 1):", + " y = y.transpose()", + " N = m.shape[0]", + " if (y.shape[0] != N):", + " raise ValueError, \"x and y must have the same number of observations.\"", + " m = m - m.mean(axis=0)", + " y = y - y.mean(axis=0)", + " val = squeeze(dot(m.transpose(),y.conj()) / fact)", + " return val", + "" + ] + } + } + ] + }, + { + "hash": "0818507117b55a7f0e95dfc3cbe9f6ed1354aad9", + "msg": "Fix cov and corrcoef in numpy", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-16T17:39:24+00:00", + "author_timezone": 0, + "committer_date": "2006-03-16T17:39:24+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "959f36c04ce8ca0b7bc44bb6438bddf162ad2db9" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 1, + "insertions": 1, + "lines": 2, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/lib/function_base.py", + "new_path": "numpy/lib/function_base.py", + "filename": "function_base.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -653,7 +653,7 @@ def cov(m,y=None, rowvar=1, bias=0):\n y = asarray(y,ndmin=2)\n X = concatenate((X,y),axis)\n \n- X -= X.mean(axis=axis)[tup]\n+ X -= X.mean(axis=1-axis)[tup]\n if rowvar:\n N = X.shape[1]\n else:\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "\n__all__ = ['logspace', 'linspace',\n 'select', 'piecewise', 'trim_zeros',\n 'copy', 'iterable', #'base_repr', 'binary_repr',\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', 'cov', 'corrcoef', 'msort',\n 'median', 'sinc', 'hamming', 'hanning', 'bartlett', 'blackman',\n 'kaiser', 'trapz', 'i0', 'add_newdoc', 'add_docstring',\n ]\n\nimport types\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import ones, zeros, arange, concatenate, array, \\\n asarray, empty, empty_like, asanyarray\nfrom numpy.core.numeric import ScalarType, dot, where, newaxis\nfrom numpy.core.umath import pi, multiply, add, arctan2, \\\n frompyfunc, isnan, cos, less_equal, sqrt, sin, mod, exp\nfrom numpy.core.oldnumeric import ravel, nonzero, choose, \\\n typecodes, ArrayType, squeeze,\\\n sort\nfrom type_check import ScalarType\nfrom shape_base import atleast_1d\nfrom twodim_base import diag\nfrom _compiled_base import digitize, bincount, _insert, add_docstring\n\n#end Fernando's utilities\n\n\ndef linspace(start, stop, num=50, endpoint=True, retstep=False):\n \"\"\"Return evenly spaced numbers.\n\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 num = int(num)\n if num <= 0:\n return array([])\n if endpoint:\n if num == 1:\n return array([start])\n step = (stop-start)/float((num-1))\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 logspace(start,stop,num=50,endpoint=True,base=10.0):\n \"\"\"Evenly spaced numbers on a logarithmic scale.\n\n Computes int(num) evenly spaced exponents from start to stop.\n If endpoint=True, then last exponent is stop.\n Returns base**exponents.\n \"\"\"\n y = linspace(start,stop,num=num,endpoint=endpoint)\n return _nx.power(base,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 = [mi+0.0 for mi in range]\n if mn == mx:\n mn -= 0.5\n mx += 0.5\n bins = linspace(mn, mx, bins, endpoint=False)\n\n n = sort(a).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(n.shape) * 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\ndef asarray_chkfinite(a):\n \"\"\"Like asarray, but check that no NaNs or Infs are present.\n \"\"\"\n a = asarray(a)\n if (a.dtype.char 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\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 A constant may be used in funclist for a function that returns a\n constant (e.g. val and lambda x: val are equivalent in a funclist).\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 x = asanyarray(x)\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[k]\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\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.dtype.char\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.dtype.char)\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.type, _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 numpy\n >>> a = array((0, 0, 0, 1, 2, 3, 2, 1, 0))\n >>> numpy.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 _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.type, _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.type, _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.type, _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.type, _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.type, _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(object):\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 numpy arrays as inputs and returns a\n numpy 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 numpy.\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 = fcode.co_argcount\n if pyfunc.func_defaults:\n self.nin_wo_defaults = self.nin - len(pyfunc.func_defaults)\n else:\n self.nin_wo_defaults = self.nin\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 self.lastcallargs = 0\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 nargs = len(args)\n if (nargs > self.nin) or (nargs < self.nin_wo_defaults):\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]).dtype.char)\n self.otypes = ''.join(otypes)\n\n if (self.ufunc is None) or (self.lastcallargs != nargs):\n self.ufunc = frompyfunc(self.thefunc, nargs, self.nout)\n self.lastcallargs = nargs\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\ndef cov(m,y=None, rowvar=1, bias=0):\n \"\"\"Estimate the covariance matrix.\n\n If m is a vector, return the variance. For matrices return the\n covariance matrix.\n\n If y is given it is treated as an additional (set of)\n variable(s). \n\n Normalization is by (N-1) where N is the number of observations\n (unbiased estimate). If bias is 1 then normalization is by N.\n\n If rowvar is non-zero (default), then each row is a variable with\n observations in the columns, otherwise each column\n is a variable and the observations are in the rows.\n \"\"\"\n\n X = asarray(m,ndmin=2)\n if X.shape[0] == 1:\n rowvar = 1\n if rowvar:\n axis = 0\n tup = (newaxis, slice(None))\n else:\n axis = 1\n tup = (slice(None),newaxis)\n \n if y is not None:\n y = asarray(y,ndmin=2)\n X = concatenate((X,y),axis)\n\n X -= X.mean(axis=1-axis)[tup]\n if rowvar:\n N = X.shape[1]\n else:\n N = X.shape[0]\n\n if bias:\n fact = N*1.0\n else:\n fact = N-1.0\n\n if not rowvar:\n return (dot(X.transpose(), X.conj()) / fact).squeeze()\n else:\n return (dot(X,X.transpose().conj())/fact).squeeze()\n \ndef corrcoef(x, y=None):\n \"\"\"The correlation coefficients\n \"\"\"\n c = cov(x, y)\n d = diag(c)\n return c/sqrt(multiply.outer(d,d))\n\ndef blackman(M):\n \"\"\"blackman(M) returns the M-point Blackman window.\n \"\"\"\n n = arange(0,M)\n return 0.42-0.5*cos(2.0*pi*n/(M-1)) + 0.08*cos(4.0*pi*n/(M-1))\n\ndef bartlett(M):\n \"\"\"bartlett(M) returns the M-point Bartlett window.\n \"\"\"\n n = arange(0,M)\n return where(less_equal(n,(M-1)/2.0),2.0*n/(M-1),2.0-2.0*n/(M-1))\n\ndef hanning(M):\n \"\"\"hanning(M) returns the M-point Hanning window.\n \"\"\"\n n = arange(0,M)\n return 0.5-0.5*cos(2.0*pi*n/(M-1))\n\ndef hamming(M):\n \"\"\"hamming(M) returns the M-point Hamming window.\n \"\"\"\n n = arange(0,M)\n return 0.54-0.46*cos(2.0*pi*n/(M-1))\n\n## Code from cephes for i0\n\n_i0A = [\n-4.41534164647933937950E-18,\n 3.33079451882223809783E-17,\n-2.43127984654795469359E-16,\n 1.71539128555513303061E-15,\n-1.16853328779934516808E-14,\n 7.67618549860493561688E-14,\n-4.85644678311192946090E-13,\n 2.95505266312963983461E-12,\n-1.72682629144155570723E-11,\n 9.67580903537323691224E-11,\n-5.18979560163526290666E-10,\n 2.65982372468238665035E-9,\n-1.30002500998624804212E-8,\n 6.04699502254191894932E-8,\n-2.67079385394061173391E-7,\n 1.11738753912010371815E-6,\n-4.41673835845875056359E-6,\n 1.64484480707288970893E-5,\n-5.75419501008210370398E-5,\n 1.88502885095841655729E-4,\n-5.76375574538582365885E-4,\n 1.63947561694133579842E-3,\n-4.32430999505057594430E-3,\n 1.05464603945949983183E-2,\n-2.37374148058994688156E-2,\n 4.93052842396707084878E-2,\n-9.49010970480476444210E-2,\n 1.71620901522208775349E-1,\n-3.04682672343198398683E-1,\n 6.76795274409476084995E-1]\n\n_i0B = [\n-7.23318048787475395456E-18,\n-4.83050448594418207126E-18,\n 4.46562142029675999901E-17,\n 3.46122286769746109310E-17,\n-2.82762398051658348494E-16,\n-3.42548561967721913462E-16,\n 1.77256013305652638360E-15,\n 3.81168066935262242075E-15,\n-9.55484669882830764870E-15,\n-4.15056934728722208663E-14,\n 1.54008621752140982691E-14,\n 3.85277838274214270114E-13,\n 7.18012445138366623367E-13,\n-1.79417853150680611778E-12,\n-1.32158118404477131188E-11,\n-3.14991652796324136454E-11,\n 1.18891471078464383424E-11,\n 4.94060238822496958910E-10,\n 3.39623202570838634515E-9,\n 2.26666899049817806459E-8,\n 2.04891858946906374183E-7,\n 2.89137052083475648297E-6,\n 6.88975834691682398426E-5,\n 3.36911647825569408990E-3,\n 8.04490411014108831608E-1]\n\ndef _chbevl(x, vals):\n b0 = vals[0]\n b1 = 0.0\n\n for i in xrange(1,len(vals)):\n b2 = b1\n b1 = b0\n b0 = x*b1 - b2 + vals[i]\n\n return 0.5*(b0 - b2)\n\ndef _i0_1(x):\n return exp(x) * _chbevl(x/2.0-2, _i0A)\n\ndef _i0_2(x):\n return exp(x) * _chbevl(32.0/x - 2.0, _i0B) / sqrt(x)\n\ndef i0(x):\n x = atleast_1d(x).copy()\n y = empty_like(x)\n ind = (x<0)\n x[ind] = -x[ind]\n ind = (x<=8.0)\n y[ind] = _i0_1(x[ind])\n ind2 = ~ind\n y[ind2] = _i0_2(x[ind2])\n return y.squeeze()\n\n## End of cephes code for i0\n\ndef kaiser(M,beta):\n \"\"\"kaiser(M, beta) returns a Kaiser window of length M with shape parameter\n beta. It depends on numpy.special (in full numpy) for the modified bessel\n function i0.\n \"\"\"\n from numpy.dual import i0\n n = arange(0,M)\n alpha = (M-1)/2.0\n return i0(beta * sqrt(1-((n-alpha)/alpha)**2.0))/i0(beta)\n\ndef sinc(x):\n \"\"\"sinc(x) returns sin(pi*x)/(pi*x) at all points of array x.\n \"\"\"\n y = pi* where(x == 0, 1.0e-20, x)\n return sin(y)/y\n\ndef msort(a):\n b = array(a,copy=True)\n b.sort(0)\n return b\n\ndef median(m):\n \"\"\"median(m) returns a median of m along the first dimension of m.\n \"\"\"\n sorted = msort(m)\n if sorted.shape[0] % 2 == 1:\n return sorted[int(sorted.shape[0]/2)]\n else:\n sorted = msort(m)\n index=sorted.shape[0]/2\n return (sorted[index-1]+sorted[index])/2.0\n\ndef trapz(y, x=None, dx=1.0, axis=-1):\n \"\"\"Integrate y(x) using samples along the given axis and the composite\n trapezoidal rule. If x is None, spacing given by dx is assumed.\n \"\"\"\n y = asarray(y)\n if x is None:\n d = dx\n else:\n d = diff(x,axis=axis)\n nd = len(y.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n return add.reduce(d * (y[slice1]+y[slice2])/2.0,axis)\n\n#always succeed\ndef add_newdoc(place, obj, doc):\n try:\n new = {}\n exec 'from %s import %s' % (place, obj) in new\n if isinstance(doc, str):\n add_docstring(new[obj], doc.strip())\n elif isinstance(doc, tuple):\n add_docstring(getattr(new[obj], doc[0]), doc[1].strip())\n elif isinstance(doc, list):\n for val in doc:\n add_docstring(getattr(new[obj], val[0]), val[1].strip())\n except:\n pass\n", + "source_code_before": "\n__all__ = ['logspace', 'linspace',\n 'select', 'piecewise', 'trim_zeros',\n 'copy', 'iterable', #'base_repr', 'binary_repr',\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', 'cov', 'corrcoef', 'msort',\n 'median', 'sinc', 'hamming', 'hanning', 'bartlett', 'blackman',\n 'kaiser', 'trapz', 'i0', 'add_newdoc', 'add_docstring',\n ]\n\nimport types\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import ones, zeros, arange, concatenate, array, \\\n asarray, empty, empty_like, asanyarray\nfrom numpy.core.numeric import ScalarType, dot, where, newaxis\nfrom numpy.core.umath import pi, multiply, add, arctan2, \\\n frompyfunc, isnan, cos, less_equal, sqrt, sin, mod, exp\nfrom numpy.core.oldnumeric import ravel, nonzero, choose, \\\n typecodes, ArrayType, squeeze,\\\n sort\nfrom type_check import ScalarType\nfrom shape_base import atleast_1d\nfrom twodim_base import diag\nfrom _compiled_base import digitize, bincount, _insert, add_docstring\n\n#end Fernando's utilities\n\n\ndef linspace(start, stop, num=50, endpoint=True, retstep=False):\n \"\"\"Return evenly spaced numbers.\n\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 num = int(num)\n if num <= 0:\n return array([])\n if endpoint:\n if num == 1:\n return array([start])\n step = (stop-start)/float((num-1))\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 logspace(start,stop,num=50,endpoint=True,base=10.0):\n \"\"\"Evenly spaced numbers on a logarithmic scale.\n\n Computes int(num) evenly spaced exponents from start to stop.\n If endpoint=True, then last exponent is stop.\n Returns base**exponents.\n \"\"\"\n y = linspace(start,stop,num=num,endpoint=endpoint)\n return _nx.power(base,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 = [mi+0.0 for mi in range]\n if mn == mx:\n mn -= 0.5\n mx += 0.5\n bins = linspace(mn, mx, bins, endpoint=False)\n\n n = sort(a).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(n.shape) * 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\ndef asarray_chkfinite(a):\n \"\"\"Like asarray, but check that no NaNs or Infs are present.\n \"\"\"\n a = asarray(a)\n if (a.dtype.char 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\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 A constant may be used in funclist for a function that returns a\n constant (e.g. val and lambda x: val are equivalent in a funclist).\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 x = asanyarray(x)\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[k]\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\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.dtype.char\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.dtype.char)\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.type, _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 numpy\n >>> a = array((0, 0, 0, 1, 2, 3, 2, 1, 0))\n >>> numpy.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 _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.type, _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.type, _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.type, _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.type, _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.type, _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(object):\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 numpy arrays as inputs and returns a\n numpy 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 numpy.\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 = fcode.co_argcount\n if pyfunc.func_defaults:\n self.nin_wo_defaults = self.nin - len(pyfunc.func_defaults)\n else:\n self.nin_wo_defaults = self.nin\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 self.lastcallargs = 0\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 nargs = len(args)\n if (nargs > self.nin) or (nargs < self.nin_wo_defaults):\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]).dtype.char)\n self.otypes = ''.join(otypes)\n\n if (self.ufunc is None) or (self.lastcallargs != nargs):\n self.ufunc = frompyfunc(self.thefunc, nargs, self.nout)\n self.lastcallargs = nargs\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\ndef cov(m,y=None, rowvar=1, bias=0):\n \"\"\"Estimate the covariance matrix.\n\n If m is a vector, return the variance. For matrices return the\n covariance matrix.\n\n If y is given it is treated as an additional (set of)\n variable(s). \n\n Normalization is by (N-1) where N is the number of observations\n (unbiased estimate). If bias is 1 then normalization is by N.\n\n If rowvar is non-zero (default), then each row is a variable with\n observations in the columns, otherwise each column\n is a variable and the observations are in the rows.\n \"\"\"\n\n X = asarray(m,ndmin=2)\n if X.shape[0] == 1:\n rowvar = 1\n if rowvar:\n axis = 0\n tup = (newaxis, slice(None))\n else:\n axis = 1\n tup = (slice(None),newaxis)\n \n if y is not None:\n y = asarray(y,ndmin=2)\n X = concatenate((X,y),axis)\n\n X -= X.mean(axis=axis)[tup]\n if rowvar:\n N = X.shape[1]\n else:\n N = X.shape[0]\n\n if bias:\n fact = N*1.0\n else:\n fact = N-1.0\n\n if not rowvar:\n return (dot(X.transpose(), X.conj()) / fact).squeeze()\n else:\n return (dot(X,X.transpose().conj())/fact).squeeze()\n \ndef corrcoef(x, y=None):\n \"\"\"The correlation coefficients\n \"\"\"\n c = cov(x, y)\n d = diag(c)\n return c/sqrt(multiply.outer(d,d))\n\ndef blackman(M):\n \"\"\"blackman(M) returns the M-point Blackman window.\n \"\"\"\n n = arange(0,M)\n return 0.42-0.5*cos(2.0*pi*n/(M-1)) + 0.08*cos(4.0*pi*n/(M-1))\n\ndef bartlett(M):\n \"\"\"bartlett(M) returns the M-point Bartlett window.\n \"\"\"\n n = arange(0,M)\n return where(less_equal(n,(M-1)/2.0),2.0*n/(M-1),2.0-2.0*n/(M-1))\n\ndef hanning(M):\n \"\"\"hanning(M) returns the M-point Hanning window.\n \"\"\"\n n = arange(0,M)\n return 0.5-0.5*cos(2.0*pi*n/(M-1))\n\ndef hamming(M):\n \"\"\"hamming(M) returns the M-point Hamming window.\n \"\"\"\n n = arange(0,M)\n return 0.54-0.46*cos(2.0*pi*n/(M-1))\n\n## Code from cephes for i0\n\n_i0A = [\n-4.41534164647933937950E-18,\n 3.33079451882223809783E-17,\n-2.43127984654795469359E-16,\n 1.71539128555513303061E-15,\n-1.16853328779934516808E-14,\n 7.67618549860493561688E-14,\n-4.85644678311192946090E-13,\n 2.95505266312963983461E-12,\n-1.72682629144155570723E-11,\n 9.67580903537323691224E-11,\n-5.18979560163526290666E-10,\n 2.65982372468238665035E-9,\n-1.30002500998624804212E-8,\n 6.04699502254191894932E-8,\n-2.67079385394061173391E-7,\n 1.11738753912010371815E-6,\n-4.41673835845875056359E-6,\n 1.64484480707288970893E-5,\n-5.75419501008210370398E-5,\n 1.88502885095841655729E-4,\n-5.76375574538582365885E-4,\n 1.63947561694133579842E-3,\n-4.32430999505057594430E-3,\n 1.05464603945949983183E-2,\n-2.37374148058994688156E-2,\n 4.93052842396707084878E-2,\n-9.49010970480476444210E-2,\n 1.71620901522208775349E-1,\n-3.04682672343198398683E-1,\n 6.76795274409476084995E-1]\n\n_i0B = [\n-7.23318048787475395456E-18,\n-4.83050448594418207126E-18,\n 4.46562142029675999901E-17,\n 3.46122286769746109310E-17,\n-2.82762398051658348494E-16,\n-3.42548561967721913462E-16,\n 1.77256013305652638360E-15,\n 3.81168066935262242075E-15,\n-9.55484669882830764870E-15,\n-4.15056934728722208663E-14,\n 1.54008621752140982691E-14,\n 3.85277838274214270114E-13,\n 7.18012445138366623367E-13,\n-1.79417853150680611778E-12,\n-1.32158118404477131188E-11,\n-3.14991652796324136454E-11,\n 1.18891471078464383424E-11,\n 4.94060238822496958910E-10,\n 3.39623202570838634515E-9,\n 2.26666899049817806459E-8,\n 2.04891858946906374183E-7,\n 2.89137052083475648297E-6,\n 6.88975834691682398426E-5,\n 3.36911647825569408990E-3,\n 8.04490411014108831608E-1]\n\ndef _chbevl(x, vals):\n b0 = vals[0]\n b1 = 0.0\n\n for i in xrange(1,len(vals)):\n b2 = b1\n b1 = b0\n b0 = x*b1 - b2 + vals[i]\n\n return 0.5*(b0 - b2)\n\ndef _i0_1(x):\n return exp(x) * _chbevl(x/2.0-2, _i0A)\n\ndef _i0_2(x):\n return exp(x) * _chbevl(32.0/x - 2.0, _i0B) / sqrt(x)\n\ndef i0(x):\n x = atleast_1d(x).copy()\n y = empty_like(x)\n ind = (x<0)\n x[ind] = -x[ind]\n ind = (x<=8.0)\n y[ind] = _i0_1(x[ind])\n ind2 = ~ind\n y[ind2] = _i0_2(x[ind2])\n return y.squeeze()\n\n## End of cephes code for i0\n\ndef kaiser(M,beta):\n \"\"\"kaiser(M, beta) returns a Kaiser window of length M with shape parameter\n beta. It depends on numpy.special (in full numpy) for the modified bessel\n function i0.\n \"\"\"\n from numpy.dual import i0\n n = arange(0,M)\n alpha = (M-1)/2.0\n return i0(beta * sqrt(1-((n-alpha)/alpha)**2.0))/i0(beta)\n\ndef sinc(x):\n \"\"\"sinc(x) returns sin(pi*x)/(pi*x) at all points of array x.\n \"\"\"\n y = pi* where(x == 0, 1.0e-20, x)\n return sin(y)/y\n\ndef msort(a):\n b = array(a,copy=True)\n b.sort(0)\n return b\n\ndef median(m):\n \"\"\"median(m) returns a median of m along the first dimension of m.\n \"\"\"\n sorted = msort(m)\n if sorted.shape[0] % 2 == 1:\n return sorted[int(sorted.shape[0]/2)]\n else:\n sorted = msort(m)\n index=sorted.shape[0]/2\n return (sorted[index-1]+sorted[index])/2.0\n\ndef trapz(y, x=None, dx=1.0, axis=-1):\n \"\"\"Integrate y(x) using samples along the given axis and the composite\n trapezoidal rule. If x is None, spacing given by dx is assumed.\n \"\"\"\n y = asarray(y)\n if x is None:\n d = dx\n else:\n d = diff(x,axis=axis)\n nd = len(y.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n return add.reduce(d * (y[slice1]+y[slice2])/2.0,axis)\n\n#always succeed\ndef add_newdoc(place, obj, doc):\n try:\n new = {}\n exec 'from %s import %s' % (place, obj) in new\n if isinstance(doc, str):\n add_docstring(new[obj], doc.strip())\n elif isinstance(doc, tuple):\n add_docstring(getattr(new[obj], doc[0]), doc[1].strip())\n elif isinstance(doc, list):\n for val in doc:\n add_docstring(getattr(new[obj], val[0]), val[1].strip())\n except:\n pass\n", + "methods": [ + { + "name": "linspace", + "long_name": "linspace( start , stop , num = 50 , endpoint = True , retstep = False )", + "filename": "function_base.py", + "nloc": 15, + "complexity": 5, + "token_count": 107, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "retstep" + ], + "start_line": 31, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "logspace", + "long_name": "logspace( start , stop , num = 50 , endpoint = True , base = 10 . 0 )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 47, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "base" + ], + "start_line": 53, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 63, + "end_line": 66, + "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": 174, + "parameters": [ + "a", + "bins", + "range", + "normed" + ], + "start_line": 68, + "end_line": 87, + "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": 334, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 89, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 0 + }, + { + "name": "asarray_chkfinite", + "long_name": "asarray_chkfinite( a )", + "filename": "function_base.py", + "nloc": 6, + "complexity": 4, + "token_count": 59, + "parameters": [ + "a" + ], + "start_line": 161, + "end_line": 168, + "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": 22, + "complexity": 7, + "token_count": 172, + "parameters": [ + "x", + "condlist", + "funclist", + "args", + "kw" + ], + "start_line": 170, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "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": 226, + "end_line": 272, + "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": 274, + "end_line": 280, + "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": 282, + "end_line": 285, + "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": 329, + "parameters": [ + "f", + "varargs" + ], + "start_line": 289, + "end_line": 361, + "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": 364, + "end_line": 382, + "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": 74, + "parameters": [ + "z", + "deg" + ], + "start_line": 384, + "end_line": 398, + "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": 400, + "end_line": 415, + "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": 12, + "complexity": 4, + "token_count": 81, + "parameters": [ + "a" + ], + "start_line": 417, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 435, + "end_line": 455, + "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": 457, + "end_line": 464, + "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": 466, + "end_line": 472, + "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": 19, + "parameters": [ + "arr", + "mask", + "vals" + ], + "start_line": 474, + "end_line": 479, + "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": 48, + "parameters": [ + "a", + "axis" + ], + "start_line": 481, + "end_line": 487, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 489, + "end_line": 495, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 497, + "end_line": 503, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 505, + "end_line": 511, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 513, + "end_line": 519, + "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": 521, + "end_line": 533, + "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": 25, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self", + "pyfunc", + "otypes", + "doc" + ], + "start_line": 566, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "function_base.py", + "nloc": 27, + "complexity": 13, + "token_count": 256, + "parameters": [ + "self", + "args" + ], + "start_line": 593, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "cov", + "long_name": "cov( m , y = None , rowvar = 1 , bias = 0 )", + "filename": "function_base.py", + "nloc": 26, + "complexity": 7, + "token_count": 207, + "parameters": [ + "m", + "y", + "rowvar", + "bias" + ], + "start_line": 625, + "end_line": 670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "corrcoef", + "long_name": "corrcoef( x , y = None )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 38, + "parameters": [ + "x", + "y" + ], + "start_line": 672, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "blackman", + "long_name": "blackman( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 679, + "end_line": 683, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "bartlett", + "long_name": "bartlett( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 685, + "end_line": 689, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hanning", + "long_name": "hanning( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 691, + "end_line": 695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hamming", + "long_name": "hamming( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 697, + "end_line": 701, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_chbevl", + "long_name": "_chbevl( x , vals )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 59, + "parameters": [ + "x", + "vals" + ], + "start_line": 764, + "end_line": 773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_i0_1", + "long_name": "_i0_1( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 23, + "parameters": [ + "x" + ], + "start_line": 775, + "end_line": 776, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_i0_2", + "long_name": "_i0_2( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 30, + "parameters": [ + "x" + ], + "start_line": 778, + "end_line": 779, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "i0", + "long_name": "i0( x )", + "filename": "function_base.py", + "nloc": 10, + "complexity": 1, + "token_count": 81, + "parameters": [ + "x" + ], + "start_line": 781, + "end_line": 790, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "kaiser", + "long_name": "kaiser( M , beta )", + "filename": "function_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 62, + "parameters": [ + "M", + "beta" + ], + "start_line": 794, + "end_line": 802, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "sinc", + "long_name": "sinc( x )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "x" + ], + "start_line": 804, + "end_line": 808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "msort", + "long_name": "msort( a )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a" + ], + "start_line": 810, + "end_line": 813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "median", + "long_name": "median( m )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 75, + "parameters": [ + "m" + ], + "start_line": 815, + "end_line": 824, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "trapz", + "long_name": "trapz( y , x = None , dx = 1 . 0 , axis = - 1 )", + "filename": "function_base.py", + "nloc": 12, + "complexity": 2, + "token_count": 123, + "parameters": [ + "y", + "x", + "dx", + "axis" + ], + "start_line": 826, + "end_line": 840, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "add_newdoc", + "long_name": "add_newdoc( place , obj , doc )", + "filename": "function_base.py", + "nloc": 13, + "complexity": 6, + "token_count": 118, + "parameters": [ + "place", + "obj", + "doc" + ], + "start_line": 843, + "end_line": 855, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "linspace", + "long_name": "linspace( start , stop , num = 50 , endpoint = True , retstep = False )", + "filename": "function_base.py", + "nloc": 15, + "complexity": 5, + "token_count": 107, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "retstep" + ], + "start_line": 31, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "logspace", + "long_name": "logspace( start , stop , num = 50 , endpoint = True , base = 10 . 0 )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 47, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "base" + ], + "start_line": 53, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 63, + "end_line": 66, + "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": 174, + "parameters": [ + "a", + "bins", + "range", + "normed" + ], + "start_line": 68, + "end_line": 87, + "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": 334, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 89, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 0 + }, + { + "name": "asarray_chkfinite", + "long_name": "asarray_chkfinite( a )", + "filename": "function_base.py", + "nloc": 6, + "complexity": 4, + "token_count": 59, + "parameters": [ + "a" + ], + "start_line": 161, + "end_line": 168, + "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": 22, + "complexity": 7, + "token_count": 172, + "parameters": [ + "x", + "condlist", + "funclist", + "args", + "kw" + ], + "start_line": 170, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "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": 226, + "end_line": 272, + "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": 274, + "end_line": 280, + "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": 282, + "end_line": 285, + "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": 329, + "parameters": [ + "f", + "varargs" + ], + "start_line": 289, + "end_line": 361, + "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": 364, + "end_line": 382, + "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": 74, + "parameters": [ + "z", + "deg" + ], + "start_line": 384, + "end_line": 398, + "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": 400, + "end_line": 415, + "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": 12, + "complexity": 4, + "token_count": 81, + "parameters": [ + "a" + ], + "start_line": 417, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 435, + "end_line": 455, + "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": 457, + "end_line": 464, + "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": 466, + "end_line": 472, + "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": 19, + "parameters": [ + "arr", + "mask", + "vals" + ], + "start_line": 474, + "end_line": 479, + "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": 48, + "parameters": [ + "a", + "axis" + ], + "start_line": 481, + "end_line": 487, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 489, + "end_line": 495, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 497, + "end_line": 503, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 505, + "end_line": 511, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 513, + "end_line": 519, + "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": 521, + "end_line": 533, + "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": 25, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self", + "pyfunc", + "otypes", + "doc" + ], + "start_line": 566, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "function_base.py", + "nloc": 27, + "complexity": 13, + "token_count": 256, + "parameters": [ + "self", + "args" + ], + "start_line": 593, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "cov", + "long_name": "cov( m , y = None , rowvar = 1 , bias = 0 )", + "filename": "function_base.py", + "nloc": 26, + "complexity": 7, + "token_count": 205, + "parameters": [ + "m", + "y", + "rowvar", + "bias" + ], + "start_line": 625, + "end_line": 670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "corrcoef", + "long_name": "corrcoef( x , y = None )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 38, + "parameters": [ + "x", + "y" + ], + "start_line": 672, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "blackman", + "long_name": "blackman( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 679, + "end_line": 683, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "bartlett", + "long_name": "bartlett( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 685, + "end_line": 689, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hanning", + "long_name": "hanning( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 691, + "end_line": 695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hamming", + "long_name": "hamming( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 697, + "end_line": 701, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_chbevl", + "long_name": "_chbevl( x , vals )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 59, + "parameters": [ + "x", + "vals" + ], + "start_line": 764, + "end_line": 773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_i0_1", + "long_name": "_i0_1( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 23, + "parameters": [ + "x" + ], + "start_line": 775, + "end_line": 776, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_i0_2", + "long_name": "_i0_2( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 30, + "parameters": [ + "x" + ], + "start_line": 778, + "end_line": 779, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "i0", + "long_name": "i0( x )", + "filename": "function_base.py", + "nloc": 10, + "complexity": 1, + "token_count": 81, + "parameters": [ + "x" + ], + "start_line": 781, + "end_line": 790, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "kaiser", + "long_name": "kaiser( M , beta )", + "filename": "function_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 62, + "parameters": [ + "M", + "beta" + ], + "start_line": 794, + "end_line": 802, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "sinc", + "long_name": "sinc( x )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "x" + ], + "start_line": 804, + "end_line": 808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "msort", + "long_name": "msort( a )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a" + ], + "start_line": 810, + "end_line": 813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "median", + "long_name": "median( m )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 75, + "parameters": [ + "m" + ], + "start_line": 815, + "end_line": 824, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "trapz", + "long_name": "trapz( y , x = None , dx = 1 . 0 , axis = - 1 )", + "filename": "function_base.py", + "nloc": 12, + "complexity": 2, + "token_count": 123, + "parameters": [ + "y", + "x", + "dx", + "axis" + ], + "start_line": 826, + "end_line": 840, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "add_newdoc", + "long_name": "add_newdoc( place , obj , doc )", + "filename": "function_base.py", + "nloc": 13, + "complexity": 6, + "token_count": 118, + "parameters": [ + "place", + "obj", + "doc" + ], + "start_line": 843, + "end_line": 855, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "cov", + "long_name": "cov( m , y = None , rowvar = 1 , bias = 0 )", + "filename": "function_base.py", + "nloc": 26, + "complexity": 7, + "token_count": 207, + "parameters": [ + "m", + "y", + "rowvar", + "bias" + ], + "start_line": 625, + "end_line": 670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + } + ], + "nloc": 563, + "complexity": 140, + "token_count": 4451, + "diff_parsed": { + "added": [ + " X -= X.mean(axis=1-axis)[tup]" + ], + "deleted": [ + " X -= X.mean(axis=axis)[tup]" + ] + } + } + ] + }, + { + "hash": "7b85f2193b938e748120695cf5d3a09a811d831f", + "msg": "Third time's the charm.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-16T17:44:20+00:00", + "author_timezone": 0, + "committer_date": "2006-03-16T17:44:20+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "0818507117b55a7f0e95dfc3cbe9f6ed1354aad9" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 2, + "insertions": 3, + "lines": 5, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/lib/function_base.py", + "new_path": "numpy/lib/function_base.py", + "filename": "function_base.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -644,10 +644,11 @@ def cov(m,y=None, rowvar=1, bias=0):\n rowvar = 1\n if rowvar:\n axis = 0\n- tup = (newaxis, slice(None))\n+ tup = (slice(None),newaxis)\n else:\n axis = 1\n- tup = (slice(None),newaxis)\n+ tup = (newaxis, slice(None))\n+\n \n if y is not None:\n y = asarray(y,ndmin=2)\n", + "added_lines": 3, + "deleted_lines": 2, + "source_code": "\n__all__ = ['logspace', 'linspace',\n 'select', 'piecewise', 'trim_zeros',\n 'copy', 'iterable', #'base_repr', 'binary_repr',\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', 'cov', 'corrcoef', 'msort',\n 'median', 'sinc', 'hamming', 'hanning', 'bartlett', 'blackman',\n 'kaiser', 'trapz', 'i0', 'add_newdoc', 'add_docstring',\n ]\n\nimport types\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import ones, zeros, arange, concatenate, array, \\\n asarray, empty, empty_like, asanyarray\nfrom numpy.core.numeric import ScalarType, dot, where, newaxis\nfrom numpy.core.umath import pi, multiply, add, arctan2, \\\n frompyfunc, isnan, cos, less_equal, sqrt, sin, mod, exp\nfrom numpy.core.oldnumeric import ravel, nonzero, choose, \\\n typecodes, ArrayType, squeeze,\\\n sort\nfrom type_check import ScalarType\nfrom shape_base import atleast_1d\nfrom twodim_base import diag\nfrom _compiled_base import digitize, bincount, _insert, add_docstring\n\n#end Fernando's utilities\n\n\ndef linspace(start, stop, num=50, endpoint=True, retstep=False):\n \"\"\"Return evenly spaced numbers.\n\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 num = int(num)\n if num <= 0:\n return array([])\n if endpoint:\n if num == 1:\n return array([start])\n step = (stop-start)/float((num-1))\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 logspace(start,stop,num=50,endpoint=True,base=10.0):\n \"\"\"Evenly spaced numbers on a logarithmic scale.\n\n Computes int(num) evenly spaced exponents from start to stop.\n If endpoint=True, then last exponent is stop.\n Returns base**exponents.\n \"\"\"\n y = linspace(start,stop,num=num,endpoint=endpoint)\n return _nx.power(base,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 = [mi+0.0 for mi in range]\n if mn == mx:\n mn -= 0.5\n mx += 0.5\n bins = linspace(mn, mx, bins, endpoint=False)\n\n n = sort(a).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(n.shape) * 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\ndef asarray_chkfinite(a):\n \"\"\"Like asarray, but check that no NaNs or Infs are present.\n \"\"\"\n a = asarray(a)\n if (a.dtype.char 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\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 A constant may be used in funclist for a function that returns a\n constant (e.g. val and lambda x: val are equivalent in a funclist).\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 x = asanyarray(x)\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[k]\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\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.dtype.char\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.dtype.char)\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.type, _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 numpy\n >>> a = array((0, 0, 0, 1, 2, 3, 2, 1, 0))\n >>> numpy.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 _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.type, _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.type, _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.type, _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.type, _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.type, _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(object):\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 numpy arrays as inputs and returns a\n numpy 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 numpy.\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 = fcode.co_argcount\n if pyfunc.func_defaults:\n self.nin_wo_defaults = self.nin - len(pyfunc.func_defaults)\n else:\n self.nin_wo_defaults = self.nin\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 self.lastcallargs = 0\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 nargs = len(args)\n if (nargs > self.nin) or (nargs < self.nin_wo_defaults):\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]).dtype.char)\n self.otypes = ''.join(otypes)\n\n if (self.ufunc is None) or (self.lastcallargs != nargs):\n self.ufunc = frompyfunc(self.thefunc, nargs, self.nout)\n self.lastcallargs = nargs\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\ndef cov(m,y=None, rowvar=1, bias=0):\n \"\"\"Estimate the covariance matrix.\n\n If m is a vector, return the variance. For matrices return the\n covariance matrix.\n\n If y is given it is treated as an additional (set of)\n variable(s). \n\n Normalization is by (N-1) where N is the number of observations\n (unbiased estimate). If bias is 1 then normalization is by N.\n\n If rowvar is non-zero (default), then each row is a variable with\n observations in the columns, otherwise each column\n is a variable and the observations are in the rows.\n \"\"\"\n\n X = asarray(m,ndmin=2)\n if X.shape[0] == 1:\n rowvar = 1\n if rowvar:\n axis = 0\n tup = (slice(None),newaxis)\n else:\n axis = 1\n tup = (newaxis, slice(None))\n\n \n if y is not None:\n y = asarray(y,ndmin=2)\n X = concatenate((X,y),axis)\n\n X -= X.mean(axis=1-axis)[tup]\n if rowvar:\n N = X.shape[1]\n else:\n N = X.shape[0]\n\n if bias:\n fact = N*1.0\n else:\n fact = N-1.0\n\n if not rowvar:\n return (dot(X.transpose(), X.conj()) / fact).squeeze()\n else:\n return (dot(X,X.transpose().conj())/fact).squeeze()\n \ndef corrcoef(x, y=None):\n \"\"\"The correlation coefficients\n \"\"\"\n c = cov(x, y)\n d = diag(c)\n return c/sqrt(multiply.outer(d,d))\n\ndef blackman(M):\n \"\"\"blackman(M) returns the M-point Blackman window.\n \"\"\"\n n = arange(0,M)\n return 0.42-0.5*cos(2.0*pi*n/(M-1)) + 0.08*cos(4.0*pi*n/(M-1))\n\ndef bartlett(M):\n \"\"\"bartlett(M) returns the M-point Bartlett window.\n \"\"\"\n n = arange(0,M)\n return where(less_equal(n,(M-1)/2.0),2.0*n/(M-1),2.0-2.0*n/(M-1))\n\ndef hanning(M):\n \"\"\"hanning(M) returns the M-point Hanning window.\n \"\"\"\n n = arange(0,M)\n return 0.5-0.5*cos(2.0*pi*n/(M-1))\n\ndef hamming(M):\n \"\"\"hamming(M) returns the M-point Hamming window.\n \"\"\"\n n = arange(0,M)\n return 0.54-0.46*cos(2.0*pi*n/(M-1))\n\n## Code from cephes for i0\n\n_i0A = [\n-4.41534164647933937950E-18,\n 3.33079451882223809783E-17,\n-2.43127984654795469359E-16,\n 1.71539128555513303061E-15,\n-1.16853328779934516808E-14,\n 7.67618549860493561688E-14,\n-4.85644678311192946090E-13,\n 2.95505266312963983461E-12,\n-1.72682629144155570723E-11,\n 9.67580903537323691224E-11,\n-5.18979560163526290666E-10,\n 2.65982372468238665035E-9,\n-1.30002500998624804212E-8,\n 6.04699502254191894932E-8,\n-2.67079385394061173391E-7,\n 1.11738753912010371815E-6,\n-4.41673835845875056359E-6,\n 1.64484480707288970893E-5,\n-5.75419501008210370398E-5,\n 1.88502885095841655729E-4,\n-5.76375574538582365885E-4,\n 1.63947561694133579842E-3,\n-4.32430999505057594430E-3,\n 1.05464603945949983183E-2,\n-2.37374148058994688156E-2,\n 4.93052842396707084878E-2,\n-9.49010970480476444210E-2,\n 1.71620901522208775349E-1,\n-3.04682672343198398683E-1,\n 6.76795274409476084995E-1]\n\n_i0B = [\n-7.23318048787475395456E-18,\n-4.83050448594418207126E-18,\n 4.46562142029675999901E-17,\n 3.46122286769746109310E-17,\n-2.82762398051658348494E-16,\n-3.42548561967721913462E-16,\n 1.77256013305652638360E-15,\n 3.81168066935262242075E-15,\n-9.55484669882830764870E-15,\n-4.15056934728722208663E-14,\n 1.54008621752140982691E-14,\n 3.85277838274214270114E-13,\n 7.18012445138366623367E-13,\n-1.79417853150680611778E-12,\n-1.32158118404477131188E-11,\n-3.14991652796324136454E-11,\n 1.18891471078464383424E-11,\n 4.94060238822496958910E-10,\n 3.39623202570838634515E-9,\n 2.26666899049817806459E-8,\n 2.04891858946906374183E-7,\n 2.89137052083475648297E-6,\n 6.88975834691682398426E-5,\n 3.36911647825569408990E-3,\n 8.04490411014108831608E-1]\n\ndef _chbevl(x, vals):\n b0 = vals[0]\n b1 = 0.0\n\n for i in xrange(1,len(vals)):\n b2 = b1\n b1 = b0\n b0 = x*b1 - b2 + vals[i]\n\n return 0.5*(b0 - b2)\n\ndef _i0_1(x):\n return exp(x) * _chbevl(x/2.0-2, _i0A)\n\ndef _i0_2(x):\n return exp(x) * _chbevl(32.0/x - 2.0, _i0B) / sqrt(x)\n\ndef i0(x):\n x = atleast_1d(x).copy()\n y = empty_like(x)\n ind = (x<0)\n x[ind] = -x[ind]\n ind = (x<=8.0)\n y[ind] = _i0_1(x[ind])\n ind2 = ~ind\n y[ind2] = _i0_2(x[ind2])\n return y.squeeze()\n\n## End of cephes code for i0\n\ndef kaiser(M,beta):\n \"\"\"kaiser(M, beta) returns a Kaiser window of length M with shape parameter\n beta. It depends on numpy.special (in full numpy) for the modified bessel\n function i0.\n \"\"\"\n from numpy.dual import i0\n n = arange(0,M)\n alpha = (M-1)/2.0\n return i0(beta * sqrt(1-((n-alpha)/alpha)**2.0))/i0(beta)\n\ndef sinc(x):\n \"\"\"sinc(x) returns sin(pi*x)/(pi*x) at all points of array x.\n \"\"\"\n y = pi* where(x == 0, 1.0e-20, x)\n return sin(y)/y\n\ndef msort(a):\n b = array(a,copy=True)\n b.sort(0)\n return b\n\ndef median(m):\n \"\"\"median(m) returns a median of m along the first dimension of m.\n \"\"\"\n sorted = msort(m)\n if sorted.shape[0] % 2 == 1:\n return sorted[int(sorted.shape[0]/2)]\n else:\n sorted = msort(m)\n index=sorted.shape[0]/2\n return (sorted[index-1]+sorted[index])/2.0\n\ndef trapz(y, x=None, dx=1.0, axis=-1):\n \"\"\"Integrate y(x) using samples along the given axis and the composite\n trapezoidal rule. If x is None, spacing given by dx is assumed.\n \"\"\"\n y = asarray(y)\n if x is None:\n d = dx\n else:\n d = diff(x,axis=axis)\n nd = len(y.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n return add.reduce(d * (y[slice1]+y[slice2])/2.0,axis)\n\n#always succeed\ndef add_newdoc(place, obj, doc):\n try:\n new = {}\n exec 'from %s import %s' % (place, obj) in new\n if isinstance(doc, str):\n add_docstring(new[obj], doc.strip())\n elif isinstance(doc, tuple):\n add_docstring(getattr(new[obj], doc[0]), doc[1].strip())\n elif isinstance(doc, list):\n for val in doc:\n add_docstring(getattr(new[obj], val[0]), val[1].strip())\n except:\n pass\n", + "source_code_before": "\n__all__ = ['logspace', 'linspace',\n 'select', 'piecewise', 'trim_zeros',\n 'copy', 'iterable', #'base_repr', 'binary_repr',\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', 'cov', 'corrcoef', 'msort',\n 'median', 'sinc', 'hamming', 'hanning', 'bartlett', 'blackman',\n 'kaiser', 'trapz', 'i0', 'add_newdoc', 'add_docstring',\n ]\n\nimport types\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import ones, zeros, arange, concatenate, array, \\\n asarray, empty, empty_like, asanyarray\nfrom numpy.core.numeric import ScalarType, dot, where, newaxis\nfrom numpy.core.umath import pi, multiply, add, arctan2, \\\n frompyfunc, isnan, cos, less_equal, sqrt, sin, mod, exp\nfrom numpy.core.oldnumeric import ravel, nonzero, choose, \\\n typecodes, ArrayType, squeeze,\\\n sort\nfrom type_check import ScalarType\nfrom shape_base import atleast_1d\nfrom twodim_base import diag\nfrom _compiled_base import digitize, bincount, _insert, add_docstring\n\n#end Fernando's utilities\n\n\ndef linspace(start, stop, num=50, endpoint=True, retstep=False):\n \"\"\"Return evenly spaced numbers.\n\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 num = int(num)\n if num <= 0:\n return array([])\n if endpoint:\n if num == 1:\n return array([start])\n step = (stop-start)/float((num-1))\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 logspace(start,stop,num=50,endpoint=True,base=10.0):\n \"\"\"Evenly spaced numbers on a logarithmic scale.\n\n Computes int(num) evenly spaced exponents from start to stop.\n If endpoint=True, then last exponent is stop.\n Returns base**exponents.\n \"\"\"\n y = linspace(start,stop,num=num,endpoint=endpoint)\n return _nx.power(base,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 = [mi+0.0 for mi in range]\n if mn == mx:\n mn -= 0.5\n mx += 0.5\n bins = linspace(mn, mx, bins, endpoint=False)\n\n n = sort(a).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(n.shape) * 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\ndef asarray_chkfinite(a):\n \"\"\"Like asarray, but check that no NaNs or Infs are present.\n \"\"\"\n a = asarray(a)\n if (a.dtype.char 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\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 A constant may be used in funclist for a function that returns a\n constant (e.g. val and lambda x: val are equivalent in a funclist).\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 x = asanyarray(x)\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[k]\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\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.dtype.char\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.dtype.char)\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.type, _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 numpy\n >>> a = array((0, 0, 0, 1, 2, 3, 2, 1, 0))\n >>> numpy.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 _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.type, _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.type, _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.type, _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.type, _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.type, _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(object):\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 numpy arrays as inputs and returns a\n numpy 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 numpy.\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 = fcode.co_argcount\n if pyfunc.func_defaults:\n self.nin_wo_defaults = self.nin - len(pyfunc.func_defaults)\n else:\n self.nin_wo_defaults = self.nin\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 self.lastcallargs = 0\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 nargs = len(args)\n if (nargs > self.nin) or (nargs < self.nin_wo_defaults):\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]).dtype.char)\n self.otypes = ''.join(otypes)\n\n if (self.ufunc is None) or (self.lastcallargs != nargs):\n self.ufunc = frompyfunc(self.thefunc, nargs, self.nout)\n self.lastcallargs = nargs\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\ndef cov(m,y=None, rowvar=1, bias=0):\n \"\"\"Estimate the covariance matrix.\n\n If m is a vector, return the variance. For matrices return the\n covariance matrix.\n\n If y is given it is treated as an additional (set of)\n variable(s). \n\n Normalization is by (N-1) where N is the number of observations\n (unbiased estimate). If bias is 1 then normalization is by N.\n\n If rowvar is non-zero (default), then each row is a variable with\n observations in the columns, otherwise each column\n is a variable and the observations are in the rows.\n \"\"\"\n\n X = asarray(m,ndmin=2)\n if X.shape[0] == 1:\n rowvar = 1\n if rowvar:\n axis = 0\n tup = (newaxis, slice(None))\n else:\n axis = 1\n tup = (slice(None),newaxis)\n \n if y is not None:\n y = asarray(y,ndmin=2)\n X = concatenate((X,y),axis)\n\n X -= X.mean(axis=1-axis)[tup]\n if rowvar:\n N = X.shape[1]\n else:\n N = X.shape[0]\n\n if bias:\n fact = N*1.0\n else:\n fact = N-1.0\n\n if not rowvar:\n return (dot(X.transpose(), X.conj()) / fact).squeeze()\n else:\n return (dot(X,X.transpose().conj())/fact).squeeze()\n \ndef corrcoef(x, y=None):\n \"\"\"The correlation coefficients\n \"\"\"\n c = cov(x, y)\n d = diag(c)\n return c/sqrt(multiply.outer(d,d))\n\ndef blackman(M):\n \"\"\"blackman(M) returns the M-point Blackman window.\n \"\"\"\n n = arange(0,M)\n return 0.42-0.5*cos(2.0*pi*n/(M-1)) + 0.08*cos(4.0*pi*n/(M-1))\n\ndef bartlett(M):\n \"\"\"bartlett(M) returns the M-point Bartlett window.\n \"\"\"\n n = arange(0,M)\n return where(less_equal(n,(M-1)/2.0),2.0*n/(M-1),2.0-2.0*n/(M-1))\n\ndef hanning(M):\n \"\"\"hanning(M) returns the M-point Hanning window.\n \"\"\"\n n = arange(0,M)\n return 0.5-0.5*cos(2.0*pi*n/(M-1))\n\ndef hamming(M):\n \"\"\"hamming(M) returns the M-point Hamming window.\n \"\"\"\n n = arange(0,M)\n return 0.54-0.46*cos(2.0*pi*n/(M-1))\n\n## Code from cephes for i0\n\n_i0A = [\n-4.41534164647933937950E-18,\n 3.33079451882223809783E-17,\n-2.43127984654795469359E-16,\n 1.71539128555513303061E-15,\n-1.16853328779934516808E-14,\n 7.67618549860493561688E-14,\n-4.85644678311192946090E-13,\n 2.95505266312963983461E-12,\n-1.72682629144155570723E-11,\n 9.67580903537323691224E-11,\n-5.18979560163526290666E-10,\n 2.65982372468238665035E-9,\n-1.30002500998624804212E-8,\n 6.04699502254191894932E-8,\n-2.67079385394061173391E-7,\n 1.11738753912010371815E-6,\n-4.41673835845875056359E-6,\n 1.64484480707288970893E-5,\n-5.75419501008210370398E-5,\n 1.88502885095841655729E-4,\n-5.76375574538582365885E-4,\n 1.63947561694133579842E-3,\n-4.32430999505057594430E-3,\n 1.05464603945949983183E-2,\n-2.37374148058994688156E-2,\n 4.93052842396707084878E-2,\n-9.49010970480476444210E-2,\n 1.71620901522208775349E-1,\n-3.04682672343198398683E-1,\n 6.76795274409476084995E-1]\n\n_i0B = [\n-7.23318048787475395456E-18,\n-4.83050448594418207126E-18,\n 4.46562142029675999901E-17,\n 3.46122286769746109310E-17,\n-2.82762398051658348494E-16,\n-3.42548561967721913462E-16,\n 1.77256013305652638360E-15,\n 3.81168066935262242075E-15,\n-9.55484669882830764870E-15,\n-4.15056934728722208663E-14,\n 1.54008621752140982691E-14,\n 3.85277838274214270114E-13,\n 7.18012445138366623367E-13,\n-1.79417853150680611778E-12,\n-1.32158118404477131188E-11,\n-3.14991652796324136454E-11,\n 1.18891471078464383424E-11,\n 4.94060238822496958910E-10,\n 3.39623202570838634515E-9,\n 2.26666899049817806459E-8,\n 2.04891858946906374183E-7,\n 2.89137052083475648297E-6,\n 6.88975834691682398426E-5,\n 3.36911647825569408990E-3,\n 8.04490411014108831608E-1]\n\ndef _chbevl(x, vals):\n b0 = vals[0]\n b1 = 0.0\n\n for i in xrange(1,len(vals)):\n b2 = b1\n b1 = b0\n b0 = x*b1 - b2 + vals[i]\n\n return 0.5*(b0 - b2)\n\ndef _i0_1(x):\n return exp(x) * _chbevl(x/2.0-2, _i0A)\n\ndef _i0_2(x):\n return exp(x) * _chbevl(32.0/x - 2.0, _i0B) / sqrt(x)\n\ndef i0(x):\n x = atleast_1d(x).copy()\n y = empty_like(x)\n ind = (x<0)\n x[ind] = -x[ind]\n ind = (x<=8.0)\n y[ind] = _i0_1(x[ind])\n ind2 = ~ind\n y[ind2] = _i0_2(x[ind2])\n return y.squeeze()\n\n## End of cephes code for i0\n\ndef kaiser(M,beta):\n \"\"\"kaiser(M, beta) returns a Kaiser window of length M with shape parameter\n beta. It depends on numpy.special (in full numpy) for the modified bessel\n function i0.\n \"\"\"\n from numpy.dual import i0\n n = arange(0,M)\n alpha = (M-1)/2.0\n return i0(beta * sqrt(1-((n-alpha)/alpha)**2.0))/i0(beta)\n\ndef sinc(x):\n \"\"\"sinc(x) returns sin(pi*x)/(pi*x) at all points of array x.\n \"\"\"\n y = pi* where(x == 0, 1.0e-20, x)\n return sin(y)/y\n\ndef msort(a):\n b = array(a,copy=True)\n b.sort(0)\n return b\n\ndef median(m):\n \"\"\"median(m) returns a median of m along the first dimension of m.\n \"\"\"\n sorted = msort(m)\n if sorted.shape[0] % 2 == 1:\n return sorted[int(sorted.shape[0]/2)]\n else:\n sorted = msort(m)\n index=sorted.shape[0]/2\n return (sorted[index-1]+sorted[index])/2.0\n\ndef trapz(y, x=None, dx=1.0, axis=-1):\n \"\"\"Integrate y(x) using samples along the given axis and the composite\n trapezoidal rule. If x is None, spacing given by dx is assumed.\n \"\"\"\n y = asarray(y)\n if x is None:\n d = dx\n else:\n d = diff(x,axis=axis)\n nd = len(y.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n return add.reduce(d * (y[slice1]+y[slice2])/2.0,axis)\n\n#always succeed\ndef add_newdoc(place, obj, doc):\n try:\n new = {}\n exec 'from %s import %s' % (place, obj) in new\n if isinstance(doc, str):\n add_docstring(new[obj], doc.strip())\n elif isinstance(doc, tuple):\n add_docstring(getattr(new[obj], doc[0]), doc[1].strip())\n elif isinstance(doc, list):\n for val in doc:\n add_docstring(getattr(new[obj], val[0]), val[1].strip())\n except:\n pass\n", + "methods": [ + { + "name": "linspace", + "long_name": "linspace( start , stop , num = 50 , endpoint = True , retstep = False )", + "filename": "function_base.py", + "nloc": 15, + "complexity": 5, + "token_count": 107, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "retstep" + ], + "start_line": 31, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "logspace", + "long_name": "logspace( start , stop , num = 50 , endpoint = True , base = 10 . 0 )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 47, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "base" + ], + "start_line": 53, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 63, + "end_line": 66, + "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": 174, + "parameters": [ + "a", + "bins", + "range", + "normed" + ], + "start_line": 68, + "end_line": 87, + "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": 334, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 89, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 0 + }, + { + "name": "asarray_chkfinite", + "long_name": "asarray_chkfinite( a )", + "filename": "function_base.py", + "nloc": 6, + "complexity": 4, + "token_count": 59, + "parameters": [ + "a" + ], + "start_line": 161, + "end_line": 168, + "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": 22, + "complexity": 7, + "token_count": 172, + "parameters": [ + "x", + "condlist", + "funclist", + "args", + "kw" + ], + "start_line": 170, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "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": 226, + "end_line": 272, + "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": 274, + "end_line": 280, + "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": 282, + "end_line": 285, + "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": 329, + "parameters": [ + "f", + "varargs" + ], + "start_line": 289, + "end_line": 361, + "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": 364, + "end_line": 382, + "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": 74, + "parameters": [ + "z", + "deg" + ], + "start_line": 384, + "end_line": 398, + "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": 400, + "end_line": 415, + "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": 12, + "complexity": 4, + "token_count": 81, + "parameters": [ + "a" + ], + "start_line": 417, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 435, + "end_line": 455, + "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": 457, + "end_line": 464, + "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": 466, + "end_line": 472, + "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": 19, + "parameters": [ + "arr", + "mask", + "vals" + ], + "start_line": 474, + "end_line": 479, + "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": 48, + "parameters": [ + "a", + "axis" + ], + "start_line": 481, + "end_line": 487, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 489, + "end_line": 495, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 497, + "end_line": 503, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 505, + "end_line": 511, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 513, + "end_line": 519, + "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": 521, + "end_line": 533, + "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": 25, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self", + "pyfunc", + "otypes", + "doc" + ], + "start_line": 566, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "function_base.py", + "nloc": 27, + "complexity": 13, + "token_count": 256, + "parameters": [ + "self", + "args" + ], + "start_line": 593, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "cov", + "long_name": "cov( m , y = None , rowvar = 1 , bias = 0 )", + "filename": "function_base.py", + "nloc": 26, + "complexity": 7, + "token_count": 207, + "parameters": [ + "m", + "y", + "rowvar", + "bias" + ], + "start_line": 625, + "end_line": 671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "corrcoef", + "long_name": "corrcoef( x , y = None )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 38, + "parameters": [ + "x", + "y" + ], + "start_line": 673, + "end_line": 678, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "blackman", + "long_name": "blackman( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 680, + "end_line": 684, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "bartlett", + "long_name": "bartlett( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 686, + "end_line": 690, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hanning", + "long_name": "hanning( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 692, + "end_line": 696, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hamming", + "long_name": "hamming( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 698, + "end_line": 702, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_chbevl", + "long_name": "_chbevl( x , vals )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 59, + "parameters": [ + "x", + "vals" + ], + "start_line": 765, + "end_line": 774, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_i0_1", + "long_name": "_i0_1( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 23, + "parameters": [ + "x" + ], + "start_line": 776, + "end_line": 777, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_i0_2", + "long_name": "_i0_2( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 30, + "parameters": [ + "x" + ], + "start_line": 779, + "end_line": 780, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "i0", + "long_name": "i0( x )", + "filename": "function_base.py", + "nloc": 10, + "complexity": 1, + "token_count": 81, + "parameters": [ + "x" + ], + "start_line": 782, + "end_line": 791, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "kaiser", + "long_name": "kaiser( M , beta )", + "filename": "function_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 62, + "parameters": [ + "M", + "beta" + ], + "start_line": 795, + "end_line": 803, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "sinc", + "long_name": "sinc( x )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "x" + ], + "start_line": 805, + "end_line": 809, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "msort", + "long_name": "msort( a )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a" + ], + "start_line": 811, + "end_line": 814, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "median", + "long_name": "median( m )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 75, + "parameters": [ + "m" + ], + "start_line": 816, + "end_line": 825, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "trapz", + "long_name": "trapz( y , x = None , dx = 1 . 0 , axis = - 1 )", + "filename": "function_base.py", + "nloc": 12, + "complexity": 2, + "token_count": 123, + "parameters": [ + "y", + "x", + "dx", + "axis" + ], + "start_line": 827, + "end_line": 841, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "add_newdoc", + "long_name": "add_newdoc( place , obj , doc )", + "filename": "function_base.py", + "nloc": 13, + "complexity": 6, + "token_count": 118, + "parameters": [ + "place", + "obj", + "doc" + ], + "start_line": 844, + "end_line": 856, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "linspace", + "long_name": "linspace( start , stop , num = 50 , endpoint = True , retstep = False )", + "filename": "function_base.py", + "nloc": 15, + "complexity": 5, + "token_count": 107, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "retstep" + ], + "start_line": 31, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "logspace", + "long_name": "logspace( start , stop , num = 50 , endpoint = True , base = 10 . 0 )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 47, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "base" + ], + "start_line": 53, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 63, + "end_line": 66, + "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": 174, + "parameters": [ + "a", + "bins", + "range", + "normed" + ], + "start_line": 68, + "end_line": 87, + "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": 334, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 89, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 0 + }, + { + "name": "asarray_chkfinite", + "long_name": "asarray_chkfinite( a )", + "filename": "function_base.py", + "nloc": 6, + "complexity": 4, + "token_count": 59, + "parameters": [ + "a" + ], + "start_line": 161, + "end_line": 168, + "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": 22, + "complexity": 7, + "token_count": 172, + "parameters": [ + "x", + "condlist", + "funclist", + "args", + "kw" + ], + "start_line": 170, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "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": 226, + "end_line": 272, + "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": 274, + "end_line": 280, + "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": 282, + "end_line": 285, + "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": 329, + "parameters": [ + "f", + "varargs" + ], + "start_line": 289, + "end_line": 361, + "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": 364, + "end_line": 382, + "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": 74, + "parameters": [ + "z", + "deg" + ], + "start_line": 384, + "end_line": 398, + "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": 400, + "end_line": 415, + "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": 12, + "complexity": 4, + "token_count": 81, + "parameters": [ + "a" + ], + "start_line": 417, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 435, + "end_line": 455, + "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": 457, + "end_line": 464, + "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": 466, + "end_line": 472, + "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": 19, + "parameters": [ + "arr", + "mask", + "vals" + ], + "start_line": 474, + "end_line": 479, + "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": 48, + "parameters": [ + "a", + "axis" + ], + "start_line": 481, + "end_line": 487, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 489, + "end_line": 495, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 497, + "end_line": 503, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 505, + "end_line": 511, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 513, + "end_line": 519, + "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": 521, + "end_line": 533, + "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": 25, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self", + "pyfunc", + "otypes", + "doc" + ], + "start_line": 566, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "function_base.py", + "nloc": 27, + "complexity": 13, + "token_count": 256, + "parameters": [ + "self", + "args" + ], + "start_line": 593, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "cov", + "long_name": "cov( m , y = None , rowvar = 1 , bias = 0 )", + "filename": "function_base.py", + "nloc": 26, + "complexity": 7, + "token_count": 207, + "parameters": [ + "m", + "y", + "rowvar", + "bias" + ], + "start_line": 625, + "end_line": 670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "corrcoef", + "long_name": "corrcoef( x , y = None )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 38, + "parameters": [ + "x", + "y" + ], + "start_line": 672, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "blackman", + "long_name": "blackman( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 679, + "end_line": 683, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "bartlett", + "long_name": "bartlett( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 685, + "end_line": 689, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hanning", + "long_name": "hanning( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 691, + "end_line": 695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hamming", + "long_name": "hamming( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 697, + "end_line": 701, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_chbevl", + "long_name": "_chbevl( x , vals )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 59, + "parameters": [ + "x", + "vals" + ], + "start_line": 764, + "end_line": 773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_i0_1", + "long_name": "_i0_1( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 23, + "parameters": [ + "x" + ], + "start_line": 775, + "end_line": 776, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_i0_2", + "long_name": "_i0_2( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 30, + "parameters": [ + "x" + ], + "start_line": 778, + "end_line": 779, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "i0", + "long_name": "i0( x )", + "filename": "function_base.py", + "nloc": 10, + "complexity": 1, + "token_count": 81, + "parameters": [ + "x" + ], + "start_line": 781, + "end_line": 790, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "kaiser", + "long_name": "kaiser( M , beta )", + "filename": "function_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 62, + "parameters": [ + "M", + "beta" + ], + "start_line": 794, + "end_line": 802, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "sinc", + "long_name": "sinc( x )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "x" + ], + "start_line": 804, + "end_line": 808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "msort", + "long_name": "msort( a )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a" + ], + "start_line": 810, + "end_line": 813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "median", + "long_name": "median( m )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 75, + "parameters": [ + "m" + ], + "start_line": 815, + "end_line": 824, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "trapz", + "long_name": "trapz( y , x = None , dx = 1 . 0 , axis = - 1 )", + "filename": "function_base.py", + "nloc": 12, + "complexity": 2, + "token_count": 123, + "parameters": [ + "y", + "x", + "dx", + "axis" + ], + "start_line": 826, + "end_line": 840, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "add_newdoc", + "long_name": "add_newdoc( place , obj , doc )", + "filename": "function_base.py", + "nloc": 13, + "complexity": 6, + "token_count": 118, + "parameters": [ + "place", + "obj", + "doc" + ], + "start_line": 843, + "end_line": 855, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "cov", + "long_name": "cov( m , y = None , rowvar = 1 , bias = 0 )", + "filename": "function_base.py", + "nloc": 26, + "complexity": 7, + "token_count": 207, + "parameters": [ + "m", + "y", + "rowvar", + "bias" + ], + "start_line": 625, + "end_line": 671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + } + ], + "nloc": 563, + "complexity": 140, + "token_count": 4451, + "diff_parsed": { + "added": [ + " tup = (slice(None),newaxis)", + " tup = (newaxis, slice(None))", + "" + ], + "deleted": [ + " tup = (newaxis, slice(None))", + " tup = (slice(None),newaxis)" + ] + } + } + ] + }, + { + "hash": "9003457feff1a215d296a300dc8e2682fa797592", + "msg": "Fix scalar case for corrcoef", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-16T17:57:07+00:00", + "author_timezone": 0, + "committer_date": "2006-03-16T17:57:07+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "7b85f2193b938e748120695cf5d3a09a811d831f" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 1, + "insertions": 4, + "lines": 5, + "files": 1, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/lib/function_base.py", + "new_path": "numpy/lib/function_base.py", + "filename": "function_base.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -674,7 +674,10 @@ def corrcoef(x, y=None):\n \"\"\"The correlation coefficients\n \"\"\"\n c = cov(x, y)\n- d = diag(c)\n+ try:\n+ d = diag(c)\n+ except ValueError: # scalar covariance\n+ return 1\n return c/sqrt(multiply.outer(d,d))\n \n def blackman(M):\n", + "added_lines": 4, + "deleted_lines": 1, + "source_code": "\n__all__ = ['logspace', 'linspace',\n 'select', 'piecewise', 'trim_zeros',\n 'copy', 'iterable', #'base_repr', 'binary_repr',\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', 'cov', 'corrcoef', 'msort',\n 'median', 'sinc', 'hamming', 'hanning', 'bartlett', 'blackman',\n 'kaiser', 'trapz', 'i0', 'add_newdoc', 'add_docstring',\n ]\n\nimport types\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import ones, zeros, arange, concatenate, array, \\\n asarray, empty, empty_like, asanyarray\nfrom numpy.core.numeric import ScalarType, dot, where, newaxis\nfrom numpy.core.umath import pi, multiply, add, arctan2, \\\n frompyfunc, isnan, cos, less_equal, sqrt, sin, mod, exp\nfrom numpy.core.oldnumeric import ravel, nonzero, choose, \\\n typecodes, ArrayType, squeeze,\\\n sort\nfrom type_check import ScalarType\nfrom shape_base import atleast_1d\nfrom twodim_base import diag\nfrom _compiled_base import digitize, bincount, _insert, add_docstring\n\n#end Fernando's utilities\n\n\ndef linspace(start, stop, num=50, endpoint=True, retstep=False):\n \"\"\"Return evenly spaced numbers.\n\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 num = int(num)\n if num <= 0:\n return array([])\n if endpoint:\n if num == 1:\n return array([start])\n step = (stop-start)/float((num-1))\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 logspace(start,stop,num=50,endpoint=True,base=10.0):\n \"\"\"Evenly spaced numbers on a logarithmic scale.\n\n Computes int(num) evenly spaced exponents from start to stop.\n If endpoint=True, then last exponent is stop.\n Returns base**exponents.\n \"\"\"\n y = linspace(start,stop,num=num,endpoint=endpoint)\n return _nx.power(base,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 = [mi+0.0 for mi in range]\n if mn == mx:\n mn -= 0.5\n mx += 0.5\n bins = linspace(mn, mx, bins, endpoint=False)\n\n n = sort(a).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(n.shape) * 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\ndef asarray_chkfinite(a):\n \"\"\"Like asarray, but check that no NaNs or Infs are present.\n \"\"\"\n a = asarray(a)\n if (a.dtype.char 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\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 A constant may be used in funclist for a function that returns a\n constant (e.g. val and lambda x: val are equivalent in a funclist).\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 x = asanyarray(x)\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[k]\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\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.dtype.char\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.dtype.char)\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.type, _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 numpy\n >>> a = array((0, 0, 0, 1, 2, 3, 2, 1, 0))\n >>> numpy.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 _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.type, _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.type, _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.type, _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.type, _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.type, _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(object):\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 numpy arrays as inputs and returns a\n numpy 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 numpy.\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 = fcode.co_argcount\n if pyfunc.func_defaults:\n self.nin_wo_defaults = self.nin - len(pyfunc.func_defaults)\n else:\n self.nin_wo_defaults = self.nin\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 self.lastcallargs = 0\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 nargs = len(args)\n if (nargs > self.nin) or (nargs < self.nin_wo_defaults):\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]).dtype.char)\n self.otypes = ''.join(otypes)\n\n if (self.ufunc is None) or (self.lastcallargs != nargs):\n self.ufunc = frompyfunc(self.thefunc, nargs, self.nout)\n self.lastcallargs = nargs\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\ndef cov(m,y=None, rowvar=1, bias=0):\n \"\"\"Estimate the covariance matrix.\n\n If m is a vector, return the variance. For matrices return the\n covariance matrix.\n\n If y is given it is treated as an additional (set of)\n variable(s). \n\n Normalization is by (N-1) where N is the number of observations\n (unbiased estimate). If bias is 1 then normalization is by N.\n\n If rowvar is non-zero (default), then each row is a variable with\n observations in the columns, otherwise each column\n is a variable and the observations are in the rows.\n \"\"\"\n\n X = asarray(m,ndmin=2)\n if X.shape[0] == 1:\n rowvar = 1\n if rowvar:\n axis = 0\n tup = (slice(None),newaxis)\n else:\n axis = 1\n tup = (newaxis, slice(None))\n\n \n if y is not None:\n y = asarray(y,ndmin=2)\n X = concatenate((X,y),axis)\n\n X -= X.mean(axis=1-axis)[tup]\n if rowvar:\n N = X.shape[1]\n else:\n N = X.shape[0]\n\n if bias:\n fact = N*1.0\n else:\n fact = N-1.0\n\n if not rowvar:\n return (dot(X.transpose(), X.conj()) / fact).squeeze()\n else:\n return (dot(X,X.transpose().conj())/fact).squeeze()\n \ndef corrcoef(x, y=None):\n \"\"\"The correlation coefficients\n \"\"\"\n c = cov(x, y)\n try:\n d = diag(c)\n except ValueError: # scalar covariance\n return 1\n return c/sqrt(multiply.outer(d,d))\n\ndef blackman(M):\n \"\"\"blackman(M) returns the M-point Blackman window.\n \"\"\"\n n = arange(0,M)\n return 0.42-0.5*cos(2.0*pi*n/(M-1)) + 0.08*cos(4.0*pi*n/(M-1))\n\ndef bartlett(M):\n \"\"\"bartlett(M) returns the M-point Bartlett window.\n \"\"\"\n n = arange(0,M)\n return where(less_equal(n,(M-1)/2.0),2.0*n/(M-1),2.0-2.0*n/(M-1))\n\ndef hanning(M):\n \"\"\"hanning(M) returns the M-point Hanning window.\n \"\"\"\n n = arange(0,M)\n return 0.5-0.5*cos(2.0*pi*n/(M-1))\n\ndef hamming(M):\n \"\"\"hamming(M) returns the M-point Hamming window.\n \"\"\"\n n = arange(0,M)\n return 0.54-0.46*cos(2.0*pi*n/(M-1))\n\n## Code from cephes for i0\n\n_i0A = [\n-4.41534164647933937950E-18,\n 3.33079451882223809783E-17,\n-2.43127984654795469359E-16,\n 1.71539128555513303061E-15,\n-1.16853328779934516808E-14,\n 7.67618549860493561688E-14,\n-4.85644678311192946090E-13,\n 2.95505266312963983461E-12,\n-1.72682629144155570723E-11,\n 9.67580903537323691224E-11,\n-5.18979560163526290666E-10,\n 2.65982372468238665035E-9,\n-1.30002500998624804212E-8,\n 6.04699502254191894932E-8,\n-2.67079385394061173391E-7,\n 1.11738753912010371815E-6,\n-4.41673835845875056359E-6,\n 1.64484480707288970893E-5,\n-5.75419501008210370398E-5,\n 1.88502885095841655729E-4,\n-5.76375574538582365885E-4,\n 1.63947561694133579842E-3,\n-4.32430999505057594430E-3,\n 1.05464603945949983183E-2,\n-2.37374148058994688156E-2,\n 4.93052842396707084878E-2,\n-9.49010970480476444210E-2,\n 1.71620901522208775349E-1,\n-3.04682672343198398683E-1,\n 6.76795274409476084995E-1]\n\n_i0B = [\n-7.23318048787475395456E-18,\n-4.83050448594418207126E-18,\n 4.46562142029675999901E-17,\n 3.46122286769746109310E-17,\n-2.82762398051658348494E-16,\n-3.42548561967721913462E-16,\n 1.77256013305652638360E-15,\n 3.81168066935262242075E-15,\n-9.55484669882830764870E-15,\n-4.15056934728722208663E-14,\n 1.54008621752140982691E-14,\n 3.85277838274214270114E-13,\n 7.18012445138366623367E-13,\n-1.79417853150680611778E-12,\n-1.32158118404477131188E-11,\n-3.14991652796324136454E-11,\n 1.18891471078464383424E-11,\n 4.94060238822496958910E-10,\n 3.39623202570838634515E-9,\n 2.26666899049817806459E-8,\n 2.04891858946906374183E-7,\n 2.89137052083475648297E-6,\n 6.88975834691682398426E-5,\n 3.36911647825569408990E-3,\n 8.04490411014108831608E-1]\n\ndef _chbevl(x, vals):\n b0 = vals[0]\n b1 = 0.0\n\n for i in xrange(1,len(vals)):\n b2 = b1\n b1 = b0\n b0 = x*b1 - b2 + vals[i]\n\n return 0.5*(b0 - b2)\n\ndef _i0_1(x):\n return exp(x) * _chbevl(x/2.0-2, _i0A)\n\ndef _i0_2(x):\n return exp(x) * _chbevl(32.0/x - 2.0, _i0B) / sqrt(x)\n\ndef i0(x):\n x = atleast_1d(x).copy()\n y = empty_like(x)\n ind = (x<0)\n x[ind] = -x[ind]\n ind = (x<=8.0)\n y[ind] = _i0_1(x[ind])\n ind2 = ~ind\n y[ind2] = _i0_2(x[ind2])\n return y.squeeze()\n\n## End of cephes code for i0\n\ndef kaiser(M,beta):\n \"\"\"kaiser(M, beta) returns a Kaiser window of length M with shape parameter\n beta. It depends on numpy.special (in full numpy) for the modified bessel\n function i0.\n \"\"\"\n from numpy.dual import i0\n n = arange(0,M)\n alpha = (M-1)/2.0\n return i0(beta * sqrt(1-((n-alpha)/alpha)**2.0))/i0(beta)\n\ndef sinc(x):\n \"\"\"sinc(x) returns sin(pi*x)/(pi*x) at all points of array x.\n \"\"\"\n y = pi* where(x == 0, 1.0e-20, x)\n return sin(y)/y\n\ndef msort(a):\n b = array(a,copy=True)\n b.sort(0)\n return b\n\ndef median(m):\n \"\"\"median(m) returns a median of m along the first dimension of m.\n \"\"\"\n sorted = msort(m)\n if sorted.shape[0] % 2 == 1:\n return sorted[int(sorted.shape[0]/2)]\n else:\n sorted = msort(m)\n index=sorted.shape[0]/2\n return (sorted[index-1]+sorted[index])/2.0\n\ndef trapz(y, x=None, dx=1.0, axis=-1):\n \"\"\"Integrate y(x) using samples along the given axis and the composite\n trapezoidal rule. If x is None, spacing given by dx is assumed.\n \"\"\"\n y = asarray(y)\n if x is None:\n d = dx\n else:\n d = diff(x,axis=axis)\n nd = len(y.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n return add.reduce(d * (y[slice1]+y[slice2])/2.0,axis)\n\n#always succeed\ndef add_newdoc(place, obj, doc):\n try:\n new = {}\n exec 'from %s import %s' % (place, obj) in new\n if isinstance(doc, str):\n add_docstring(new[obj], doc.strip())\n elif isinstance(doc, tuple):\n add_docstring(getattr(new[obj], doc[0]), doc[1].strip())\n elif isinstance(doc, list):\n for val in doc:\n add_docstring(getattr(new[obj], val[0]), val[1].strip())\n except:\n pass\n", + "source_code_before": "\n__all__ = ['logspace', 'linspace',\n 'select', 'piecewise', 'trim_zeros',\n 'copy', 'iterable', #'base_repr', 'binary_repr',\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', 'cov', 'corrcoef', 'msort',\n 'median', 'sinc', 'hamming', 'hanning', 'bartlett', 'blackman',\n 'kaiser', 'trapz', 'i0', 'add_newdoc', 'add_docstring',\n ]\n\nimport types\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import ones, zeros, arange, concatenate, array, \\\n asarray, empty, empty_like, asanyarray\nfrom numpy.core.numeric import ScalarType, dot, where, newaxis\nfrom numpy.core.umath import pi, multiply, add, arctan2, \\\n frompyfunc, isnan, cos, less_equal, sqrt, sin, mod, exp\nfrom numpy.core.oldnumeric import ravel, nonzero, choose, \\\n typecodes, ArrayType, squeeze,\\\n sort\nfrom type_check import ScalarType\nfrom shape_base import atleast_1d\nfrom twodim_base import diag\nfrom _compiled_base import digitize, bincount, _insert, add_docstring\n\n#end Fernando's utilities\n\n\ndef linspace(start, stop, num=50, endpoint=True, retstep=False):\n \"\"\"Return evenly spaced numbers.\n\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 num = int(num)\n if num <= 0:\n return array([])\n if endpoint:\n if num == 1:\n return array([start])\n step = (stop-start)/float((num-1))\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 logspace(start,stop,num=50,endpoint=True,base=10.0):\n \"\"\"Evenly spaced numbers on a logarithmic scale.\n\n Computes int(num) evenly spaced exponents from start to stop.\n If endpoint=True, then last exponent is stop.\n Returns base**exponents.\n \"\"\"\n y = linspace(start,stop,num=num,endpoint=endpoint)\n return _nx.power(base,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 = [mi+0.0 for mi in range]\n if mn == mx:\n mn -= 0.5\n mx += 0.5\n bins = linspace(mn, mx, bins, endpoint=False)\n\n n = sort(a).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(n.shape) * 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\ndef asarray_chkfinite(a):\n \"\"\"Like asarray, but check that no NaNs or Infs are present.\n \"\"\"\n a = asarray(a)\n if (a.dtype.char 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\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 A constant may be used in funclist for a function that returns a\n constant (e.g. val and lambda x: val are equivalent in a funclist).\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 x = asanyarray(x)\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[k]\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\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.dtype.char\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.dtype.char)\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.type, _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 numpy\n >>> a = array((0, 0, 0, 1, 2, 3, 2, 1, 0))\n >>> numpy.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 _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.type, _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.type, _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.type, _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.type, _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.type, _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(object):\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 numpy arrays as inputs and returns a\n numpy 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 numpy.\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 = fcode.co_argcount\n if pyfunc.func_defaults:\n self.nin_wo_defaults = self.nin - len(pyfunc.func_defaults)\n else:\n self.nin_wo_defaults = self.nin\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 self.lastcallargs = 0\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 nargs = len(args)\n if (nargs > self.nin) or (nargs < self.nin_wo_defaults):\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]).dtype.char)\n self.otypes = ''.join(otypes)\n\n if (self.ufunc is None) or (self.lastcallargs != nargs):\n self.ufunc = frompyfunc(self.thefunc, nargs, self.nout)\n self.lastcallargs = nargs\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\ndef cov(m,y=None, rowvar=1, bias=0):\n \"\"\"Estimate the covariance matrix.\n\n If m is a vector, return the variance. For matrices return the\n covariance matrix.\n\n If y is given it is treated as an additional (set of)\n variable(s). \n\n Normalization is by (N-1) where N is the number of observations\n (unbiased estimate). If bias is 1 then normalization is by N.\n\n If rowvar is non-zero (default), then each row is a variable with\n observations in the columns, otherwise each column\n is a variable and the observations are in the rows.\n \"\"\"\n\n X = asarray(m,ndmin=2)\n if X.shape[0] == 1:\n rowvar = 1\n if rowvar:\n axis = 0\n tup = (slice(None),newaxis)\n else:\n axis = 1\n tup = (newaxis, slice(None))\n\n \n if y is not None:\n y = asarray(y,ndmin=2)\n X = concatenate((X,y),axis)\n\n X -= X.mean(axis=1-axis)[tup]\n if rowvar:\n N = X.shape[1]\n else:\n N = X.shape[0]\n\n if bias:\n fact = N*1.0\n else:\n fact = N-1.0\n\n if not rowvar:\n return (dot(X.transpose(), X.conj()) / fact).squeeze()\n else:\n return (dot(X,X.transpose().conj())/fact).squeeze()\n \ndef corrcoef(x, y=None):\n \"\"\"The correlation coefficients\n \"\"\"\n c = cov(x, y)\n d = diag(c)\n return c/sqrt(multiply.outer(d,d))\n\ndef blackman(M):\n \"\"\"blackman(M) returns the M-point Blackman window.\n \"\"\"\n n = arange(0,M)\n return 0.42-0.5*cos(2.0*pi*n/(M-1)) + 0.08*cos(4.0*pi*n/(M-1))\n\ndef bartlett(M):\n \"\"\"bartlett(M) returns the M-point Bartlett window.\n \"\"\"\n n = arange(0,M)\n return where(less_equal(n,(M-1)/2.0),2.0*n/(M-1),2.0-2.0*n/(M-1))\n\ndef hanning(M):\n \"\"\"hanning(M) returns the M-point Hanning window.\n \"\"\"\n n = arange(0,M)\n return 0.5-0.5*cos(2.0*pi*n/(M-1))\n\ndef hamming(M):\n \"\"\"hamming(M) returns the M-point Hamming window.\n \"\"\"\n n = arange(0,M)\n return 0.54-0.46*cos(2.0*pi*n/(M-1))\n\n## Code from cephes for i0\n\n_i0A = [\n-4.41534164647933937950E-18,\n 3.33079451882223809783E-17,\n-2.43127984654795469359E-16,\n 1.71539128555513303061E-15,\n-1.16853328779934516808E-14,\n 7.67618549860493561688E-14,\n-4.85644678311192946090E-13,\n 2.95505266312963983461E-12,\n-1.72682629144155570723E-11,\n 9.67580903537323691224E-11,\n-5.18979560163526290666E-10,\n 2.65982372468238665035E-9,\n-1.30002500998624804212E-8,\n 6.04699502254191894932E-8,\n-2.67079385394061173391E-7,\n 1.11738753912010371815E-6,\n-4.41673835845875056359E-6,\n 1.64484480707288970893E-5,\n-5.75419501008210370398E-5,\n 1.88502885095841655729E-4,\n-5.76375574538582365885E-4,\n 1.63947561694133579842E-3,\n-4.32430999505057594430E-3,\n 1.05464603945949983183E-2,\n-2.37374148058994688156E-2,\n 4.93052842396707084878E-2,\n-9.49010970480476444210E-2,\n 1.71620901522208775349E-1,\n-3.04682672343198398683E-1,\n 6.76795274409476084995E-1]\n\n_i0B = [\n-7.23318048787475395456E-18,\n-4.83050448594418207126E-18,\n 4.46562142029675999901E-17,\n 3.46122286769746109310E-17,\n-2.82762398051658348494E-16,\n-3.42548561967721913462E-16,\n 1.77256013305652638360E-15,\n 3.81168066935262242075E-15,\n-9.55484669882830764870E-15,\n-4.15056934728722208663E-14,\n 1.54008621752140982691E-14,\n 3.85277838274214270114E-13,\n 7.18012445138366623367E-13,\n-1.79417853150680611778E-12,\n-1.32158118404477131188E-11,\n-3.14991652796324136454E-11,\n 1.18891471078464383424E-11,\n 4.94060238822496958910E-10,\n 3.39623202570838634515E-9,\n 2.26666899049817806459E-8,\n 2.04891858946906374183E-7,\n 2.89137052083475648297E-6,\n 6.88975834691682398426E-5,\n 3.36911647825569408990E-3,\n 8.04490411014108831608E-1]\n\ndef _chbevl(x, vals):\n b0 = vals[0]\n b1 = 0.0\n\n for i in xrange(1,len(vals)):\n b2 = b1\n b1 = b0\n b0 = x*b1 - b2 + vals[i]\n\n return 0.5*(b0 - b2)\n\ndef _i0_1(x):\n return exp(x) * _chbevl(x/2.0-2, _i0A)\n\ndef _i0_2(x):\n return exp(x) * _chbevl(32.0/x - 2.0, _i0B) / sqrt(x)\n\ndef i0(x):\n x = atleast_1d(x).copy()\n y = empty_like(x)\n ind = (x<0)\n x[ind] = -x[ind]\n ind = (x<=8.0)\n y[ind] = _i0_1(x[ind])\n ind2 = ~ind\n y[ind2] = _i0_2(x[ind2])\n return y.squeeze()\n\n## End of cephes code for i0\n\ndef kaiser(M,beta):\n \"\"\"kaiser(M, beta) returns a Kaiser window of length M with shape parameter\n beta. It depends on numpy.special (in full numpy) for the modified bessel\n function i0.\n \"\"\"\n from numpy.dual import i0\n n = arange(0,M)\n alpha = (M-1)/2.0\n return i0(beta * sqrt(1-((n-alpha)/alpha)**2.0))/i0(beta)\n\ndef sinc(x):\n \"\"\"sinc(x) returns sin(pi*x)/(pi*x) at all points of array x.\n \"\"\"\n y = pi* where(x == 0, 1.0e-20, x)\n return sin(y)/y\n\ndef msort(a):\n b = array(a,copy=True)\n b.sort(0)\n return b\n\ndef median(m):\n \"\"\"median(m) returns a median of m along the first dimension of m.\n \"\"\"\n sorted = msort(m)\n if sorted.shape[0] % 2 == 1:\n return sorted[int(sorted.shape[0]/2)]\n else:\n sorted = msort(m)\n index=sorted.shape[0]/2\n return (sorted[index-1]+sorted[index])/2.0\n\ndef trapz(y, x=None, dx=1.0, axis=-1):\n \"\"\"Integrate y(x) using samples along the given axis and the composite\n trapezoidal rule. If x is None, spacing given by dx is assumed.\n \"\"\"\n y = asarray(y)\n if x is None:\n d = dx\n else:\n d = diff(x,axis=axis)\n nd = len(y.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n return add.reduce(d * (y[slice1]+y[slice2])/2.0,axis)\n\n#always succeed\ndef add_newdoc(place, obj, doc):\n try:\n new = {}\n exec 'from %s import %s' % (place, obj) in new\n if isinstance(doc, str):\n add_docstring(new[obj], doc.strip())\n elif isinstance(doc, tuple):\n add_docstring(getattr(new[obj], doc[0]), doc[1].strip())\n elif isinstance(doc, list):\n for val in doc:\n add_docstring(getattr(new[obj], val[0]), val[1].strip())\n except:\n pass\n", + "methods": [ + { + "name": "linspace", + "long_name": "linspace( start , stop , num = 50 , endpoint = True , retstep = False )", + "filename": "function_base.py", + "nloc": 15, + "complexity": 5, + "token_count": 107, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "retstep" + ], + "start_line": 31, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "logspace", + "long_name": "logspace( start , stop , num = 50 , endpoint = True , base = 10 . 0 )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 47, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "base" + ], + "start_line": 53, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 63, + "end_line": 66, + "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": 174, + "parameters": [ + "a", + "bins", + "range", + "normed" + ], + "start_line": 68, + "end_line": 87, + "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": 334, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 89, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 0 + }, + { + "name": "asarray_chkfinite", + "long_name": "asarray_chkfinite( a )", + "filename": "function_base.py", + "nloc": 6, + "complexity": 4, + "token_count": 59, + "parameters": [ + "a" + ], + "start_line": 161, + "end_line": 168, + "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": 22, + "complexity": 7, + "token_count": 172, + "parameters": [ + "x", + "condlist", + "funclist", + "args", + "kw" + ], + "start_line": 170, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "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": 226, + "end_line": 272, + "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": 274, + "end_line": 280, + "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": 282, + "end_line": 285, + "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": 329, + "parameters": [ + "f", + "varargs" + ], + "start_line": 289, + "end_line": 361, + "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": 364, + "end_line": 382, + "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": 74, + "parameters": [ + "z", + "deg" + ], + "start_line": 384, + "end_line": 398, + "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": 400, + "end_line": 415, + "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": 12, + "complexity": 4, + "token_count": 81, + "parameters": [ + "a" + ], + "start_line": 417, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 435, + "end_line": 455, + "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": 457, + "end_line": 464, + "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": 466, + "end_line": 472, + "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": 19, + "parameters": [ + "arr", + "mask", + "vals" + ], + "start_line": 474, + "end_line": 479, + "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": 48, + "parameters": [ + "a", + "axis" + ], + "start_line": 481, + "end_line": 487, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 489, + "end_line": 495, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 497, + "end_line": 503, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 505, + "end_line": 511, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 513, + "end_line": 519, + "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": 521, + "end_line": 533, + "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": 25, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self", + "pyfunc", + "otypes", + "doc" + ], + "start_line": 566, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "function_base.py", + "nloc": 27, + "complexity": 13, + "token_count": 256, + "parameters": [ + "self", + "args" + ], + "start_line": 593, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "cov", + "long_name": "cov( m , y = None , rowvar = 1 , bias = 0 )", + "filename": "function_base.py", + "nloc": 26, + "complexity": 7, + "token_count": 207, + "parameters": [ + "m", + "y", + "rowvar", + "bias" + ], + "start_line": 625, + "end_line": 671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "corrcoef", + "long_name": "corrcoef( x , y = None )", + "filename": "function_base.py", + "nloc": 7, + "complexity": 2, + "token_count": 45, + "parameters": [ + "x", + "y" + ], + "start_line": 673, + "end_line": 681, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "blackman", + "long_name": "blackman( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 683, + "end_line": 687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "bartlett", + "long_name": "bartlett( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 689, + "end_line": 693, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hanning", + "long_name": "hanning( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 695, + "end_line": 699, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hamming", + "long_name": "hamming( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 701, + "end_line": 705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_chbevl", + "long_name": "_chbevl( x , vals )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 59, + "parameters": [ + "x", + "vals" + ], + "start_line": 768, + "end_line": 777, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_i0_1", + "long_name": "_i0_1( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 23, + "parameters": [ + "x" + ], + "start_line": 779, + "end_line": 780, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_i0_2", + "long_name": "_i0_2( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 30, + "parameters": [ + "x" + ], + "start_line": 782, + "end_line": 783, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "i0", + "long_name": "i0( x )", + "filename": "function_base.py", + "nloc": 10, + "complexity": 1, + "token_count": 81, + "parameters": [ + "x" + ], + "start_line": 785, + "end_line": 794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "kaiser", + "long_name": "kaiser( M , beta )", + "filename": "function_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 62, + "parameters": [ + "M", + "beta" + ], + "start_line": 798, + "end_line": 806, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "sinc", + "long_name": "sinc( x )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "x" + ], + "start_line": 808, + "end_line": 812, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "msort", + "long_name": "msort( a )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a" + ], + "start_line": 814, + "end_line": 817, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "median", + "long_name": "median( m )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 75, + "parameters": [ + "m" + ], + "start_line": 819, + "end_line": 828, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "trapz", + "long_name": "trapz( y , x = None , dx = 1 . 0 , axis = - 1 )", + "filename": "function_base.py", + "nloc": 12, + "complexity": 2, + "token_count": 123, + "parameters": [ + "y", + "x", + "dx", + "axis" + ], + "start_line": 830, + "end_line": 844, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "add_newdoc", + "long_name": "add_newdoc( place , obj , doc )", + "filename": "function_base.py", + "nloc": 13, + "complexity": 6, + "token_count": 118, + "parameters": [ + "place", + "obj", + "doc" + ], + "start_line": 847, + "end_line": 859, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "linspace", + "long_name": "linspace( start , stop , num = 50 , endpoint = True , retstep = False )", + "filename": "function_base.py", + "nloc": 15, + "complexity": 5, + "token_count": 107, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "retstep" + ], + "start_line": 31, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "logspace", + "long_name": "logspace( start , stop , num = 50 , endpoint = True , base = 10 . 0 )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 47, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "base" + ], + "start_line": 53, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 63, + "end_line": 66, + "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": 174, + "parameters": [ + "a", + "bins", + "range", + "normed" + ], + "start_line": 68, + "end_line": 87, + "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": 334, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 89, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 0 + }, + { + "name": "asarray_chkfinite", + "long_name": "asarray_chkfinite( a )", + "filename": "function_base.py", + "nloc": 6, + "complexity": 4, + "token_count": 59, + "parameters": [ + "a" + ], + "start_line": 161, + "end_line": 168, + "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": 22, + "complexity": 7, + "token_count": 172, + "parameters": [ + "x", + "condlist", + "funclist", + "args", + "kw" + ], + "start_line": 170, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "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": 226, + "end_line": 272, + "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": 274, + "end_line": 280, + "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": 282, + "end_line": 285, + "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": 329, + "parameters": [ + "f", + "varargs" + ], + "start_line": 289, + "end_line": 361, + "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": 364, + "end_line": 382, + "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": 74, + "parameters": [ + "z", + "deg" + ], + "start_line": 384, + "end_line": 398, + "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": 400, + "end_line": 415, + "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": 12, + "complexity": 4, + "token_count": 81, + "parameters": [ + "a" + ], + "start_line": 417, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 435, + "end_line": 455, + "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": 457, + "end_line": 464, + "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": 466, + "end_line": 472, + "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": 19, + "parameters": [ + "arr", + "mask", + "vals" + ], + "start_line": 474, + "end_line": 479, + "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": 48, + "parameters": [ + "a", + "axis" + ], + "start_line": 481, + "end_line": 487, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 489, + "end_line": 495, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 497, + "end_line": 503, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 505, + "end_line": 511, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 513, + "end_line": 519, + "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": 521, + "end_line": 533, + "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": 25, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self", + "pyfunc", + "otypes", + "doc" + ], + "start_line": 566, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "function_base.py", + "nloc": 27, + "complexity": 13, + "token_count": 256, + "parameters": [ + "self", + "args" + ], + "start_line": 593, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "cov", + "long_name": "cov( m , y = None , rowvar = 1 , bias = 0 )", + "filename": "function_base.py", + "nloc": 26, + "complexity": 7, + "token_count": 207, + "parameters": [ + "m", + "y", + "rowvar", + "bias" + ], + "start_line": 625, + "end_line": 671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "corrcoef", + "long_name": "corrcoef( x , y = None )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 38, + "parameters": [ + "x", + "y" + ], + "start_line": 673, + "end_line": 678, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "blackman", + "long_name": "blackman( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 680, + "end_line": 684, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "bartlett", + "long_name": "bartlett( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 686, + "end_line": 690, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hanning", + "long_name": "hanning( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 692, + "end_line": 696, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hamming", + "long_name": "hamming( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 698, + "end_line": 702, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_chbevl", + "long_name": "_chbevl( x , vals )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 59, + "parameters": [ + "x", + "vals" + ], + "start_line": 765, + "end_line": 774, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_i0_1", + "long_name": "_i0_1( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 23, + "parameters": [ + "x" + ], + "start_line": 776, + "end_line": 777, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_i0_2", + "long_name": "_i0_2( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 30, + "parameters": [ + "x" + ], + "start_line": 779, + "end_line": 780, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "i0", + "long_name": "i0( x )", + "filename": "function_base.py", + "nloc": 10, + "complexity": 1, + "token_count": 81, + "parameters": [ + "x" + ], + "start_line": 782, + "end_line": 791, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "kaiser", + "long_name": "kaiser( M , beta )", + "filename": "function_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 62, + "parameters": [ + "M", + "beta" + ], + "start_line": 795, + "end_line": 803, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "sinc", + "long_name": "sinc( x )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "x" + ], + "start_line": 805, + "end_line": 809, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "msort", + "long_name": "msort( a )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a" + ], + "start_line": 811, + "end_line": 814, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "median", + "long_name": "median( m )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 75, + "parameters": [ + "m" + ], + "start_line": 816, + "end_line": 825, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "trapz", + "long_name": "trapz( y , x = None , dx = 1 . 0 , axis = - 1 )", + "filename": "function_base.py", + "nloc": 12, + "complexity": 2, + "token_count": 123, + "parameters": [ + "y", + "x", + "dx", + "axis" + ], + "start_line": 827, + "end_line": 841, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "add_newdoc", + "long_name": "add_newdoc( place , obj , doc )", + "filename": "function_base.py", + "nloc": 13, + "complexity": 6, + "token_count": 118, + "parameters": [ + "place", + "obj", + "doc" + ], + "start_line": 844, + "end_line": 856, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "corrcoef", + "long_name": "corrcoef( x , y = None )", + "filename": "function_base.py", + "nloc": 7, + "complexity": 2, + "token_count": 45, + "parameters": [ + "x", + "y" + ], + "start_line": 673, + "end_line": 681, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + } + ], + "nloc": 566, + "complexity": 141, + "token_count": 4458, + "diff_parsed": { + "added": [ + " try:", + " d = diag(c)", + " except ValueError: # scalar covariance", + " return 1" + ], + "deleted": [ + " d = diag(c)" + ] + } + } + ] + }, + { + "hash": "6eec749b27cf8787177585df601795d92f31e643", + "msg": "Add extra arguments to corrcoef.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-16T18:00:56+00:00", + "author_timezone": 0, + "committer_date": "2006-03-16T18:00:56+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "9003457feff1a215d296a300dc8e2682fa797592" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 2, + "insertions": 2, + "lines": 4, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/lib/function_base.py", + "new_path": "numpy/lib/function_base.py", + "filename": "function_base.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -670,10 +670,10 @@ def cov(m,y=None, rowvar=1, bias=0):\n else:\n return (dot(X,X.transpose().conj())/fact).squeeze()\n \n-def corrcoef(x, y=None):\n+def corrcoef(x, y=None, rowvar=1, bias=0):\n \"\"\"The correlation coefficients\n \"\"\"\n- c = cov(x, y)\n+ c = cov(x, y, rowvar, bias)\n try:\n d = diag(c)\n except ValueError: # scalar covariance\n", + "added_lines": 2, + "deleted_lines": 2, + "source_code": "\n__all__ = ['logspace', 'linspace',\n 'select', 'piecewise', 'trim_zeros',\n 'copy', 'iterable', #'base_repr', 'binary_repr',\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', 'cov', 'corrcoef', 'msort',\n 'median', 'sinc', 'hamming', 'hanning', 'bartlett', 'blackman',\n 'kaiser', 'trapz', 'i0', 'add_newdoc', 'add_docstring',\n ]\n\nimport types\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import ones, zeros, arange, concatenate, array, \\\n asarray, empty, empty_like, asanyarray\nfrom numpy.core.numeric import ScalarType, dot, where, newaxis\nfrom numpy.core.umath import pi, multiply, add, arctan2, \\\n frompyfunc, isnan, cos, less_equal, sqrt, sin, mod, exp\nfrom numpy.core.oldnumeric import ravel, nonzero, choose, \\\n typecodes, ArrayType, squeeze,\\\n sort\nfrom type_check import ScalarType\nfrom shape_base import atleast_1d\nfrom twodim_base import diag\nfrom _compiled_base import digitize, bincount, _insert, add_docstring\n\n#end Fernando's utilities\n\n\ndef linspace(start, stop, num=50, endpoint=True, retstep=False):\n \"\"\"Return evenly spaced numbers.\n\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 num = int(num)\n if num <= 0:\n return array([])\n if endpoint:\n if num == 1:\n return array([start])\n step = (stop-start)/float((num-1))\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 logspace(start,stop,num=50,endpoint=True,base=10.0):\n \"\"\"Evenly spaced numbers on a logarithmic scale.\n\n Computes int(num) evenly spaced exponents from start to stop.\n If endpoint=True, then last exponent is stop.\n Returns base**exponents.\n \"\"\"\n y = linspace(start,stop,num=num,endpoint=endpoint)\n return _nx.power(base,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 = [mi+0.0 for mi in range]\n if mn == mx:\n mn -= 0.5\n mx += 0.5\n bins = linspace(mn, mx, bins, endpoint=False)\n\n n = sort(a).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(n.shape) * 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\ndef asarray_chkfinite(a):\n \"\"\"Like asarray, but check that no NaNs or Infs are present.\n \"\"\"\n a = asarray(a)\n if (a.dtype.char 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\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 A constant may be used in funclist for a function that returns a\n constant (e.g. val and lambda x: val are equivalent in a funclist).\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 x = asanyarray(x)\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[k]\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\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.dtype.char\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.dtype.char)\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.type, _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 numpy\n >>> a = array((0, 0, 0, 1, 2, 3, 2, 1, 0))\n >>> numpy.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 _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.type, _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.type, _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.type, _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.type, _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.type, _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(object):\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 numpy arrays as inputs and returns a\n numpy 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 numpy.\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 = fcode.co_argcount\n if pyfunc.func_defaults:\n self.nin_wo_defaults = self.nin - len(pyfunc.func_defaults)\n else:\n self.nin_wo_defaults = self.nin\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 self.lastcallargs = 0\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 nargs = len(args)\n if (nargs > self.nin) or (nargs < self.nin_wo_defaults):\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]).dtype.char)\n self.otypes = ''.join(otypes)\n\n if (self.ufunc is None) or (self.lastcallargs != nargs):\n self.ufunc = frompyfunc(self.thefunc, nargs, self.nout)\n self.lastcallargs = nargs\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\ndef cov(m,y=None, rowvar=1, bias=0):\n \"\"\"Estimate the covariance matrix.\n\n If m is a vector, return the variance. For matrices return the\n covariance matrix.\n\n If y is given it is treated as an additional (set of)\n variable(s). \n\n Normalization is by (N-1) where N is the number of observations\n (unbiased estimate). If bias is 1 then normalization is by N.\n\n If rowvar is non-zero (default), then each row is a variable with\n observations in the columns, otherwise each column\n is a variable and the observations are in the rows.\n \"\"\"\n\n X = asarray(m,ndmin=2)\n if X.shape[0] == 1:\n rowvar = 1\n if rowvar:\n axis = 0\n tup = (slice(None),newaxis)\n else:\n axis = 1\n tup = (newaxis, slice(None))\n\n \n if y is not None:\n y = asarray(y,ndmin=2)\n X = concatenate((X,y),axis)\n\n X -= X.mean(axis=1-axis)[tup]\n if rowvar:\n N = X.shape[1]\n else:\n N = X.shape[0]\n\n if bias:\n fact = N*1.0\n else:\n fact = N-1.0\n\n if not rowvar:\n return (dot(X.transpose(), X.conj()) / fact).squeeze()\n else:\n return (dot(X,X.transpose().conj())/fact).squeeze()\n \ndef corrcoef(x, y=None, rowvar=1, bias=0):\n \"\"\"The correlation coefficients\n \"\"\"\n c = cov(x, y, rowvar, bias)\n try:\n d = diag(c)\n except ValueError: # scalar covariance\n return 1\n return c/sqrt(multiply.outer(d,d))\n\ndef blackman(M):\n \"\"\"blackman(M) returns the M-point Blackman window.\n \"\"\"\n n = arange(0,M)\n return 0.42-0.5*cos(2.0*pi*n/(M-1)) + 0.08*cos(4.0*pi*n/(M-1))\n\ndef bartlett(M):\n \"\"\"bartlett(M) returns the M-point Bartlett window.\n \"\"\"\n n = arange(0,M)\n return where(less_equal(n,(M-1)/2.0),2.0*n/(M-1),2.0-2.0*n/(M-1))\n\ndef hanning(M):\n \"\"\"hanning(M) returns the M-point Hanning window.\n \"\"\"\n n = arange(0,M)\n return 0.5-0.5*cos(2.0*pi*n/(M-1))\n\ndef hamming(M):\n \"\"\"hamming(M) returns the M-point Hamming window.\n \"\"\"\n n = arange(0,M)\n return 0.54-0.46*cos(2.0*pi*n/(M-1))\n\n## Code from cephes for i0\n\n_i0A = [\n-4.41534164647933937950E-18,\n 3.33079451882223809783E-17,\n-2.43127984654795469359E-16,\n 1.71539128555513303061E-15,\n-1.16853328779934516808E-14,\n 7.67618549860493561688E-14,\n-4.85644678311192946090E-13,\n 2.95505266312963983461E-12,\n-1.72682629144155570723E-11,\n 9.67580903537323691224E-11,\n-5.18979560163526290666E-10,\n 2.65982372468238665035E-9,\n-1.30002500998624804212E-8,\n 6.04699502254191894932E-8,\n-2.67079385394061173391E-7,\n 1.11738753912010371815E-6,\n-4.41673835845875056359E-6,\n 1.64484480707288970893E-5,\n-5.75419501008210370398E-5,\n 1.88502885095841655729E-4,\n-5.76375574538582365885E-4,\n 1.63947561694133579842E-3,\n-4.32430999505057594430E-3,\n 1.05464603945949983183E-2,\n-2.37374148058994688156E-2,\n 4.93052842396707084878E-2,\n-9.49010970480476444210E-2,\n 1.71620901522208775349E-1,\n-3.04682672343198398683E-1,\n 6.76795274409476084995E-1]\n\n_i0B = [\n-7.23318048787475395456E-18,\n-4.83050448594418207126E-18,\n 4.46562142029675999901E-17,\n 3.46122286769746109310E-17,\n-2.82762398051658348494E-16,\n-3.42548561967721913462E-16,\n 1.77256013305652638360E-15,\n 3.81168066935262242075E-15,\n-9.55484669882830764870E-15,\n-4.15056934728722208663E-14,\n 1.54008621752140982691E-14,\n 3.85277838274214270114E-13,\n 7.18012445138366623367E-13,\n-1.79417853150680611778E-12,\n-1.32158118404477131188E-11,\n-3.14991652796324136454E-11,\n 1.18891471078464383424E-11,\n 4.94060238822496958910E-10,\n 3.39623202570838634515E-9,\n 2.26666899049817806459E-8,\n 2.04891858946906374183E-7,\n 2.89137052083475648297E-6,\n 6.88975834691682398426E-5,\n 3.36911647825569408990E-3,\n 8.04490411014108831608E-1]\n\ndef _chbevl(x, vals):\n b0 = vals[0]\n b1 = 0.0\n\n for i in xrange(1,len(vals)):\n b2 = b1\n b1 = b0\n b0 = x*b1 - b2 + vals[i]\n\n return 0.5*(b0 - b2)\n\ndef _i0_1(x):\n return exp(x) * _chbevl(x/2.0-2, _i0A)\n\ndef _i0_2(x):\n return exp(x) * _chbevl(32.0/x - 2.0, _i0B) / sqrt(x)\n\ndef i0(x):\n x = atleast_1d(x).copy()\n y = empty_like(x)\n ind = (x<0)\n x[ind] = -x[ind]\n ind = (x<=8.0)\n y[ind] = _i0_1(x[ind])\n ind2 = ~ind\n y[ind2] = _i0_2(x[ind2])\n return y.squeeze()\n\n## End of cephes code for i0\n\ndef kaiser(M,beta):\n \"\"\"kaiser(M, beta) returns a Kaiser window of length M with shape parameter\n beta. It depends on numpy.special (in full numpy) for the modified bessel\n function i0.\n \"\"\"\n from numpy.dual import i0\n n = arange(0,M)\n alpha = (M-1)/2.0\n return i0(beta * sqrt(1-((n-alpha)/alpha)**2.0))/i0(beta)\n\ndef sinc(x):\n \"\"\"sinc(x) returns sin(pi*x)/(pi*x) at all points of array x.\n \"\"\"\n y = pi* where(x == 0, 1.0e-20, x)\n return sin(y)/y\n\ndef msort(a):\n b = array(a,copy=True)\n b.sort(0)\n return b\n\ndef median(m):\n \"\"\"median(m) returns a median of m along the first dimension of m.\n \"\"\"\n sorted = msort(m)\n if sorted.shape[0] % 2 == 1:\n return sorted[int(sorted.shape[0]/2)]\n else:\n sorted = msort(m)\n index=sorted.shape[0]/2\n return (sorted[index-1]+sorted[index])/2.0\n\ndef trapz(y, x=None, dx=1.0, axis=-1):\n \"\"\"Integrate y(x) using samples along the given axis and the composite\n trapezoidal rule. If x is None, spacing given by dx is assumed.\n \"\"\"\n y = asarray(y)\n if x is None:\n d = dx\n else:\n d = diff(x,axis=axis)\n nd = len(y.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n return add.reduce(d * (y[slice1]+y[slice2])/2.0,axis)\n\n#always succeed\ndef add_newdoc(place, obj, doc):\n try:\n new = {}\n exec 'from %s import %s' % (place, obj) in new\n if isinstance(doc, str):\n add_docstring(new[obj], doc.strip())\n elif isinstance(doc, tuple):\n add_docstring(getattr(new[obj], doc[0]), doc[1].strip())\n elif isinstance(doc, list):\n for val in doc:\n add_docstring(getattr(new[obj], val[0]), val[1].strip())\n except:\n pass\n", + "source_code_before": "\n__all__ = ['logspace', 'linspace',\n 'select', 'piecewise', 'trim_zeros',\n 'copy', 'iterable', #'base_repr', 'binary_repr',\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', 'cov', 'corrcoef', 'msort',\n 'median', 'sinc', 'hamming', 'hanning', 'bartlett', 'blackman',\n 'kaiser', 'trapz', 'i0', 'add_newdoc', 'add_docstring',\n ]\n\nimport types\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import ones, zeros, arange, concatenate, array, \\\n asarray, empty, empty_like, asanyarray\nfrom numpy.core.numeric import ScalarType, dot, where, newaxis\nfrom numpy.core.umath import pi, multiply, add, arctan2, \\\n frompyfunc, isnan, cos, less_equal, sqrt, sin, mod, exp\nfrom numpy.core.oldnumeric import ravel, nonzero, choose, \\\n typecodes, ArrayType, squeeze,\\\n sort\nfrom type_check import ScalarType\nfrom shape_base import atleast_1d\nfrom twodim_base import diag\nfrom _compiled_base import digitize, bincount, _insert, add_docstring\n\n#end Fernando's utilities\n\n\ndef linspace(start, stop, num=50, endpoint=True, retstep=False):\n \"\"\"Return evenly spaced numbers.\n\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 num = int(num)\n if num <= 0:\n return array([])\n if endpoint:\n if num == 1:\n return array([start])\n step = (stop-start)/float((num-1))\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 logspace(start,stop,num=50,endpoint=True,base=10.0):\n \"\"\"Evenly spaced numbers on a logarithmic scale.\n\n Computes int(num) evenly spaced exponents from start to stop.\n If endpoint=True, then last exponent is stop.\n Returns base**exponents.\n \"\"\"\n y = linspace(start,stop,num=num,endpoint=endpoint)\n return _nx.power(base,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 = [mi+0.0 for mi in range]\n if mn == mx:\n mn -= 0.5\n mx += 0.5\n bins = linspace(mn, mx, bins, endpoint=False)\n\n n = sort(a).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(n.shape) * 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\ndef asarray_chkfinite(a):\n \"\"\"Like asarray, but check that no NaNs or Infs are present.\n \"\"\"\n a = asarray(a)\n if (a.dtype.char 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\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 A constant may be used in funclist for a function that returns a\n constant (e.g. val and lambda x: val are equivalent in a funclist).\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 x = asanyarray(x)\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[k]\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\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.dtype.char\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.dtype.char)\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.type, _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 numpy\n >>> a = array((0, 0, 0, 1, 2, 3, 2, 1, 0))\n >>> numpy.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 _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.type, _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.type, _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.type, _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.type, _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.type, _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(object):\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 numpy arrays as inputs and returns a\n numpy 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 numpy.\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 = fcode.co_argcount\n if pyfunc.func_defaults:\n self.nin_wo_defaults = self.nin - len(pyfunc.func_defaults)\n else:\n self.nin_wo_defaults = self.nin\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 self.lastcallargs = 0\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 nargs = len(args)\n if (nargs > self.nin) or (nargs < self.nin_wo_defaults):\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]).dtype.char)\n self.otypes = ''.join(otypes)\n\n if (self.ufunc is None) or (self.lastcallargs != nargs):\n self.ufunc = frompyfunc(self.thefunc, nargs, self.nout)\n self.lastcallargs = nargs\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\ndef cov(m,y=None, rowvar=1, bias=0):\n \"\"\"Estimate the covariance matrix.\n\n If m is a vector, return the variance. For matrices return the\n covariance matrix.\n\n If y is given it is treated as an additional (set of)\n variable(s). \n\n Normalization is by (N-1) where N is the number of observations\n (unbiased estimate). If bias is 1 then normalization is by N.\n\n If rowvar is non-zero (default), then each row is a variable with\n observations in the columns, otherwise each column\n is a variable and the observations are in the rows.\n \"\"\"\n\n X = asarray(m,ndmin=2)\n if X.shape[0] == 1:\n rowvar = 1\n if rowvar:\n axis = 0\n tup = (slice(None),newaxis)\n else:\n axis = 1\n tup = (newaxis, slice(None))\n\n \n if y is not None:\n y = asarray(y,ndmin=2)\n X = concatenate((X,y),axis)\n\n X -= X.mean(axis=1-axis)[tup]\n if rowvar:\n N = X.shape[1]\n else:\n N = X.shape[0]\n\n if bias:\n fact = N*1.0\n else:\n fact = N-1.0\n\n if not rowvar:\n return (dot(X.transpose(), X.conj()) / fact).squeeze()\n else:\n return (dot(X,X.transpose().conj())/fact).squeeze()\n \ndef corrcoef(x, y=None):\n \"\"\"The correlation coefficients\n \"\"\"\n c = cov(x, y)\n try:\n d = diag(c)\n except ValueError: # scalar covariance\n return 1\n return c/sqrt(multiply.outer(d,d))\n\ndef blackman(M):\n \"\"\"blackman(M) returns the M-point Blackman window.\n \"\"\"\n n = arange(0,M)\n return 0.42-0.5*cos(2.0*pi*n/(M-1)) + 0.08*cos(4.0*pi*n/(M-1))\n\ndef bartlett(M):\n \"\"\"bartlett(M) returns the M-point Bartlett window.\n \"\"\"\n n = arange(0,M)\n return where(less_equal(n,(M-1)/2.0),2.0*n/(M-1),2.0-2.0*n/(M-1))\n\ndef hanning(M):\n \"\"\"hanning(M) returns the M-point Hanning window.\n \"\"\"\n n = arange(0,M)\n return 0.5-0.5*cos(2.0*pi*n/(M-1))\n\ndef hamming(M):\n \"\"\"hamming(M) returns the M-point Hamming window.\n \"\"\"\n n = arange(0,M)\n return 0.54-0.46*cos(2.0*pi*n/(M-1))\n\n## Code from cephes for i0\n\n_i0A = [\n-4.41534164647933937950E-18,\n 3.33079451882223809783E-17,\n-2.43127984654795469359E-16,\n 1.71539128555513303061E-15,\n-1.16853328779934516808E-14,\n 7.67618549860493561688E-14,\n-4.85644678311192946090E-13,\n 2.95505266312963983461E-12,\n-1.72682629144155570723E-11,\n 9.67580903537323691224E-11,\n-5.18979560163526290666E-10,\n 2.65982372468238665035E-9,\n-1.30002500998624804212E-8,\n 6.04699502254191894932E-8,\n-2.67079385394061173391E-7,\n 1.11738753912010371815E-6,\n-4.41673835845875056359E-6,\n 1.64484480707288970893E-5,\n-5.75419501008210370398E-5,\n 1.88502885095841655729E-4,\n-5.76375574538582365885E-4,\n 1.63947561694133579842E-3,\n-4.32430999505057594430E-3,\n 1.05464603945949983183E-2,\n-2.37374148058994688156E-2,\n 4.93052842396707084878E-2,\n-9.49010970480476444210E-2,\n 1.71620901522208775349E-1,\n-3.04682672343198398683E-1,\n 6.76795274409476084995E-1]\n\n_i0B = [\n-7.23318048787475395456E-18,\n-4.83050448594418207126E-18,\n 4.46562142029675999901E-17,\n 3.46122286769746109310E-17,\n-2.82762398051658348494E-16,\n-3.42548561967721913462E-16,\n 1.77256013305652638360E-15,\n 3.81168066935262242075E-15,\n-9.55484669882830764870E-15,\n-4.15056934728722208663E-14,\n 1.54008621752140982691E-14,\n 3.85277838274214270114E-13,\n 7.18012445138366623367E-13,\n-1.79417853150680611778E-12,\n-1.32158118404477131188E-11,\n-3.14991652796324136454E-11,\n 1.18891471078464383424E-11,\n 4.94060238822496958910E-10,\n 3.39623202570838634515E-9,\n 2.26666899049817806459E-8,\n 2.04891858946906374183E-7,\n 2.89137052083475648297E-6,\n 6.88975834691682398426E-5,\n 3.36911647825569408990E-3,\n 8.04490411014108831608E-1]\n\ndef _chbevl(x, vals):\n b0 = vals[0]\n b1 = 0.0\n\n for i in xrange(1,len(vals)):\n b2 = b1\n b1 = b0\n b0 = x*b1 - b2 + vals[i]\n\n return 0.5*(b0 - b2)\n\ndef _i0_1(x):\n return exp(x) * _chbevl(x/2.0-2, _i0A)\n\ndef _i0_2(x):\n return exp(x) * _chbevl(32.0/x - 2.0, _i0B) / sqrt(x)\n\ndef i0(x):\n x = atleast_1d(x).copy()\n y = empty_like(x)\n ind = (x<0)\n x[ind] = -x[ind]\n ind = (x<=8.0)\n y[ind] = _i0_1(x[ind])\n ind2 = ~ind\n y[ind2] = _i0_2(x[ind2])\n return y.squeeze()\n\n## End of cephes code for i0\n\ndef kaiser(M,beta):\n \"\"\"kaiser(M, beta) returns a Kaiser window of length M with shape parameter\n beta. It depends on numpy.special (in full numpy) for the modified bessel\n function i0.\n \"\"\"\n from numpy.dual import i0\n n = arange(0,M)\n alpha = (M-1)/2.0\n return i0(beta * sqrt(1-((n-alpha)/alpha)**2.0))/i0(beta)\n\ndef sinc(x):\n \"\"\"sinc(x) returns sin(pi*x)/(pi*x) at all points of array x.\n \"\"\"\n y = pi* where(x == 0, 1.0e-20, x)\n return sin(y)/y\n\ndef msort(a):\n b = array(a,copy=True)\n b.sort(0)\n return b\n\ndef median(m):\n \"\"\"median(m) returns a median of m along the first dimension of m.\n \"\"\"\n sorted = msort(m)\n if sorted.shape[0] % 2 == 1:\n return sorted[int(sorted.shape[0]/2)]\n else:\n sorted = msort(m)\n index=sorted.shape[0]/2\n return (sorted[index-1]+sorted[index])/2.0\n\ndef trapz(y, x=None, dx=1.0, axis=-1):\n \"\"\"Integrate y(x) using samples along the given axis and the composite\n trapezoidal rule. If x is None, spacing given by dx is assumed.\n \"\"\"\n y = asarray(y)\n if x is None:\n d = dx\n else:\n d = diff(x,axis=axis)\n nd = len(y.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n return add.reduce(d * (y[slice1]+y[slice2])/2.0,axis)\n\n#always succeed\ndef add_newdoc(place, obj, doc):\n try:\n new = {}\n exec 'from %s import %s' % (place, obj) in new\n if isinstance(doc, str):\n add_docstring(new[obj], doc.strip())\n elif isinstance(doc, tuple):\n add_docstring(getattr(new[obj], doc[0]), doc[1].strip())\n elif isinstance(doc, list):\n for val in doc:\n add_docstring(getattr(new[obj], val[0]), val[1].strip())\n except:\n pass\n", + "methods": [ + { + "name": "linspace", + "long_name": "linspace( start , stop , num = 50 , endpoint = True , retstep = False )", + "filename": "function_base.py", + "nloc": 15, + "complexity": 5, + "token_count": 107, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "retstep" + ], + "start_line": 31, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "logspace", + "long_name": "logspace( start , stop , num = 50 , endpoint = True , base = 10 . 0 )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 47, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "base" + ], + "start_line": 53, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 63, + "end_line": 66, + "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": 174, + "parameters": [ + "a", + "bins", + "range", + "normed" + ], + "start_line": 68, + "end_line": 87, + "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": 334, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 89, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 0 + }, + { + "name": "asarray_chkfinite", + "long_name": "asarray_chkfinite( a )", + "filename": "function_base.py", + "nloc": 6, + "complexity": 4, + "token_count": 59, + "parameters": [ + "a" + ], + "start_line": 161, + "end_line": 168, + "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": 22, + "complexity": 7, + "token_count": 172, + "parameters": [ + "x", + "condlist", + "funclist", + "args", + "kw" + ], + "start_line": 170, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "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": 226, + "end_line": 272, + "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": 274, + "end_line": 280, + "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": 282, + "end_line": 285, + "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": 329, + "parameters": [ + "f", + "varargs" + ], + "start_line": 289, + "end_line": 361, + "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": 364, + "end_line": 382, + "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": 74, + "parameters": [ + "z", + "deg" + ], + "start_line": 384, + "end_line": 398, + "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": 400, + "end_line": 415, + "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": 12, + "complexity": 4, + "token_count": 81, + "parameters": [ + "a" + ], + "start_line": 417, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 435, + "end_line": 455, + "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": 457, + "end_line": 464, + "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": 466, + "end_line": 472, + "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": 19, + "parameters": [ + "arr", + "mask", + "vals" + ], + "start_line": 474, + "end_line": 479, + "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": 48, + "parameters": [ + "a", + "axis" + ], + "start_line": 481, + "end_line": 487, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 489, + "end_line": 495, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 497, + "end_line": 503, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 505, + "end_line": 511, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 513, + "end_line": 519, + "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": 521, + "end_line": 533, + "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": 25, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self", + "pyfunc", + "otypes", + "doc" + ], + "start_line": 566, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "function_base.py", + "nloc": 27, + "complexity": 13, + "token_count": 256, + "parameters": [ + "self", + "args" + ], + "start_line": 593, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "cov", + "long_name": "cov( m , y = None , rowvar = 1 , bias = 0 )", + "filename": "function_base.py", + "nloc": 26, + "complexity": 7, + "token_count": 207, + "parameters": [ + "m", + "y", + "rowvar", + "bias" + ], + "start_line": 625, + "end_line": 671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "corrcoef", + "long_name": "corrcoef( x , y = None , rowvar = 1 , bias = 0 )", + "filename": "function_base.py", + "nloc": 7, + "complexity": 2, + "token_count": 57, + "parameters": [ + "x", + "y", + "rowvar", + "bias" + ], + "start_line": 673, + "end_line": 681, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "blackman", + "long_name": "blackman( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 683, + "end_line": 687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "bartlett", + "long_name": "bartlett( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 689, + "end_line": 693, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hanning", + "long_name": "hanning( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 695, + "end_line": 699, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hamming", + "long_name": "hamming( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 701, + "end_line": 705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_chbevl", + "long_name": "_chbevl( x , vals )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 59, + "parameters": [ + "x", + "vals" + ], + "start_line": 768, + "end_line": 777, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_i0_1", + "long_name": "_i0_1( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 23, + "parameters": [ + "x" + ], + "start_line": 779, + "end_line": 780, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_i0_2", + "long_name": "_i0_2( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 30, + "parameters": [ + "x" + ], + "start_line": 782, + "end_line": 783, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "i0", + "long_name": "i0( x )", + "filename": "function_base.py", + "nloc": 10, + "complexity": 1, + "token_count": 81, + "parameters": [ + "x" + ], + "start_line": 785, + "end_line": 794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "kaiser", + "long_name": "kaiser( M , beta )", + "filename": "function_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 62, + "parameters": [ + "M", + "beta" + ], + "start_line": 798, + "end_line": 806, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "sinc", + "long_name": "sinc( x )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "x" + ], + "start_line": 808, + "end_line": 812, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "msort", + "long_name": "msort( a )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a" + ], + "start_line": 814, + "end_line": 817, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "median", + "long_name": "median( m )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 75, + "parameters": [ + "m" + ], + "start_line": 819, + "end_line": 828, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "trapz", + "long_name": "trapz( y , x = None , dx = 1 . 0 , axis = - 1 )", + "filename": "function_base.py", + "nloc": 12, + "complexity": 2, + "token_count": 123, + "parameters": [ + "y", + "x", + "dx", + "axis" + ], + "start_line": 830, + "end_line": 844, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "add_newdoc", + "long_name": "add_newdoc( place , obj , doc )", + "filename": "function_base.py", + "nloc": 13, + "complexity": 6, + "token_count": 118, + "parameters": [ + "place", + "obj", + "doc" + ], + "start_line": 847, + "end_line": 859, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "linspace", + "long_name": "linspace( start , stop , num = 50 , endpoint = True , retstep = False )", + "filename": "function_base.py", + "nloc": 15, + "complexity": 5, + "token_count": 107, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "retstep" + ], + "start_line": 31, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "logspace", + "long_name": "logspace( start , stop , num = 50 , endpoint = True , base = 10 . 0 )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 47, + "parameters": [ + "start", + "stop", + "num", + "endpoint", + "base" + ], + "start_line": 53, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 63, + "end_line": 66, + "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": 174, + "parameters": [ + "a", + "bins", + "range", + "normed" + ], + "start_line": 68, + "end_line": 87, + "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": 334, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 89, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 0 + }, + { + "name": "asarray_chkfinite", + "long_name": "asarray_chkfinite( a )", + "filename": "function_base.py", + "nloc": 6, + "complexity": 4, + "token_count": 59, + "parameters": [ + "a" + ], + "start_line": 161, + "end_line": 168, + "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": 22, + "complexity": 7, + "token_count": 172, + "parameters": [ + "x", + "condlist", + "funclist", + "args", + "kw" + ], + "start_line": 170, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "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": 226, + "end_line": 272, + "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": 274, + "end_line": 280, + "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": 282, + "end_line": 285, + "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": 329, + "parameters": [ + "f", + "varargs" + ], + "start_line": 289, + "end_line": 361, + "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": 364, + "end_line": 382, + "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": 74, + "parameters": [ + "z", + "deg" + ], + "start_line": 384, + "end_line": 398, + "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": 400, + "end_line": 415, + "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": 12, + "complexity": 4, + "token_count": 81, + "parameters": [ + "a" + ], + "start_line": 417, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 435, + "end_line": 455, + "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": 457, + "end_line": 464, + "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": 466, + "end_line": 472, + "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": 19, + "parameters": [ + "arr", + "mask", + "vals" + ], + "start_line": 474, + "end_line": 479, + "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": 48, + "parameters": [ + "a", + "axis" + ], + "start_line": 481, + "end_line": 487, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 489, + "end_line": 495, + "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": 50, + "parameters": [ + "a", + "axis" + ], + "start_line": 497, + "end_line": 503, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 505, + "end_line": 511, + "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": 51, + "parameters": [ + "a", + "axis" + ], + "start_line": 513, + "end_line": 519, + "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": 521, + "end_line": 533, + "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": 25, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self", + "pyfunc", + "otypes", + "doc" + ], + "start_line": 566, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "function_base.py", + "nloc": 27, + "complexity": 13, + "token_count": 256, + "parameters": [ + "self", + "args" + ], + "start_line": 593, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "cov", + "long_name": "cov( m , y = None , rowvar = 1 , bias = 0 )", + "filename": "function_base.py", + "nloc": 26, + "complexity": 7, + "token_count": 207, + "parameters": [ + "m", + "y", + "rowvar", + "bias" + ], + "start_line": 625, + "end_line": 671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "corrcoef", + "long_name": "corrcoef( x , y = None )", + "filename": "function_base.py", + "nloc": 7, + "complexity": 2, + "token_count": 45, + "parameters": [ + "x", + "y" + ], + "start_line": 673, + "end_line": 681, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "blackman", + "long_name": "blackman( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 683, + "end_line": 687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "bartlett", + "long_name": "bartlett( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 60, + "parameters": [ + "M" + ], + "start_line": 689, + "end_line": 693, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hanning", + "long_name": "hanning( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 695, + "end_line": 699, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "hamming", + "long_name": "hamming( M )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "M" + ], + "start_line": 701, + "end_line": 705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_chbevl", + "long_name": "_chbevl( x , vals )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 59, + "parameters": [ + "x", + "vals" + ], + "start_line": 768, + "end_line": 777, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_i0_1", + "long_name": "_i0_1( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 23, + "parameters": [ + "x" + ], + "start_line": 779, + "end_line": 780, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_i0_2", + "long_name": "_i0_2( x )", + "filename": "function_base.py", + "nloc": 2, + "complexity": 1, + "token_count": 30, + "parameters": [ + "x" + ], + "start_line": 782, + "end_line": 783, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "i0", + "long_name": "i0( x )", + "filename": "function_base.py", + "nloc": 10, + "complexity": 1, + "token_count": 81, + "parameters": [ + "x" + ], + "start_line": 785, + "end_line": 794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "kaiser", + "long_name": "kaiser( M , beta )", + "filename": "function_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 62, + "parameters": [ + "M", + "beta" + ], + "start_line": 798, + "end_line": 806, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "sinc", + "long_name": "sinc( x )", + "filename": "function_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "x" + ], + "start_line": 808, + "end_line": 812, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "msort", + "long_name": "msort( a )", + "filename": "function_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a" + ], + "start_line": 814, + "end_line": 817, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "median", + "long_name": "median( m )", + "filename": "function_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 75, + "parameters": [ + "m" + ], + "start_line": 819, + "end_line": 828, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "trapz", + "long_name": "trapz( y , x = None , dx = 1 . 0 , axis = - 1 )", + "filename": "function_base.py", + "nloc": 12, + "complexity": 2, + "token_count": 123, + "parameters": [ + "y", + "x", + "dx", + "axis" + ], + "start_line": 830, + "end_line": 844, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "add_newdoc", + "long_name": "add_newdoc( place , obj , doc )", + "filename": "function_base.py", + "nloc": 13, + "complexity": 6, + "token_count": 118, + "parameters": [ + "place", + "obj", + "doc" + ], + "start_line": 847, + "end_line": 859, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "corrcoef", + "long_name": "corrcoef( x , y = None )", + "filename": "function_base.py", + "nloc": 7, + "complexity": 2, + "token_count": 45, + "parameters": [ + "x", + "y" + ], + "start_line": 673, + "end_line": 681, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "corrcoef", + "long_name": "corrcoef( x , y = None , rowvar = 1 , bias = 0 )", + "filename": "function_base.py", + "nloc": 7, + "complexity": 2, + "token_count": 57, + "parameters": [ + "x", + "y", + "rowvar", + "bias" + ], + "start_line": 673, + "end_line": 681, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + } + ], + "nloc": 566, + "complexity": 141, + "token_count": 4470, + "diff_parsed": { + "added": [ + "def corrcoef(x, y=None, rowvar=1, bias=0):", + " c = cov(x, y, rowvar, bias)" + ], + "deleted": [ + "def corrcoef(x, y=None):", + " c = cov(x, y)" + ] + } + } + ] + }, + { + "hash": "178049619a9ae83860977e8cec27ecb281569a28", + "msg": "Comments only.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-17T00:56:39+00:00", + "author_timezone": 0, + "committer_date": "2006-03-17T00:56:39+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "6eec749b27cf8787177585df601795d92f31e643" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 1, + "insertions": 14, + "lines": 15, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -1,3 +1,5 @@\n+/* -*- c -*- */\n+\n /* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n \n@@ -10,8 +12,19 @@\n #include \"numpy/ufuncobject.h\"\n \n \n-/**end repeat**/\n+/* The general strategy is to\n+\n+1) Check to see if it's a scalar of the same type and do \n+ a quick exit. \n+2) Check to see if it's a Python scalar and do a\n+ quick exit.\n+3) Check to see if it's another array scalar, and cast it\n+ and exit\n+4) Check to see if it's a 0-d array and convert it \n+ and exit.\n+5) Go through the ufunc machinery for all other cases. \n \n+*/\n \n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n", + "added_lines": 14, + "deleted_lines": 1, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n */\n\n#include \"numpy/arrayobject.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n/* The general strategy is to\n\n1) Check to see if it's a scalar of the same type and do \n a quick exit. \n2) Check to see if it's a Python scalar and do a\n quick exit.\n3) Check to see if it's another array scalar, and cast it\n and exit\n4) Check to see if it's a 0-d array and convert it \n and exit.\n5) Go through the ufunc machinery for all other cases. \n\n*/\n\n/**begin repeat\n#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n\nstatic PyObject *\n@name@_add(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_subtract(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_multiply(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_divide(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_remainder(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_divmod(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_negative(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_copy(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_absolute(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_nonzero_number(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_invert(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_lshift(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_rshift(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_and(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_xor(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_or(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_int(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_long(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_float(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_oct(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_hex(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_floor_divide(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_true_divide(PyObject *a, PyObject *b)\n{\n}\n\n#if PY_VERSION_HEX >= 0x02050000\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n}\n#endif\n\n\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n}\n/**end repeat**/\n\n\n\n\n/**begin repeat\n#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_copy, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero_number, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n\t(lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n\nstatic void\nadd_scalarmath(void)\n{\n/**begin repeat\n#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n**/\n\tPyArr@NAME@Type_Type.tp_as_number = @name@_as_number;\n\tPyArr@NAME@Type_Type.tp_richcompare = @name@_richcompare;\n/**end repeat**/\n}\n\n\n\nstatic struct PyMethodDef methods[] = {\n\t{\"alter_pyscalars\", (PyCFunction) alter_pyscalars,\n\t METH_VARARGS , doc_alterpyscalars},\n\t{NULL, NULL, 0}\n};\n\nDL_EXPORT(void) initscalarmath(void) {\n\tPyObject *m;\n\n\tm = Py_initModule(\"scalarmath\", methods);\n\t\n\tif (import_array() < 0) return;\n\tif (import_umath() < 0) return;\n\n\tadd_scalarmath();\n\t\n\treturn;\n}\n", + "source_code_before": "/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n */\n\n#include \"numpy/arrayobject.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n/**end repeat**/\n\n\n/**begin repeat\n#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n\nstatic PyObject *\n@name@_add(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_subtract(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_multiply(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_divide(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_remainder(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_divmod(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_negative(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_copy(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_absolute(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_nonzero_number(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_invert(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_lshift(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_rshift(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_and(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_xor(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_or(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_int(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_long(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_float(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_oct(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_hex(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_floor_divide(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_true_divide(PyObject *a, PyObject *b)\n{\n}\n\n#if PY_VERSION_HEX >= 0x02050000\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n}\n#endif\n\n\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n}\n/**end repeat**/\n\n\n\n\n/**begin repeat\n#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_copy, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero_number, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n\t(lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n\nstatic void\nadd_scalarmath(void)\n{\n/**begin repeat\n#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n**/\n\tPyArr@NAME@Type_Type.tp_as_number = @name@_as_number;\n\tPyArr@NAME@Type_Type.tp_richcompare = @name@_richcompare;\n/**end repeat**/\n}\n\n\n\nstatic struct PyMethodDef methods[] = {\n\t{\"alter_pyscalars\", (PyCFunction) alter_pyscalars,\n\t METH_VARARGS , doc_alterpyscalars},\n\t{NULL, NULL, 0}\n};\n\nDL_EXPORT(void) initscalarmath(void) {\n\tPyObject *m;\n\n\tm = Py_initModule(\"scalarmath\", methods);\n\t\n\tif (import_array() < 0) return;\n\tif (import_umath() < 0) return;\n\n\tadd_scalarmath();\n\t\n\treturn;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "/* -*- c -*- */", + "", + "/* The general strategy is to", + "", + "1) Check to see if it's a scalar of the same type and do", + " a quick exit.", + "2) Check to see if it's a Python scalar and do a", + " quick exit.", + "3) Check to see if it's another array scalar, and cast it", + " and exit", + "4) Check to see if it's a 0-d array and convert it", + " and exit.", + "5) Go through the ufunc machinery for all other cases.", + "*/" + ], + "deleted": [ + "/**end repeat**/" + ] + } + } + ] + }, + { + "hash": "116482559bc3a3856022b0a7b25429605d351c02", + "msg": "Add coercion test for scalar objects.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-17T09:48:17+00:00", + "author_timezone": 0, + "committer_date": "2006-03-17T09:48:17+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "178049619a9ae83860977e8cec27ecb281569a28" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 8, + "insertions": 28, + "lines": 36, + "files": 3, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/core/code_generators/array_api_order.txt", + "new_path": "numpy/core/code_generators/array_api_order.txt", + "filename": "array_api_order.txt", + "extension": "txt", + "change_type": "MODIFY", + "diff": "@@ -68,3 +68,4 @@ PyArray_FromArrayAttr\n PyArray_ScalarKind\n PyArray_CanCoerceScalar\n PyArray_NewFlagsObject\n+PyArray_CanCastScalar\n", + "added_lines": 1, + "deleted_lines": 0, + "source_code": "# The functions in the numpy_core C API\n# They are defined here so that the order is set.\nPyArray_SetNumericOps\nPyArray_GetNumericOps\nPyArray_INCREF\nPyArray_XDECREF\nPyArray_SetStringFunction\nPyArray_DescrFromType\nPyArray_TypeObjectFromType\nPyArray_Zero\nPyArray_One\nPyArray_CastToType\nPyArray_CastTo\nPyArray_CanCastSafely\nPyArray_CanCastTo\nPyArray_ObjectType\nPyArray_DescrFromObject\nPyArray_ConvertToCommonType\nPyArray_DescrFromScalar\nPyArray_Size\nPyArray_Scalar\nPyArray_ToScalar\nPyArray_FromScalar\nPyArray_ScalarAsCtype\nPyArray_CastScalarToCtype\nPyArray_RegisterDataType\nPyArray_RegisterDescrForType\nPyArray_FromDims\nPyArray_FromDimsAndDataAndDescr\nPyArray_FromAny\nPyArray_EnsureArray\nPyArray_FromFile\nPyArray_FromString\nPyArray_FromBuffer\nPyArray_Return\nPyArray_GetField\nPyArray_SetField\nPyArray_Byteswap\nPyArray_Resize\nPyArray_NewCopy\nPyArray_CopyInto\nPyArray_ToList\nPyArray_ToFile\nPyArray_Dump\nPyArray_Dumps\nPyArray_ValidType\nPyArray_UpdateFlags\nPyArray_New\nPyArray_NewFromDescr\nPyArray_DescrNew\nPyArray_DescrNewFromType\nPyArray_GetPriority\nPyArray_IterNew\nPyArray_MultiIterNew\nPyArray_PyIntAsInt\nPyArray_PyIntAsIntp\nPyArray_Broadcast\nPyArray_FillObjectArray\nPyArray_FillWithScalar\nPyArray_CheckStrides\nPyArray_DescrNewByteorder\nPyArray_IterAllButAxis\nPyArray_CheckFromAny\nPyArray_FromArray\nPyArray_FromInterface\nPyArray_FromStructInterface\nPyArray_FromArrayAttr\nPyArray_ScalarKind\nPyArray_CanCoerceScalar\nPyArray_NewFlagsObject\nPyArray_CanCastScalar\n", + "source_code_before": "# The functions in the numpy_core C API\n# They are defined here so that the order is set.\nPyArray_SetNumericOps\nPyArray_GetNumericOps\nPyArray_INCREF\nPyArray_XDECREF\nPyArray_SetStringFunction\nPyArray_DescrFromType\nPyArray_TypeObjectFromType\nPyArray_Zero\nPyArray_One\nPyArray_CastToType\nPyArray_CastTo\nPyArray_CanCastSafely\nPyArray_CanCastTo\nPyArray_ObjectType\nPyArray_DescrFromObject\nPyArray_ConvertToCommonType\nPyArray_DescrFromScalar\nPyArray_Size\nPyArray_Scalar\nPyArray_ToScalar\nPyArray_FromScalar\nPyArray_ScalarAsCtype\nPyArray_CastScalarToCtype\nPyArray_RegisterDataType\nPyArray_RegisterDescrForType\nPyArray_FromDims\nPyArray_FromDimsAndDataAndDescr\nPyArray_FromAny\nPyArray_EnsureArray\nPyArray_FromFile\nPyArray_FromString\nPyArray_FromBuffer\nPyArray_Return\nPyArray_GetField\nPyArray_SetField\nPyArray_Byteswap\nPyArray_Resize\nPyArray_NewCopy\nPyArray_CopyInto\nPyArray_ToList\nPyArray_ToFile\nPyArray_Dump\nPyArray_Dumps\nPyArray_ValidType\nPyArray_UpdateFlags\nPyArray_New\nPyArray_NewFromDescr\nPyArray_DescrNew\nPyArray_DescrNewFromType\nPyArray_GetPriority\nPyArray_IterNew\nPyArray_MultiIterNew\nPyArray_PyIntAsInt\nPyArray_PyIntAsIntp\nPyArray_Broadcast\nPyArray_FillObjectArray\nPyArray_FillWithScalar\nPyArray_CheckStrides\nPyArray_DescrNewByteorder\nPyArray_IterAllButAxis\nPyArray_CheckFromAny\nPyArray_FromArray\nPyArray_FromInterface\nPyArray_FromStructInterface\nPyArray_FromArrayAttr\nPyArray_ScalarKind\nPyArray_CanCoerceScalar\nPyArray_NewFlagsObject\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "PyArray_CanCastScalar" + ], + "deleted": [] + } + }, + { + "old_path": "numpy/core/src/arrayobject.c", + "new_path": "numpy/core/src/arrayobject.c", + "filename": "arrayobject.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -6711,6 +6711,21 @@ PyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n \treturn ret;\n }\n \n+/*OBJECT_API\n+ See if array scalars can be cast.\n+ */\n+static Bool\n+PyArray_CanCastScalar(PyTypeObject *from, PyTypeObject *to)\n+{\n+\tint fromtype;\n+\tint totype;\n+\n+\tfromtype = _typenum_fromtypeobj((PyObject *)from, 0);\n+\ttotype = _typenum_fromtypeobj((PyObject *)to, 0);\n+\tif (fromtype == PyArray_NOTYPE || totype == PyArray_NOTYPE) \n+\t\treturn FALSE;\n+\treturn (Bool) PyArray_CanCastSafely(fromtype, totype);\t\n+}\n \n \n /*********************** Element-wise Array Iterator ***********************/\n", + "added_lines": 15, + "deleted_lines": 0, + "source_code": "/*\n Provide multidimensional arrays as a basic object type in python.\n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004\n\nHeavily modified in 2005 with inspiration from Numarray\n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University\n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by\nSpace Science Telescope Institute\n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_)\n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear();\n priority = default_;\n }\n Py_XDECREF(ret);\n return priority;\n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a\n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n }\n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int\ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides,\n\t intp *src_dimensions, int src_nd, int elsize,\n\t int copies) {\n intp i, j;\n\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1,\n dest_dimensions+1, dest_nd-1,\n src, src_strides,\n src_dimensions, src_nd,\n elsize, copies) == -1)\n return -1;\n }\n return 0;\n }\n\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError,\n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) &&\n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] !=\n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src)\n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\n dest_strides_ptr = dest_strides;\n\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1)\n return NULL;\n\n new_data = (char *)_pya_malloc(stride);\n\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions,\n dest_nd, src->data, src_strides,\n src_dimensions, src_nd, elsize, copies);\n\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *,\n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int\nPyArray_INCREF(PyArrayObject *mp)\n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap)\n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n\n\n if ((numitems == 1) || (itemsize == srcstrides))\n memcpy(d1, s1, itemsize*numitems);\n else {\n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n }\n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG\n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i)\n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp\nPyArray_Size(PyObject *op)\n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n }\n\telse {\n return 0;\n }\n}\n\n/* If destination is not the right type, then src\n will be cast to destination.\n*/\n\n/* Does a flat iterator-based copy.\n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however.\n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n\n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError,\n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n\n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, elsize);\n PyArray_INCREF(dest);\n return 0;\n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n }\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int\nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)\n{\n PyArrayObject *src;\n int ret;\n\t\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d,\n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t} \n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,\n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd,\n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran,\n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\n return (PyObject *)ret;\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) {\n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED;\n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=0;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use\n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifndef Py_UNICODE_WIDE\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\treturn obj;\n#endif\n\t\t}\n\t\telse {\n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, itemsize);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this.\n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag\n*/\n\n/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp)\n{\n\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n\n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int\nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs,\n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/*\n copyies over from the old descr table for anything\n NULL or zero in what is given.\n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)\n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data,\n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError,\n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr,\n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element\"\\\n \" %d to file\",\n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj);\n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj),\n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\",\n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1)\n fwrite(sep, 1, n3, fp);\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self)\n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0)\n\t\treturn self->descr->f->getitem(self->data,self);\n\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n\n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void\narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an\n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE\n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n\n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\narray_length(PyArrayObject *self)\n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i)\n{\n\tchar *item;\n\tPyArrayObject *r;\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1,\n\t\t\t\t\t\t self->dimensions+1,\n\t\t\t\t\t\t self->strides+1, item,\n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\nstatic PyObject *\narray_item_nice(PyArrayObject *self, _int_or_ssize_t i)\n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\n\nstatic int\narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v)\n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret;\n }\n\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if PY_VERSION_HEX < 0x02050000\n #if SIZEOF_INT == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#else\n #if SIZEOF_SIZE_T == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#endif\n#ifndef array_ass_item\nstatic int\narray_ass_item(PyArrayObject *self, _int_or_ssize_t i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int\nparse_index(PyArrayObject *self, PyObject *op,\n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError,\n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\n nd_old = nd_new = 0;\n\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n\t/* tuple for transpose is\n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of\n\t the broadcasted index array\n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the\n\t result\n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2)\n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call.\n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type,\n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret))\n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, PyArray_ITEMSIZE(arr));\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS];\n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL)\n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0\n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from\n Python when using a[object] unless object is a standard slice object\n (not an extended one).\n\n*/\n\n/* There are two situations:\n\n 1 - the subscript is a standard view and a reference to the\n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned.\n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *);\n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op)\n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr,\n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis) {\n\t\t\t/* XXX: This leads to a small inconsistency\n\t\t\t XXX: with the nd>0 case where (x[...] is x)\n\t\t\t XXX: is false for nd>0 case. */\n\t\t\tPy_INCREF(self);\n\t\t\treturn (PyObject *)self;\n\t\t}\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op)) {\n\t\t\t\tPy_INCREF(self);\n\t\t\t\treturn (PyObject *)self;\n\t\t\t}\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset))\n == -1)\n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset,\n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL)\n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be\n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *);\n\nstatic int\narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)\n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr,\n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1;\n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to\n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op)\n{\n\t/* The following is just a copy of PyArray_Return with an\n\t additional logic in the nd == 0 case. More efficient\n\t implementation may be possible by refactoring\n\t array_subscript */\n\n\tPyArrayObject *mp = (PyArrayObject *)array_subscript(self, op);\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tBool noellipses = TRUE;\n\t\tif (op == Py_Ellipsis)\n\t\t\tnoellipses = FALSE;\n\t\telse if (PySequence_Check(op)) {\n\t\t\tint n, i;\n\t\t\tn = PySequence_Size(op);\n\t\t\tfor (i = 0; i < n; ++i) \n\t\t\t\tif (PySequence_GetItem(op, i) == Py_Ellipsis) {\n\t\t\t\t\tnoellipses = FALSE;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t\tif (noellipses) {\n\t\t\tPyObject *ret;\n\t\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\t\tPy_DECREF(mp);\n\t\t\treturn ret;\n\t\t}\n\t}\n\treturn (PyObject *)mp;\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t /*mp_length*/\n#else\n (inquiry)array_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic _int_or_ssize_t\narray_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp)\n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic _int_or_ssize_t\narray_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"accessing non-existing array segment\");\n return -1;\n }\n\n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic _int_or_ssize_t\narray_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (PyArray_CHKFLAGS(self, WRITEABLE))\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic _int_or_ssize_t\narray_getcharbuf(PyArrayObject *self, _int_or_ssize_t segment, const char **ptrptr)\n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError,\n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (writebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (segcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (charbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#else\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#endif\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n *square,\n *reciprocal,\n *ones_like,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum,\n\t\t*rint;\n} NumericOps;\n\nstatic NumericOps n_ops; /* NB: static objects inlitialized to zero */\n\n/* Dictionary can contain any of the numeric operations, by name.\n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n\n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint\nPyArray_SetNumericOps(PyObject *dict)\n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n SET(square);\n SET(reciprocal);\n SET(ones_like);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\n SET(true_divide);\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n\tSET(rint);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void)\n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL)\n\t\treturn NULL;\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n GET(square);\n GET(reciprocal);\n GET(ones_like);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide);\n GET(true_divide);\n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\tGET(rint);\n\treturn dict;\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,\n\t\t\t\t PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2)\n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\n\nstatic PyObject *array_float(PyArrayObject *v);\n\n\nstatic int\narray_power_is_scalar(PyObject *o2, double* exp)\n{\n PyObject *temp;\n const int optimize_fpexps = 1;\n if (PyInt_Check(o2)) {\n *exp = (double)PyInt_AsLong(o2);\n return 1;\n }\n if (optimize_fpexps && PyFloat_Check(o2)) {\n *exp = PyFloat_AsDouble(o2);\n return 1;\n }\n if (PyArray_CheckScalar(o2)) {\n if (PyArray_ISINTEGER(o2) || (optimize_fpexps && PyArray_ISFLOAT(o2))) {\n temp = array_float((PyArrayObject *)o2);\n if (temp != NULL) {\n *exp = PyFloat_AsDouble(o2);\n Py_DECREF(temp);\n return 1;\n }\n }\n }\n return 0;\n}\n\n/* optimize float array or complex array to a scalar power */\nstatic PyObject *\nfast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) {\n double exp;\n if (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) || PyArray_ISCOMPLEX(a1))) {\n if (array_power_is_scalar(o2, &exp)) {\n PyObject *fastop = NULL;\n if (exp == 1.0) {\n /* we have to do this one special, as the \"copy\" method of\n array objects isn't set up early enough to be added\n by PyArray_SetNumericOps.\n */\n if (inplace) {\n return (PyObject *)a1;\n } else {\n return PyArray_Copy(a1);\n }\n } else if (exp == -1.0) {\n fastop = n_ops.reciprocal;\n } else if (exp == 0.0) {\n fastop = n_ops.ones_like;\n } else if (exp == 0.5) {\n fastop = n_ops.sqrt;\n } else if (exp == 2.0) {\n fastop = n_ops.square;\n } else {\n return NULL;\n }\n if (inplace) {\n PyArray_GenericInplaceUnaryFunction(a1, fastop);\n } else {\n return PyArray_GenericUnaryFunction(a1, fastop);\n }\n }\n }\n return NULL;\n}\n\nstatic PyObject *\narray_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 0);\n if (!value) {\n value = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\n\nstatic PyObject *\narray_negative(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 1);\n if (!value) {\n value = PyArray_GenericInplaceBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int\narray_any_nonzero(PyArrayObject *mp)\n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2)\n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_float(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to a \"\\\n\t\t\t\t\"float; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_long(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/\n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected\n*/\n\n\nstatic PyObject *\narray_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t _int_or_ssize_t ihigh)\n{\n PyArrayObject *r;\n _int_or_ssize_t l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n self->dimensions[0] = l;\n\tif (r == NULL) return NULL;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS);\n return (PyObject *)r;\n}\n\n\nstatic int\narray_ass_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t\t_int_or_ssize_t ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res;\n int ret;\n\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\nstatic PySequenceMethods array_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (ssizeargfunc)NULL,\n\t(ssizeargfunc)array_item_nice,\n\t(ssizessizeargfunc)array_slice,\n (ssizeobjargproc)array_ass_item,\t /*sq_ass_item*/\n (ssizessizeobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(ssizeargfunc)NULL,\n#else\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t /*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n#endif\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int\ndump_data(char **string, int *n, int *max_n, char *data, int nd,\n intp *dimensions, intp *strides, PyArrayObject* self)\n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\n if (nd == 0) {\n\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata,\n\t\t self->nd, self->dimensions,\n self->strides, self) < 0) {\n\t\t_pya_free(string); return NULL;\n\t}\n\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void\nPyArray_SetStringFunction(PyObject *op, int repr)\n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_ReprFunction = op;\n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_StrFunction = op;\n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)\n{\n PyObject *array_other, *result;\n\tint typenum;\n\n switch (cmp_op)\n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then return False\n\t\t\t\t This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of False\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the\n\t\t\t two array objects can not be compared together so\n\t\t\t return zero\n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be\n\t\t\t\t compared and cannot be equal, therefore,\n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t other,\n\t\t\t\t\t\t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL,\n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int\n_IsFortranContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap)\n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object\n\t If it is a writeable array, then return TRUE\n\t If we can find an array object\n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable\n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA))\n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly\n\t and unpickled array can be set and reset writeable\n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t\telse ret->flags &= ~WRITEABLE;\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not\n ever be able to walk outside of the memory implied numbytes and offset.\n\n The available memory is assumed to start at -offset and proceed\n to numbytes-offset. The strides are checked to ensure\n that accessing memory using striding will not try to reach beyond\n this memory for any of the axes.\n\n If numbytes is 0 it will be calculated using the dimensions and\n element-size.\n\n This function checks for walking beyond the beginning and right-end\n of the buffer and therefore works for any integer stride (positive\n or negative).\n*/\n\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\tintp byte_begin;\n\tintp begin;\n\tintp end;\n\n\tif (numbytes == 0)\n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\n\tbegin = -offset;\n\tend = numbytes - offset - elsize;\n\tfor (i=0; i end))\n\t\t\treturn FALSE;\n\t}\n\treturn TRUE;\n\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings\n depending on data and strides:\n\n If data is given, then flags is flags associated with data.\n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument\n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set).\n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired.\n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize,\n\t\t int inflag, int *objflags)\n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\n/* and update the dimensions and strides\n appropriately. Dimensions and strides are added\n to the end unless we have a FORTRAN array\n and then they are added to the beginning\n\n Strides are only added if given (because data is given).\n*/\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,\n\t\t\t intp *newstrides, int oldnd, int isfortran)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\tint tuple;\n\n\told = *des;\n\t*des = old->subarray->base;\n\n\n\tmydim = newdims + oldnd;\n\ttuple = PyTuple_Check(old->subarray->shape);\n\tif (tuple) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t}\n\telse {\n\t\tnumnew = 1;\n\t}\n\n\n\tnewnd = oldnd + numnew;\n\tif (newnd > MAX_DIMS) goto finish;\n\tif (isfortran) {\n\t\tmemmove(newdims+numnew, newdims, oldnd*sizeof(intp));\n\t\tmydim = newdims;\n\t}\n\n\tif (tuple) {\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\tif (isfortran) {\n\t\t\tmemmove(newstrides+numnew, newstrides,\n\t\t\t\toldnd*sizeof(intp));\n\t\t\tmystrides = newstrides;\n\t\t}\n\t\t/* Make new strides -- alwasy C-contiguous */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\n finish:\n\tPy_INCREF(*des);\n\tPy_DECREF(old);\n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,\n\t\t intp *dims, intp *strides, void *data,\n\t\t int flags, PyObject *obj)\n{\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tint isfortran=0;\n\t\tisfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || \\\n\t\t\t(!data && flags);\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims,\n\t\t\t\t\t\t newstrides, nd, isfortran);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims,\n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { \n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN;\n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse { /* we allow strides even when we create\n\t\t\t the memory, but be careful with this...\n\t\t */\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays\n\t\t e.g. shape=(0,) -- otherwise buffer exposure\n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in,\n\t\t\t\t\t this object won't own it\n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for\n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype.\n\t If obj is NULL, then call method with Py_None \n\t*/\n\tif ((subtype != &PyArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (strides != NULL) { /* did not allocate own data \n\t\t\t\t\t or funny strides */\n\t\t\t/* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tif (obj == NULL) obj=Py_None;\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n If refcheck is 0, then the reference count is not checked\n and assumed to be 1.\n You still must own this data and have no weak-references and no base\n object.\n*/\nstatic PyObject *\nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\n if (!PyArray_ISONESEGMENT(self)) {\n PyErr_SetString(PyExc_ValueError,\n \"resize only works on single-segment arrays\");\n return NULL;\n }\n\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n\n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (refcheck) refcnt = REFCOUNT(self);\n\t\telse refcnt = 1;\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (newsize == 0) sd = self->descr->elsize;\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n\n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) {\n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0,\n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n\n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n\n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n self->flags, &(self->flags));\n\n\n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\n return Py_None;\n\n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\tPyArray_FillWithScalarFunc* fillwithscalar =\n\t\t\tarr->descr->f->fillwithscalar;\n\t\tif (fillwithscalar && PyArray_ISALIGNED(arr)) {\n\t\t\tcopyswap(fromptr, NULL, swap, itemsize);\n\t\t\tfillwithscalar(toptr, size, fromptr, arr);\n\t\t}\n\t\telse {\n\t\t\twhile (size--) {\n\t\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\t\ttoptr += itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL;\n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous\n\t array of a specific type and shape.\n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims,\n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter,\n &strides,\n &fortran))\n\t\tgoto fail;\n\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"data-type with unspecified variable length\");\n\t\tgoto fail;\n\t}\n\t\n\tif (strides.ptr != NULL) {\n\t\tintp nb, off;\n\t\tif (strides.len != dims.len) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides, if given, must be \"\t\\\n\t\t\t\t\t\"the same length as shape\");\n\t\t\tgoto fail;\n\t\t}\n\n\t\tif (buffer.ptr == NULL) {\n\t\t\tnb = 0;\n\t\t\toff = 0;\n\t\t}\n\t\telse {\n\t\t\tnb = buffer.len;\n\t\t\toff = offset;\n\t\t}\n\t\t\n\n\t\tif (!PyArray_CheckStrides(itemsize, dims.len, \n\t\t\t\t\t nb, off,\n\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides is incompatible \"\t\\\n\t\t\t\t\t\"with shape of requested \"\t\\\n\t\t\t\t\t\"array and size of buffer\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\t\t\t\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len,\n\t\t\t\t\t dims.ptr,\n\t\t\t\t\t strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = (buffer.len-offset) / itemsize;\n }\n else if ((strides.ptr == NULL) && \\\n\t\t\t buffer.len < itemsize*\t\t\t\t\\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError,\n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t offset + (char *)buffer.ptr,\n\t\t\t\t\t buffer.flags, NULL);\n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base);\n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyArray_NewFlagsObject((PyObject *)self);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n\tint nd;\n\tPyObject *ret;\n\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret),\n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret),\n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes=0;\n\tintp offset=0;\n\tint buf_len;\n\tchar *buf;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base && PyArray_Check(new->base)) {\n\t\tnew = (PyArrayObject *)(new->base);\n\t}\n\t/* Get the available memory through the buffer\n\t interface on new->base or if that fails\n\t from the current new */\n\tif (new->base && PyObject_AsReadBuffer(new->base,\n\t\t\t\t\t (const void **)&buf,\n\t\t\t\t\t &buf_len) >= 0) {\n\t\toffset = self->data - buf;\n\t\tnumbytes = buf_len + offset;\n\t}\n\telse {\n\t\tPyErr_Clear();\n \t\tnumbytes = PyArray_MultiplyList(new->dimensions,\n\t\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\toffset = self->data - new->data;\n\t}\n\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes,\n\t\t\t\t offset,\n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self))\n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self)\n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0,\n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf,\n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse\n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse\n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed.\n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the\n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0)\n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n\telse if (newtype->elsize > self->descr->elsize) {\n\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update\n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\t/* We would decref newtype here --- temp will\n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tif (temp == NULL) return -1;\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\tPy_INCREF(temp->descr);\n\t\t/* Fool deallocator not to delete these*/\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype;\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA);\n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num -\n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type,\n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new);\n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int\narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode,\n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr));\n memmove(selfit->dataptr, arrit->dataptr,\n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size)\n PyArray_ITER_RESET(arrit);\n }\n retval = 0;\n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->descr->elsize);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size)\n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\",\n\t (getter)array_ndim_get,\n\t NULL,\n\t \"number of array dimensions\"},\n {\"flags\",\n\t (getter)array_flags_get,\n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\",\n\t (getter)array_shape_get,\n\t (setter)array_shape_set,\n\t \"tuple of array dimensions\"},\n {\"strides\",\n\t (getter)array_strides_get,\n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)array_data_get,\n\t (setter)array_data_set,\n\t \"pointer to start of data\"},\n {\"itemsize\",\n\t (getter)array_itemsize_get,\n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\",\n\t (getter)array_real_get,\n\t (setter)array_real_set,\n\t \"real part of array\"},\n {\"imag\",\n\t (getter)array_imag_get,\n\t (setter)array_imag_set,\n\t \"imaginary part of array\"},\n\t{\"flat\",\n\t (getter)array_flat_get,\n\t (setter)array_flat_set,\n\t \"a 1-d view of a contiguous array\"},\n\t{\"__array_data__\",\n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\",\n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n\t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */\n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] =\n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\nstatic PyTypeObject PyArray_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0,\t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n &array_as_sequence,\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str,\t /*tp_str*/\n\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n &array_as_buffer, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT\n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter,\t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n array_alloc,\t /* tp_alloc */\n (newfunc)array_new,\t\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int\ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple)\n{\n int d=0;\n PyObject *e;\n\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0)\n\t\treturn 1;\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize)\n{\n\tint n, r, i;\n\tPyObject *e;\n\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s)\n\t\t\t*itemsize = MAX(*itemsize, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype ---\n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately\n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE &&\n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\nstatic PyArray_Descr *\n_array_find_python_scalar_type(PyObject *op)\n{\n if (PyFloat_Check(op)) {\n return PyArray_DescrFromType(PyArray_DOUBLE);\n } else if (PyComplex_Check(op)) {\n return PyArray_DescrFromType(PyArray_CDOUBLE);\n } else if (PyInt_Check(op)) {\n /* bools are a subclass of int */\n if (PyBool_Check(op)) {\n return PyArray_DescrFromType(PyArray_BOOL);\n } else {\n return PyArray_DescrFromType(PyArray_LONG);\n }\n } else if (PyLong_Check(op)) {\n /* if integer can fit into a longlong then return that\n */\n if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n PyErr_Clear();\n return PyArray_DescrFromType(PyArray_OBJECT);\n }\n return PyArray_DescrFromType(PyArray_LONGLONG);\n }\n return NULL;\n}\n\n/* op is an object to be converted to an ndarray.\n\n minitype is the minimum type-descriptor needed.\n\n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n\n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\n\tif (minitype == NULL)\n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\n if (max < 0) goto deflt;\n\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n chktype = _array_find_python_scalar_type(op);\n if (chktype) {\n goto finish;\n }\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n\n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind,\n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n }\n\n\tif (PyInstance_Check(op)) goto deflt;\n\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\n finish:\n\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype;\n}\n\nstatic int\nAssign_Array(PyArrayObject *self, PyObject *v)\n{\n PyObject *e;\n int l, r;\n\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\n l=PyObject_Length(v);\n if(l < 0) return -1;\n\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1;\n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */\n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode)\n{\n PyArrayObject *ret;\n\tint itemsize;\n\tint type;\n\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= 4;\n\n\t\tif (itemsize != typecode->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(typecode);\n\t\t\ttypecode->elsize = itemsize;\n\t\t}\n\t}\n\n ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL,\n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\tif (ret == NULL) return NULL;\n\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode */\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string,\n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid input sequence\");\n\t\tgoto fail;\n }\n\n\tif (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {\n\t\tnd = max_depth;\n\t}\n\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid number of dimensions\");\n\t\tgoto fail;\n }\n\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\n if(!r) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int\nPyArray_ValidType(int type)\n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in))\n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, 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\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n oelsize);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject *\nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING)\n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd,\n\t\t\t\t mp->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\n}\n\n/* The number of elements in out must be an integer multiple\n of the number of elements in mp.\n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1;\n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * mpsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr,\n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)\n{\n\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1)\n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse {\n if ((flags & ENSUREARRAY)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype,\n\t\t\t\t\t\t newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr;\n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\n\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong))\n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char))\n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long))\n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap)\n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n\n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL;\n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n\n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data,\n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr));\n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n\n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context)\n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, \n\t\t\t\t\t\t\t\t NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None,\n\t\t\t\t\t\t context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", \n\t\t\t\t\t\t typecode, context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", \n\t\t\t\t\t\t\t typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError,\n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n}\n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,\n int max_depth, int flags, PyObject *context)\n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op))\n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t} else if (newtype == NULL &&\n (newtype = _array_find_python_scalar_type(op))) {\n r = Array_FromScalar(op, newtype);\n }\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, \n\t\t\t\t\t\tflags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\n\t/* Be sure we succeed here */\n\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int\nPyArray_ObjectType(PyObject *op, int minimum_type)\n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of\n CONTIGUOUS,\n FORTRAN,\n ALIGNED,\n WRITEABLE,\n NOTSWAPPED,\n ENSURECOPY,\n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should\n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or\n not it has such features.\n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well.\n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n\n FORTRAN can be set in the FLAGS to request a FORTRAN array.\n Fortran arrays are always behaved (aligned,\n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d).\n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array.\n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe.\n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,\n int max_depth, int requires, PyObject *context)\n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0,\n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place\n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op)) return op;\n\n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int\nPyArray_CanCastSafely(int fromtype, int totype)\n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype))\n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode\n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\n\t\t*/\n\t}\n\treturn ret;\n}\n\n/*OBJECT_API\n See if array scalars can be cast.\n */\nstatic Bool\nPyArray_CanCastScalar(PyTypeObject *from, PyTypeObject *to)\n{\n\tint fromtype;\n\tint totype;\n\n\tfromtype = _typenum_fromtypeobj((PyObject *)from, 0);\n\ttotype = _typenum_fromtypeobj((PyObject *)to, 0);\n\tif (fromtype == PyArray_NOTYPE || totype == PyArray_NOTYPE) \n\t\treturn FALSE;\n\treturn (Bool) PyArray_CanCastSafely(fromtype, totype);\t\n}\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n\n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd;\n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D)\n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic _int_or_ssize_t\niter_length(PyArrayIterObject *self)\n{\n return self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr,\n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1)\n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t 1, &n_steps,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail;\n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0,\n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n\t\t\t\t itemsize);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size)\n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size)\n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)\n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size)\n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0,\n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)iter_length,\t\t /*mp_length*/\n#else\n (inquiry)iter_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op)\n{\n\n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options:\n 1) underlying array is contiguous\n -- return 1-d wrapper around it\n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, it->ao->data,\n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r);\n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n\n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\",\n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &iter_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t\t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular\n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators\n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++)\n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already\n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1)\n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\n\t\t\t\t\t\t\t\"to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of\n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord,\n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t sizeof(intp));\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so,\n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size.\n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere.\n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well.\n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0\n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t/* But, be sure to do it with a true array.\n\t */\n\tif (PyArray_CheckExact(arr)) {\n\t\tsub = array_subscript(arr, mit->indexobj);\n\t}\n\telse {\n\t\tPy_INCREF(arr);\n\t\tobj = PyArray_EnsureArray((PyObject *)arr);\n\t\tif (obj == NULL) goto fail;\n\t\tsub = array_subscript((PyArrayObject *)obj, mit->indexobj);\n\t\tPy_DECREF(obj);\n\t}\n\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects\n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been\n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj))\n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj,\n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1;\n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) *indptr, (int) (dimsize-1),\n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0,\n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n\tmit->index = 0;\n\tmit->ait = NULL;\n\tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY\n#undef SOBJ_ISFANCY\n#undef SOBJ_BADARRAY\n#undef SOBJ_TOOMANY\n#undef SOBJ_LISTTUP\n\n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple\n\t (with at least 1 list or arrayobject or Bool object), */\n\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i,\n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing\n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n\n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work.\n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a);\n mapiter is equivalent to a[indexobj].flat but the latter gets to use\n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t\t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t\t /* tp_iter */\n (iternextfunc)0,\t /* tp_iternext */\n 0,\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\n\tint i, err=0;\n\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\n\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL)\n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i,\n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(multi->iters[i]);\n\t_pya_free(multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\",\n\t (getter)arraymultiter_size_get,\n\t NULL,\n\t \"total size of broadcasted result\"},\n {\"index\",\n\t (getter)arraymultiter_index_get,\n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter),\n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t\t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods,\t /* tp_methods */\n arraymultiter_members,\t\t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types.\n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these\n builtins will be attempted leading to problems.\n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically\n allocated).\n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless\n there is a reference-count problem\n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set.\n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base,\n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0)\n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\",\n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self)\n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\",\n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr)\n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr)\n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv))\n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\n\t/* Now return the state which is at least\n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize\n and alignment for EXTENDED arrays\n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\n\tif (PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are:\n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args)\n{\n\tchar endian=PyArray_SWAP;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS,\n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n\tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\ndescr_length(PyArray_Descr *self)\n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op)\n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError,\n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)descr_length,\t\t /*mp_length*/\n#else\n (inquiry)descr_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t\t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &descr_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t/* tp_iternext */\n arraydescr_methods,\t\t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n\n/** Array Flags Object **/\n\ntypedef struct PyArrayFlagsObject {\n PyObject_HEAD\n PyObject *arr;\n int flags;\n} PyArrayFlagsObject;\n\n/*OBJECT_API\n Get New ArrayFlagsObject\n*/\nstatic PyObject *\nPyArray_NewFlagsObject(PyObject *obj)\n{\n PyObject *flagobj;\n int flags;\n if (obj == NULL) {\n flags = CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n }\n else {\n flags = PyArray_FLAGS(obj);\n }\n flagobj = PyArrayFlags_Type.tp_alloc(&PyArrayFlags_Type, 0);\n if (flagobj == NULL) return NULL;\n Py_XINCREF(obj);\n ((PyArrayFlagsObject *)flagobj)->arr = obj;\n ((PyArrayFlagsObject *)flagobj)->flags = flags;\n\n return flagobj;\n}\n\nstatic void\narrayflags_dealloc(PyArrayFlagsObject *self)\n{\n\tPy_XDECREF(self->arr);\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n\n#define _define_get(UPPER, lower) \\\nstatic PyObject * \\\narrayflags_ ## lower ## _get(PyArrayFlagsObject *self) \\\n{ \\\n PyObject *item; \\\n item = ((self->flags & (UPPER)) == (UPPER)) ? Py_True : Py_False; \\\n Py_INCREF(item); \\\n return item; \\\n}\n\n_define_get(CONTIGUOUS, contiguous)\n_define_get(FORTRAN, fortran)\n_define_get(UPDATEIFCOPY, updateifcopy)\n_define_get(OWNDATA, owndata)\n_define_get(ALIGNED, aligned)\n_define_get(WRITEABLE, writeable)\n\n_define_get(ALIGNED|WRITEABLE, behaved)\n_define_get(ALIGNED|WRITEABLE|CONTIGUOUS, carray)\n\nstatic PyObject *\narrayflags_forc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) ||\n ((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_fnc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_farray_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & (ALIGNED|WRITEABLE|FORTRAN)) == \\\n (ALIGNED|WRITEABLE|FORTRAN)) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_num_get(PyArrayFlagsObject *self)\n{\n return PyInt_FromLong(self->flags);\n}\n\n/* relies on setflags order being write, align, uic */\nstatic int\narrayflags_updateifcopy_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False));\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_aligned_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_writeable_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None, Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\n\nstatic PyGetSetDef arrayflags_getsets[] = {\n\t{\"contiguous\",\n\t (getter)arrayflags_contiguous_get,\n\t NULL,\n\t \"\"},\n {\"fortran\",\n (getter)arrayflags_fortran_get,\n NULL,\n \"\"},\n {\"updateifcopy\",\n (getter)arrayflags_updateifcopy_get,\n (setter)arrayflags_updateifcopy_set,\n \"\"},\n {\"owndata\",\n (getter)arrayflags_owndata_get,\n NULL,\n \"\"},\n {\"aligned\",\n (getter)arrayflags_aligned_get,\n (setter)arrayflags_aligned_set,\n \"\"},\n {\"writeable\",\n (getter)arrayflags_writeable_get,\n (setter)arrayflags_writeable_set,\n \"\"},\n {\"fnc\",\n (getter)arrayflags_fnc_get,\n NULL,\n \"\"},\n {\"forc\",\n (getter)arrayflags_forc_get,\n NULL,\n \"\"},\n {\"behaved\",\n (getter)arrayflags_behaved_get,\n NULL,\n \"\"},\n {\"carray\",\n (getter)arrayflags_carray_get,\n NULL,\n \"\"},\n {\"farray\",\n (getter)arrayflags_farray_get,\n NULL,\n \"\"},\n {\"num\",\n (getter)arrayflags_num_get,\n NULL,\n \"\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyObject *\narrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)\n{\n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n\tswitch(n) {\n\tcase 1:\n\t\tswitch(key[0]) {\n\t\tcase 'C':\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tcase 'F':\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tcase 'W':\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tcase 'B':\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tcase 'O':\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tcase 'A':\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tcase 'U':\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tdefault:\n\t\t\tgoto fail;\n\t\t}\n\t\tbreak;\n\tcase 2:\n\t\tif (strncmp(key, \"CA\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FA\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 3:\n\t\tif (strncmp(key, \"FNC\", n)==0)\n\t\t\treturn arrayflags_fnc_get(self);\n\t\tbreak;\n\tcase 4:\n\t\tif (strncmp(key, \"FORC\", n)==0)\n\t\t\treturn arrayflags_forc_get(self);\n\t\tbreak;\n\tcase 6:\n\t\tif (strncmp(key, \"CARRAY\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FARRAY\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 7:\n\t\tif (strncmp(key,\"FORTRAN\",n)==0)\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tif (strncmp(key,\"BEHAVED\",n)==0)\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tif (strncmp(key,\"OWNDATA\",n)==0)\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tif (strncmp(key,\"ALIGNED\",n)==0)\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tbreak;\n\tcase 9:\t\n\t\tif (strncmp(key,\"WRITEABLE\",n)==0)\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tbreak;\n\tcase 10:\n\t\tif (strncmp(key,\"CONTIGUOUS\",n)==0)\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tbreak;\n\tcase 12:\n\t\tif (strncmp(key, \"UPDATEIFCOPY\", n)==0)\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tbreak;\n\t}\n\n fail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return NULL;\n}\n\nstatic int\narrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)\n{ \n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n if (((n==9) && (strncmp(key, \"WRITEABLE\", n)==0)) ||\n\t ((n==1) && (strncmp(key, \"W\", n)==0)))\n return arrayflags_writeable_set(self, item);\n else if (((n==7) && (strncmp(key, \"ALIGNED\", n)==0)) || \n ((n==1) && (strncmp(key, \"A\", n)==0)))\n return arrayflags_aligned_set(self, item);\n else if (((n==12) && (strncmp(key, \"UPDATEIFCOPY\", n)==0)) ||\n ((n==1) && (strncmp(key, \"U\", n)==0)))\n return arrayflags_updateifcopy_set(self, item); \n\nfail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return -1;\n}\n\nstatic char *\n_torf_(int flags, int val)\n{\n if ((flags & val) == val) return \"True\";\n else return \"False\"; \n}\n\nstatic PyObject *\narrayflags_print(PyArrayFlagsObject *self)\n{\n int fl = self->flags;\n \n return PyString_FromFormat(\" %s : %s\\n %s : %s\\n %s : %s\\n\"\\\n \" %s : %s\\n %s : %s\\n %s : %s\",\n \"CONTIGUOUS\", _torf_(fl, CONTIGUOUS),\n \"FORTRAN\", _torf_(fl, FORTRAN),\n \"OWNDATA\", _torf_(fl, OWNDATA),\n \"WRITEABLE\", _torf_(fl, WRITEABLE),\n \"ALIGNED\", _torf_(fl, ALIGNED),\n \"UPDATEIFCOPY\", _torf_(fl, UPDATEIFCOPY));\n}\n\n\nstatic PyMappingMethods arrayflags_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)NULL, \t\t /*mp_length*/\n#else\n (inquiry)NULL, \t\t /*mp_length*/\n#endif\n (binaryfunc)arrayflags_getitem,\t /*mp_subscript*/\n (objobjargproc)arrayflags_setitem, /*mp_ass_subscript*/\n};\n\n\nstatic PyObject *\narrayflags_new(PyTypeObject *self, PyObject *args, PyObject *kwds)\n{\n PyObject *arg=NULL;\n if (!PyArg_UnpackTuple(args, \"flagsobj\", 0, 1, &arg))\n return NULL;\n\n if ((arg != NULL) && PyArray_Check(arg)) {\n return PyArray_NewFlagsObject(arg);\n }\n else {\n return PyArray_NewFlagsObject(NULL);\n }\n}\n\nstatic PyTypeObject PyArrayFlags_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\n \"numpy.flagsobj\",\n sizeof(PyArrayFlagsObject),\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayflags_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t0,\t\t /* tp_compare */\n (reprfunc)arrayflags_print, /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &arrayflags_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arrayflags_print, /* tp_str */\n 0,\t \t /* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t /* tp_iternext */\n 0,\t \t /* tp_methods */\n 0,\t /* tp_members */\n arrayflags_getsets, /* tp_getset */\n 0,\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t /* tp_init */\n 0,\t /* tp_alloc */\n arrayflags_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "source_code_before": "/*\n Provide multidimensional arrays as a basic object type in python.\n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004\n\nHeavily modified in 2005 with inspiration from Numarray\n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University\n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by\nSpace Science Telescope Institute\n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_)\n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear();\n priority = default_;\n }\n Py_XDECREF(ret);\n return priority;\n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a\n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n }\n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int\ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides,\n\t intp *src_dimensions, int src_nd, int elsize,\n\t int copies) {\n intp i, j;\n\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1,\n dest_dimensions+1, dest_nd-1,\n src, src_strides,\n src_dimensions, src_nd,\n elsize, copies) == -1)\n return -1;\n }\n return 0;\n }\n\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError,\n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) &&\n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] !=\n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src)\n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\n dest_strides_ptr = dest_strides;\n\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1)\n return NULL;\n\n new_data = (char *)_pya_malloc(stride);\n\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions,\n dest_nd, src->data, src_strides,\n src_dimensions, src_nd, elsize, copies);\n\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *,\n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int\nPyArray_INCREF(PyArrayObject *mp)\n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap)\n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n\n\n if ((numitems == 1) || (itemsize == srcstrides))\n memcpy(d1, s1, itemsize*numitems);\n else {\n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n }\n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG\n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i)\n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp\nPyArray_Size(PyObject *op)\n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n }\n\telse {\n return 0;\n }\n}\n\n/* If destination is not the right type, then src\n will be cast to destination.\n*/\n\n/* Does a flat iterator-based copy.\n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however.\n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n\n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError,\n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n\n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, elsize);\n PyArray_INCREF(dest);\n return 0;\n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n }\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int\nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)\n{\n PyArrayObject *src;\n int ret;\n\t\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d,\n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t} \n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,\n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd,\n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran,\n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\n return (PyObject *)ret;\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) {\n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED;\n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=0;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use\n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifndef Py_UNICODE_WIDE\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\treturn obj;\n#endif\n\t\t}\n\t\telse {\n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, itemsize);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this.\n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag\n*/\n\n/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp)\n{\n\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n\n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int\nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs,\n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/*\n copyies over from the old descr table for anything\n NULL or zero in what is given.\n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)\n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data,\n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError,\n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr,\n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element\"\\\n \" %d to file\",\n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj);\n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj),\n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\",\n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1)\n fwrite(sep, 1, n3, fp);\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self)\n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0)\n\t\treturn self->descr->f->getitem(self->data,self);\n\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n\n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void\narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an\n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE\n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n\n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\narray_length(PyArrayObject *self)\n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i)\n{\n\tchar *item;\n\tPyArrayObject *r;\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1,\n\t\t\t\t\t\t self->dimensions+1,\n\t\t\t\t\t\t self->strides+1, item,\n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\nstatic PyObject *\narray_item_nice(PyArrayObject *self, _int_or_ssize_t i)\n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\n\nstatic int\narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v)\n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret;\n }\n\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if PY_VERSION_HEX < 0x02050000\n #if SIZEOF_INT == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#else\n #if SIZEOF_SIZE_T == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#endif\n#ifndef array_ass_item\nstatic int\narray_ass_item(PyArrayObject *self, _int_or_ssize_t i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int\nparse_index(PyArrayObject *self, PyObject *op,\n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError,\n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\n nd_old = nd_new = 0;\n\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n\t/* tuple for transpose is\n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of\n\t the broadcasted index array\n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the\n\t result\n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2)\n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call.\n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type,\n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret))\n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, PyArray_ITEMSIZE(arr));\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS];\n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL)\n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0\n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from\n Python when using a[object] unless object is a standard slice object\n (not an extended one).\n\n*/\n\n/* There are two situations:\n\n 1 - the subscript is a standard view and a reference to the\n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned.\n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *);\n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op)\n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr,\n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis) {\n\t\t\t/* XXX: This leads to a small inconsistency\n\t\t\t XXX: with the nd>0 case where (x[...] is x)\n\t\t\t XXX: is false for nd>0 case. */\n\t\t\tPy_INCREF(self);\n\t\t\treturn (PyObject *)self;\n\t\t}\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op)) {\n\t\t\t\tPy_INCREF(self);\n\t\t\t\treturn (PyObject *)self;\n\t\t\t}\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset))\n == -1)\n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset,\n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL)\n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be\n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *);\n\nstatic int\narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)\n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr,\n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1;\n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to\n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op)\n{\n\t/* The following is just a copy of PyArray_Return with an\n\t additional logic in the nd == 0 case. More efficient\n\t implementation may be possible by refactoring\n\t array_subscript */\n\n\tPyArrayObject *mp = (PyArrayObject *)array_subscript(self, op);\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tBool noellipses = TRUE;\n\t\tif (op == Py_Ellipsis)\n\t\t\tnoellipses = FALSE;\n\t\telse if (PySequence_Check(op)) {\n\t\t\tint n, i;\n\t\t\tn = PySequence_Size(op);\n\t\t\tfor (i = 0; i < n; ++i) \n\t\t\t\tif (PySequence_GetItem(op, i) == Py_Ellipsis) {\n\t\t\t\t\tnoellipses = FALSE;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t\tif (noellipses) {\n\t\t\tPyObject *ret;\n\t\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\t\tPy_DECREF(mp);\n\t\t\treturn ret;\n\t\t}\n\t}\n\treturn (PyObject *)mp;\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t /*mp_length*/\n#else\n (inquiry)array_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic _int_or_ssize_t\narray_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp)\n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic _int_or_ssize_t\narray_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"accessing non-existing array segment\");\n return -1;\n }\n\n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic _int_or_ssize_t\narray_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (PyArray_CHKFLAGS(self, WRITEABLE))\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic _int_or_ssize_t\narray_getcharbuf(PyArrayObject *self, _int_or_ssize_t segment, const char **ptrptr)\n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError,\n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (writebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (segcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (charbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#else\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#endif\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n *square,\n *reciprocal,\n *ones_like,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum,\n\t\t*rint;\n} NumericOps;\n\nstatic NumericOps n_ops; /* NB: static objects inlitialized to zero */\n\n/* Dictionary can contain any of the numeric operations, by name.\n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n\n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint\nPyArray_SetNumericOps(PyObject *dict)\n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n SET(square);\n SET(reciprocal);\n SET(ones_like);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\n SET(true_divide);\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n\tSET(rint);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void)\n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL)\n\t\treturn NULL;\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n GET(square);\n GET(reciprocal);\n GET(ones_like);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide);\n GET(true_divide);\n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\tGET(rint);\n\treturn dict;\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,\n\t\t\t\t PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2)\n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\n\nstatic PyObject *array_float(PyArrayObject *v);\n\n\nstatic int\narray_power_is_scalar(PyObject *o2, double* exp)\n{\n PyObject *temp;\n const int optimize_fpexps = 1;\n if (PyInt_Check(o2)) {\n *exp = (double)PyInt_AsLong(o2);\n return 1;\n }\n if (optimize_fpexps && PyFloat_Check(o2)) {\n *exp = PyFloat_AsDouble(o2);\n return 1;\n }\n if (PyArray_CheckScalar(o2)) {\n if (PyArray_ISINTEGER(o2) || (optimize_fpexps && PyArray_ISFLOAT(o2))) {\n temp = array_float((PyArrayObject *)o2);\n if (temp != NULL) {\n *exp = PyFloat_AsDouble(o2);\n Py_DECREF(temp);\n return 1;\n }\n }\n }\n return 0;\n}\n\n/* optimize float array or complex array to a scalar power */\nstatic PyObject *\nfast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) {\n double exp;\n if (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) || PyArray_ISCOMPLEX(a1))) {\n if (array_power_is_scalar(o2, &exp)) {\n PyObject *fastop = NULL;\n if (exp == 1.0) {\n /* we have to do this one special, as the \"copy\" method of\n array objects isn't set up early enough to be added\n by PyArray_SetNumericOps.\n */\n if (inplace) {\n return (PyObject *)a1;\n } else {\n return PyArray_Copy(a1);\n }\n } else if (exp == -1.0) {\n fastop = n_ops.reciprocal;\n } else if (exp == 0.0) {\n fastop = n_ops.ones_like;\n } else if (exp == 0.5) {\n fastop = n_ops.sqrt;\n } else if (exp == 2.0) {\n fastop = n_ops.square;\n } else {\n return NULL;\n }\n if (inplace) {\n PyArray_GenericInplaceUnaryFunction(a1, fastop);\n } else {\n return PyArray_GenericUnaryFunction(a1, fastop);\n }\n }\n }\n return NULL;\n}\n\nstatic PyObject *\narray_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 0);\n if (!value) {\n value = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\n\nstatic PyObject *\narray_negative(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 1);\n if (!value) {\n value = PyArray_GenericInplaceBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int\narray_any_nonzero(PyArrayObject *mp)\n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2)\n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_float(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to a \"\\\n\t\t\t\t\"float; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_long(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/\n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected\n*/\n\n\nstatic PyObject *\narray_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t _int_or_ssize_t ihigh)\n{\n PyArrayObject *r;\n _int_or_ssize_t l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n self->dimensions[0] = l;\n\tif (r == NULL) return NULL;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS);\n return (PyObject *)r;\n}\n\n\nstatic int\narray_ass_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t\t_int_or_ssize_t ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res;\n int ret;\n\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\nstatic PySequenceMethods array_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (ssizeargfunc)NULL,\n\t(ssizeargfunc)array_item_nice,\n\t(ssizessizeargfunc)array_slice,\n (ssizeobjargproc)array_ass_item,\t /*sq_ass_item*/\n (ssizessizeobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(ssizeargfunc)NULL,\n#else\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t /*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n#endif\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int\ndump_data(char **string, int *n, int *max_n, char *data, int nd,\n intp *dimensions, intp *strides, PyArrayObject* self)\n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\n if (nd == 0) {\n\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata,\n\t\t self->nd, self->dimensions,\n self->strides, self) < 0) {\n\t\t_pya_free(string); return NULL;\n\t}\n\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void\nPyArray_SetStringFunction(PyObject *op, int repr)\n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_ReprFunction = op;\n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_StrFunction = op;\n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)\n{\n PyObject *array_other, *result;\n\tint typenum;\n\n switch (cmp_op)\n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then return False\n\t\t\t\t This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of False\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the\n\t\t\t two array objects can not be compared together so\n\t\t\t return zero\n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be\n\t\t\t\t compared and cannot be equal, therefore,\n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t other,\n\t\t\t\t\t\t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL,\n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int\n_IsFortranContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap)\n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object\n\t If it is a writeable array, then return TRUE\n\t If we can find an array object\n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable\n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA))\n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly\n\t and unpickled array can be set and reset writeable\n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t\telse ret->flags &= ~WRITEABLE;\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not\n ever be able to walk outside of the memory implied numbytes and offset.\n\n The available memory is assumed to start at -offset and proceed\n to numbytes-offset. The strides are checked to ensure\n that accessing memory using striding will not try to reach beyond\n this memory for any of the axes.\n\n If numbytes is 0 it will be calculated using the dimensions and\n element-size.\n\n This function checks for walking beyond the beginning and right-end\n of the buffer and therefore works for any integer stride (positive\n or negative).\n*/\n\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\tintp byte_begin;\n\tintp begin;\n\tintp end;\n\n\tif (numbytes == 0)\n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\n\tbegin = -offset;\n\tend = numbytes - offset - elsize;\n\tfor (i=0; i end))\n\t\t\treturn FALSE;\n\t}\n\treturn TRUE;\n\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings\n depending on data and strides:\n\n If data is given, then flags is flags associated with data.\n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument\n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set).\n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired.\n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize,\n\t\t int inflag, int *objflags)\n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\n/* and update the dimensions and strides\n appropriately. Dimensions and strides are added\n to the end unless we have a FORTRAN array\n and then they are added to the beginning\n\n Strides are only added if given (because data is given).\n*/\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,\n\t\t\t intp *newstrides, int oldnd, int isfortran)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\tint tuple;\n\n\told = *des;\n\t*des = old->subarray->base;\n\n\n\tmydim = newdims + oldnd;\n\ttuple = PyTuple_Check(old->subarray->shape);\n\tif (tuple) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t}\n\telse {\n\t\tnumnew = 1;\n\t}\n\n\n\tnewnd = oldnd + numnew;\n\tif (newnd > MAX_DIMS) goto finish;\n\tif (isfortran) {\n\t\tmemmove(newdims+numnew, newdims, oldnd*sizeof(intp));\n\t\tmydim = newdims;\n\t}\n\n\tif (tuple) {\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\tif (isfortran) {\n\t\t\tmemmove(newstrides+numnew, newstrides,\n\t\t\t\toldnd*sizeof(intp));\n\t\t\tmystrides = newstrides;\n\t\t}\n\t\t/* Make new strides -- alwasy C-contiguous */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\n finish:\n\tPy_INCREF(*des);\n\tPy_DECREF(old);\n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,\n\t\t intp *dims, intp *strides, void *data,\n\t\t int flags, PyObject *obj)\n{\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tint isfortran=0;\n\t\tisfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || \\\n\t\t\t(!data && flags);\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims,\n\t\t\t\t\t\t newstrides, nd, isfortran);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims,\n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { \n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN;\n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse { /* we allow strides even when we create\n\t\t\t the memory, but be careful with this...\n\t\t */\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays\n\t\t e.g. shape=(0,) -- otherwise buffer exposure\n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in,\n\t\t\t\t\t this object won't own it\n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for\n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype.\n\t If obj is NULL, then call method with Py_None \n\t*/\n\tif ((subtype != &PyArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (strides != NULL) { /* did not allocate own data \n\t\t\t\t\t or funny strides */\n\t\t\t/* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tif (obj == NULL) obj=Py_None;\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n If refcheck is 0, then the reference count is not checked\n and assumed to be 1.\n You still must own this data and have no weak-references and no base\n object.\n*/\nstatic PyObject *\nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\n if (!PyArray_ISONESEGMENT(self)) {\n PyErr_SetString(PyExc_ValueError,\n \"resize only works on single-segment arrays\");\n return NULL;\n }\n\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n\n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (refcheck) refcnt = REFCOUNT(self);\n\t\telse refcnt = 1;\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (newsize == 0) sd = self->descr->elsize;\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n\n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) {\n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0,\n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n\n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n\n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n self->flags, &(self->flags));\n\n\n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\n return Py_None;\n\n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\tPyArray_FillWithScalarFunc* fillwithscalar =\n\t\t\tarr->descr->f->fillwithscalar;\n\t\tif (fillwithscalar && PyArray_ISALIGNED(arr)) {\n\t\t\tcopyswap(fromptr, NULL, swap, itemsize);\n\t\t\tfillwithscalar(toptr, size, fromptr, arr);\n\t\t}\n\t\telse {\n\t\t\twhile (size--) {\n\t\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\t\ttoptr += itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL;\n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous\n\t array of a specific type and shape.\n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims,\n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter,\n &strides,\n &fortran))\n\t\tgoto fail;\n\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"data-type with unspecified variable length\");\n\t\tgoto fail;\n\t}\n\t\n\tif (strides.ptr != NULL) {\n\t\tintp nb, off;\n\t\tif (strides.len != dims.len) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides, if given, must be \"\t\\\n\t\t\t\t\t\"the same length as shape\");\n\t\t\tgoto fail;\n\t\t}\n\n\t\tif (buffer.ptr == NULL) {\n\t\t\tnb = 0;\n\t\t\toff = 0;\n\t\t}\n\t\telse {\n\t\t\tnb = buffer.len;\n\t\t\toff = offset;\n\t\t}\n\t\t\n\n\t\tif (!PyArray_CheckStrides(itemsize, dims.len, \n\t\t\t\t\t nb, off,\n\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides is incompatible \"\t\\\n\t\t\t\t\t\"with shape of requested \"\t\\\n\t\t\t\t\t\"array and size of buffer\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\t\t\t\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len,\n\t\t\t\t\t dims.ptr,\n\t\t\t\t\t strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = (buffer.len-offset) / itemsize;\n }\n else if ((strides.ptr == NULL) && \\\n\t\t\t buffer.len < itemsize*\t\t\t\t\\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError,\n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t offset + (char *)buffer.ptr,\n\t\t\t\t\t buffer.flags, NULL);\n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base);\n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyArray_NewFlagsObject((PyObject *)self);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n\tint nd;\n\tPyObject *ret;\n\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret),\n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret),\n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes=0;\n\tintp offset=0;\n\tint buf_len;\n\tchar *buf;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base && PyArray_Check(new->base)) {\n\t\tnew = (PyArrayObject *)(new->base);\n\t}\n\t/* Get the available memory through the buffer\n\t interface on new->base or if that fails\n\t from the current new */\n\tif (new->base && PyObject_AsReadBuffer(new->base,\n\t\t\t\t\t (const void **)&buf,\n\t\t\t\t\t &buf_len) >= 0) {\n\t\toffset = self->data - buf;\n\t\tnumbytes = buf_len + offset;\n\t}\n\telse {\n\t\tPyErr_Clear();\n \t\tnumbytes = PyArray_MultiplyList(new->dimensions,\n\t\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\toffset = self->data - new->data;\n\t}\n\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes,\n\t\t\t\t offset,\n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self))\n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self)\n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0,\n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf,\n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse\n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse\n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed.\n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the\n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0)\n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n\telse if (newtype->elsize > self->descr->elsize) {\n\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update\n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\t/* We would decref newtype here --- temp will\n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tif (temp == NULL) return -1;\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\tPy_INCREF(temp->descr);\n\t\t/* Fool deallocator not to delete these*/\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype;\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA);\n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num -\n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type,\n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new);\n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int\narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode,\n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr));\n memmove(selfit->dataptr, arrit->dataptr,\n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size)\n PyArray_ITER_RESET(arrit);\n }\n retval = 0;\n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->descr->elsize);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size)\n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\",\n\t (getter)array_ndim_get,\n\t NULL,\n\t \"number of array dimensions\"},\n {\"flags\",\n\t (getter)array_flags_get,\n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\",\n\t (getter)array_shape_get,\n\t (setter)array_shape_set,\n\t \"tuple of array dimensions\"},\n {\"strides\",\n\t (getter)array_strides_get,\n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)array_data_get,\n\t (setter)array_data_set,\n\t \"pointer to start of data\"},\n {\"itemsize\",\n\t (getter)array_itemsize_get,\n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\",\n\t (getter)array_real_get,\n\t (setter)array_real_set,\n\t \"real part of array\"},\n {\"imag\",\n\t (getter)array_imag_get,\n\t (setter)array_imag_set,\n\t \"imaginary part of array\"},\n\t{\"flat\",\n\t (getter)array_flat_get,\n\t (setter)array_flat_set,\n\t \"a 1-d view of a contiguous array\"},\n\t{\"__array_data__\",\n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\",\n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n\t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */\n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] =\n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\nstatic PyTypeObject PyArray_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0,\t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n &array_as_sequence,\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str,\t /*tp_str*/\n\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n &array_as_buffer, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT\n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter,\t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n array_alloc,\t /* tp_alloc */\n (newfunc)array_new,\t\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int\ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple)\n{\n int d=0;\n PyObject *e;\n\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0)\n\t\treturn 1;\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize)\n{\n\tint n, r, i;\n\tPyObject *e;\n\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s)\n\t\t\t*itemsize = MAX(*itemsize, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype ---\n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately\n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE &&\n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\nstatic PyArray_Descr *\n_array_find_python_scalar_type(PyObject *op)\n{\n if (PyFloat_Check(op)) {\n return PyArray_DescrFromType(PyArray_DOUBLE);\n } else if (PyComplex_Check(op)) {\n return PyArray_DescrFromType(PyArray_CDOUBLE);\n } else if (PyInt_Check(op)) {\n /* bools are a subclass of int */\n if (PyBool_Check(op)) {\n return PyArray_DescrFromType(PyArray_BOOL);\n } else {\n return PyArray_DescrFromType(PyArray_LONG);\n }\n } else if (PyLong_Check(op)) {\n /* if integer can fit into a longlong then return that\n */\n if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n PyErr_Clear();\n return PyArray_DescrFromType(PyArray_OBJECT);\n }\n return PyArray_DescrFromType(PyArray_LONGLONG);\n }\n return NULL;\n}\n\n/* op is an object to be converted to an ndarray.\n\n minitype is the minimum type-descriptor needed.\n\n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n\n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\n\tif (minitype == NULL)\n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\n if (max < 0) goto deflt;\n\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n chktype = _array_find_python_scalar_type(op);\n if (chktype) {\n goto finish;\n }\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n\n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind,\n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n }\n\n\tif (PyInstance_Check(op)) goto deflt;\n\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\n finish:\n\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype;\n}\n\nstatic int\nAssign_Array(PyArrayObject *self, PyObject *v)\n{\n PyObject *e;\n int l, r;\n\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\n l=PyObject_Length(v);\n if(l < 0) return -1;\n\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1;\n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */\n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode)\n{\n PyArrayObject *ret;\n\tint itemsize;\n\tint type;\n\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= 4;\n\n\t\tif (itemsize != typecode->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(typecode);\n\t\t\ttypecode->elsize = itemsize;\n\t\t}\n\t}\n\n ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL,\n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\tif (ret == NULL) return NULL;\n\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode */\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string,\n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid input sequence\");\n\t\tgoto fail;\n }\n\n\tif (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {\n\t\tnd = max_depth;\n\t}\n\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid number of dimensions\");\n\t\tgoto fail;\n }\n\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\n if(!r) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int\nPyArray_ValidType(int type)\n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in))\n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, 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\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n oelsize);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject *\nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING)\n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd,\n\t\t\t\t mp->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\n}\n\n/* The number of elements in out must be an integer multiple\n of the number of elements in mp.\n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1;\n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * mpsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr,\n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)\n{\n\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1)\n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse {\n if ((flags & ENSUREARRAY)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype,\n\t\t\t\t\t\t newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr;\n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\n\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong))\n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char))\n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long))\n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap)\n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n\n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL;\n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n\n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data,\n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr));\n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n\n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context)\n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, \n\t\t\t\t\t\t\t\t NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None,\n\t\t\t\t\t\t context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", \n\t\t\t\t\t\t typecode, context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", \n\t\t\t\t\t\t\t typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError,\n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n}\n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,\n int max_depth, int flags, PyObject *context)\n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op))\n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t} else if (newtype == NULL &&\n (newtype = _array_find_python_scalar_type(op))) {\n r = Array_FromScalar(op, newtype);\n }\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, \n\t\t\t\t\t\tflags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\n\t/* Be sure we succeed here */\n\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int\nPyArray_ObjectType(PyObject *op, int minimum_type)\n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of\n CONTIGUOUS,\n FORTRAN,\n ALIGNED,\n WRITEABLE,\n NOTSWAPPED,\n ENSURECOPY,\n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should\n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or\n not it has such features.\n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well.\n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n\n FORTRAN can be set in the FLAGS to request a FORTRAN array.\n Fortran arrays are always behaved (aligned,\n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d).\n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array.\n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe.\n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,\n int max_depth, int requires, PyObject *context)\n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0,\n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place\n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op)) return op;\n\n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int\nPyArray_CanCastSafely(int fromtype, int totype)\n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype))\n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode\n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\n\t\t*/\n\t}\n\treturn ret;\n}\n\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n\n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd;\n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D)\n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic _int_or_ssize_t\niter_length(PyArrayIterObject *self)\n{\n return self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr,\n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1)\n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t 1, &n_steps,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail;\n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0,\n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n\t\t\t\t itemsize);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size)\n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size)\n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)\n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size)\n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0,\n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)iter_length,\t\t /*mp_length*/\n#else\n (inquiry)iter_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op)\n{\n\n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options:\n 1) underlying array is contiguous\n -- return 1-d wrapper around it\n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, it->ao->data,\n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r);\n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n\n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\",\n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &iter_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t\t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular\n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators\n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++)\n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already\n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1)\n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\n\t\t\t\t\t\t\t\"to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of\n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord,\n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t sizeof(intp));\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so,\n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size.\n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere.\n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well.\n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0\n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t/* But, be sure to do it with a true array.\n\t */\n\tif (PyArray_CheckExact(arr)) {\n\t\tsub = array_subscript(arr, mit->indexobj);\n\t}\n\telse {\n\t\tPy_INCREF(arr);\n\t\tobj = PyArray_EnsureArray((PyObject *)arr);\n\t\tif (obj == NULL) goto fail;\n\t\tsub = array_subscript((PyArrayObject *)obj, mit->indexobj);\n\t\tPy_DECREF(obj);\n\t}\n\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects\n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been\n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj))\n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj,\n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1;\n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) *indptr, (int) (dimsize-1),\n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0,\n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n\tmit->index = 0;\n\tmit->ait = NULL;\n\tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY\n#undef SOBJ_ISFANCY\n#undef SOBJ_BADARRAY\n#undef SOBJ_TOOMANY\n#undef SOBJ_LISTTUP\n\n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple\n\t (with at least 1 list or arrayobject or Bool object), */\n\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i,\n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing\n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n\n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work.\n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a);\n mapiter is equivalent to a[indexobj].flat but the latter gets to use\n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t\t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t\t /* tp_iter */\n (iternextfunc)0,\t /* tp_iternext */\n 0,\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\n\tint i, err=0;\n\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\n\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL)\n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i,\n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(multi->iters[i]);\n\t_pya_free(multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\",\n\t (getter)arraymultiter_size_get,\n\t NULL,\n\t \"total size of broadcasted result\"},\n {\"index\",\n\t (getter)arraymultiter_index_get,\n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter),\n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t\t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods,\t /* tp_methods */\n arraymultiter_members,\t\t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types.\n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these\n builtins will be attempted leading to problems.\n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically\n allocated).\n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless\n there is a reference-count problem\n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set.\n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base,\n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0)\n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\",\n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self)\n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\",\n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr)\n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr)\n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv))\n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\n\t/* Now return the state which is at least\n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize\n and alignment for EXTENDED arrays\n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\n\tif (PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are:\n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args)\n{\n\tchar endian=PyArray_SWAP;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS,\n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n\tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\ndescr_length(PyArray_Descr *self)\n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op)\n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError,\n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)descr_length,\t\t /*mp_length*/\n#else\n (inquiry)descr_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t\t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &descr_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t/* tp_iternext */\n arraydescr_methods,\t\t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n\n/** Array Flags Object **/\n\ntypedef struct PyArrayFlagsObject {\n PyObject_HEAD\n PyObject *arr;\n int flags;\n} PyArrayFlagsObject;\n\n/*OBJECT_API\n Get New ArrayFlagsObject\n*/\nstatic PyObject *\nPyArray_NewFlagsObject(PyObject *obj)\n{\n PyObject *flagobj;\n int flags;\n if (obj == NULL) {\n flags = CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n }\n else {\n flags = PyArray_FLAGS(obj);\n }\n flagobj = PyArrayFlags_Type.tp_alloc(&PyArrayFlags_Type, 0);\n if (flagobj == NULL) return NULL;\n Py_XINCREF(obj);\n ((PyArrayFlagsObject *)flagobj)->arr = obj;\n ((PyArrayFlagsObject *)flagobj)->flags = flags;\n\n return flagobj;\n}\n\nstatic void\narrayflags_dealloc(PyArrayFlagsObject *self)\n{\n\tPy_XDECREF(self->arr);\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n\n#define _define_get(UPPER, lower) \\\nstatic PyObject * \\\narrayflags_ ## lower ## _get(PyArrayFlagsObject *self) \\\n{ \\\n PyObject *item; \\\n item = ((self->flags & (UPPER)) == (UPPER)) ? Py_True : Py_False; \\\n Py_INCREF(item); \\\n return item; \\\n}\n\n_define_get(CONTIGUOUS, contiguous)\n_define_get(FORTRAN, fortran)\n_define_get(UPDATEIFCOPY, updateifcopy)\n_define_get(OWNDATA, owndata)\n_define_get(ALIGNED, aligned)\n_define_get(WRITEABLE, writeable)\n\n_define_get(ALIGNED|WRITEABLE, behaved)\n_define_get(ALIGNED|WRITEABLE|CONTIGUOUS, carray)\n\nstatic PyObject *\narrayflags_forc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) ||\n ((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_fnc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_farray_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & (ALIGNED|WRITEABLE|FORTRAN)) == \\\n (ALIGNED|WRITEABLE|FORTRAN)) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_num_get(PyArrayFlagsObject *self)\n{\n return PyInt_FromLong(self->flags);\n}\n\n/* relies on setflags order being write, align, uic */\nstatic int\narrayflags_updateifcopy_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False));\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_aligned_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_writeable_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None, Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\n\nstatic PyGetSetDef arrayflags_getsets[] = {\n\t{\"contiguous\",\n\t (getter)arrayflags_contiguous_get,\n\t NULL,\n\t \"\"},\n {\"fortran\",\n (getter)arrayflags_fortran_get,\n NULL,\n \"\"},\n {\"updateifcopy\",\n (getter)arrayflags_updateifcopy_get,\n (setter)arrayflags_updateifcopy_set,\n \"\"},\n {\"owndata\",\n (getter)arrayflags_owndata_get,\n NULL,\n \"\"},\n {\"aligned\",\n (getter)arrayflags_aligned_get,\n (setter)arrayflags_aligned_set,\n \"\"},\n {\"writeable\",\n (getter)arrayflags_writeable_get,\n (setter)arrayflags_writeable_set,\n \"\"},\n {\"fnc\",\n (getter)arrayflags_fnc_get,\n NULL,\n \"\"},\n {\"forc\",\n (getter)arrayflags_forc_get,\n NULL,\n \"\"},\n {\"behaved\",\n (getter)arrayflags_behaved_get,\n NULL,\n \"\"},\n {\"carray\",\n (getter)arrayflags_carray_get,\n NULL,\n \"\"},\n {\"farray\",\n (getter)arrayflags_farray_get,\n NULL,\n \"\"},\n {\"num\",\n (getter)arrayflags_num_get,\n NULL,\n \"\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyObject *\narrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)\n{\n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n\tswitch(n) {\n\tcase 1:\n\t\tswitch(key[0]) {\n\t\tcase 'C':\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tcase 'F':\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tcase 'W':\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tcase 'B':\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tcase 'O':\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tcase 'A':\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tcase 'U':\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tdefault:\n\t\t\tgoto fail;\n\t\t}\n\t\tbreak;\n\tcase 2:\n\t\tif (strncmp(key, \"CA\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FA\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 3:\n\t\tif (strncmp(key, \"FNC\", n)==0)\n\t\t\treturn arrayflags_fnc_get(self);\n\t\tbreak;\n\tcase 4:\n\t\tif (strncmp(key, \"FORC\", n)==0)\n\t\t\treturn arrayflags_forc_get(self);\n\t\tbreak;\n\tcase 6:\n\t\tif (strncmp(key, \"CARRAY\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FARRAY\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 7:\n\t\tif (strncmp(key,\"FORTRAN\",n)==0)\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tif (strncmp(key,\"BEHAVED\",n)==0)\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tif (strncmp(key,\"OWNDATA\",n)==0)\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tif (strncmp(key,\"ALIGNED\",n)==0)\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tbreak;\n\tcase 9:\t\n\t\tif (strncmp(key,\"WRITEABLE\",n)==0)\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tbreak;\n\tcase 10:\n\t\tif (strncmp(key,\"CONTIGUOUS\",n)==0)\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tbreak;\n\tcase 12:\n\t\tif (strncmp(key, \"UPDATEIFCOPY\", n)==0)\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tbreak;\n\t}\n\n fail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return NULL;\n}\n\nstatic int\narrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)\n{ \n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n if (((n==9) && (strncmp(key, \"WRITEABLE\", n)==0)) ||\n\t ((n==1) && (strncmp(key, \"W\", n)==0)))\n return arrayflags_writeable_set(self, item);\n else if (((n==7) && (strncmp(key, \"ALIGNED\", n)==0)) || \n ((n==1) && (strncmp(key, \"A\", n)==0)))\n return arrayflags_aligned_set(self, item);\n else if (((n==12) && (strncmp(key, \"UPDATEIFCOPY\", n)==0)) ||\n ((n==1) && (strncmp(key, \"U\", n)==0)))\n return arrayflags_updateifcopy_set(self, item); \n\nfail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return -1;\n}\n\nstatic char *\n_torf_(int flags, int val)\n{\n if ((flags & val) == val) return \"True\";\n else return \"False\"; \n}\n\nstatic PyObject *\narrayflags_print(PyArrayFlagsObject *self)\n{\n int fl = self->flags;\n \n return PyString_FromFormat(\" %s : %s\\n %s : %s\\n %s : %s\\n\"\\\n \" %s : %s\\n %s : %s\\n %s : %s\",\n \"CONTIGUOUS\", _torf_(fl, CONTIGUOUS),\n \"FORTRAN\", _torf_(fl, FORTRAN),\n \"OWNDATA\", _torf_(fl, OWNDATA),\n \"WRITEABLE\", _torf_(fl, WRITEABLE),\n \"ALIGNED\", _torf_(fl, ALIGNED),\n \"UPDATEIFCOPY\", _torf_(fl, UPDATEIFCOPY));\n}\n\n\nstatic PyMappingMethods arrayflags_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)NULL, \t\t /*mp_length*/\n#else\n (inquiry)NULL, \t\t /*mp_length*/\n#endif\n (binaryfunc)arrayflags_getitem,\t /*mp_subscript*/\n (objobjargproc)arrayflags_setitem, /*mp_ass_subscript*/\n};\n\n\nstatic PyObject *\narrayflags_new(PyTypeObject *self, PyObject *args, PyObject *kwds)\n{\n PyObject *arg=NULL;\n if (!PyArg_UnpackTuple(args, \"flagsobj\", 0, 1, &arg))\n return NULL;\n\n if ((arg != NULL) && PyArray_Check(arg)) {\n return PyArray_NewFlagsObject(arg);\n }\n else {\n return PyArray_NewFlagsObject(NULL);\n }\n}\n\nstatic PyTypeObject PyArrayFlags_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\n \"numpy.flagsobj\",\n sizeof(PyArrayFlagsObject),\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayflags_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t0,\t\t /* tp_compare */\n (reprfunc)arrayflags_print, /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &arrayflags_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arrayflags_print, /* tp_str */\n 0,\t \t /* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t /* tp_iternext */\n 0,\t \t /* tp_methods */\n 0,\t /* tp_members */\n arrayflags_getsets, /* tp_getset */\n 0,\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t /* tp_init */\n 0,\t /* tp_alloc */\n arrayflags_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "methods": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 76, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 65, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 99, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 134, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 207, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 241, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 291, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 319, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 344, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 387, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 427, + "end_line": 509, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 516, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 593, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Size", + "long_name": "PyArray_Size( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 33, + "parameters": [ + "op" + ], + "start_line": 614, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 638, + "end_line": 718, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyObject", + "long_name": "PyArray_CopyObject( PyArrayObject * dest , PyObject * src_object)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 722, + "end_line": 736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDimsAndDataAndDescr", + "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 137, + "parameters": [ + "nd", + "d", + "descr", + "data" + ], + "start_line": 749, + "end_line": 775, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDims", + "long_name": "PyArray_FromDims( int nd , int * d , int type)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "nd", + "d", + "type" + ], + "start_line": 781, + "end_line": 795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewCopy", + "long_name": "PyArray_NewCopy( PyArrayObject * m1 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 804, + "end_line": 824, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 17, + "token_count": 616, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 833, + "end_line": 949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 965, + "end_line": 968, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Return", + "long_name": "PyArray_Return( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 91, + "parameters": [ + "mp" + ], + "start_line": 978, + "end_line": 1000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDataType", + "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 9, + "token_count": 229, + "parameters": [ + "type" + ], + "start_line": 1014, + "end_line": 1054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDescrForType", + "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 214, + "parameters": [ + "typenum", + "descr" + ], + "start_line": 1069, + "end_line": 1110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToFile", + "long_name": "PyArray_ToFile( PyArrayObject * self , FILE * fp , char * sep , char * format)", + "filename": "arrayobject.c", + "nloc": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1117, + "end_line": 1208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToList", + "long_name": "PyArray_ToList( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self" + ], + "start_line": 1214, + "end_line": 1243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToString", + "long_name": "PyArray_ToString( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 170, + "parameters": [ + "self" + ], + "start_line": 1246, + "end_line": 1282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_dealloc", + "long_name": "array_dealloc( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 1291, + "end_line": 1328, + "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": 1335, + "end_line": 1343, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_big_item", + "long_name": "array_big_item( PyArrayObject * self , intp i)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 4, + "token_count": 151, + "parameters": [ + "self", + "i" + ], + "start_line": 1346, + "end_line": 1371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , _int_or_ssize_t i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1374, + "end_line": 1377, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_ass_big_item", + "long_name": "array_ass_big_item( PyArrayObject * self , intp i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1380, + "end_line": 1415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , _int_or_ssize_t i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1428, + "end_line": 1431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "slice_coerce_index", + "long_name": "slice_coerce_index( PyObject * o , intp * v)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "o", + "v" + ], + "start_line": 1437, + "end_line": 1445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "slice_GetIndices", + "long_name": "slice_GetIndices( PySliceObject * r , intp length , intp * start , intp * stop , intp * step , intp * slicelength)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 24, + "token_count": 376, + "parameters": [ + "r", + "length", + "start", + "stop", + "step", + "slicelength" + ], + "start_line": 1451, + "end_line": 1501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "parse_subindex", + "long_name": "parse_subindex( PyObject * op , intp * step_size , intp * n_steps , intp max)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "step_size", + "n_steps", + "max" + ], + "start_line": 1508, + "end_line": 1553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "parse_index", + "long_name": "parse_index( PyArrayObject * self , PyObject * op , intp * dimensions , intp * strides , intp * offset_ptr)", + "filename": "arrayobject.c", + "nloc": 88, + "complexity": 20, + "token_count": 539, + "parameters": [ + "self", + "op", + "dimensions", + "strides", + "offset_ptr" + ], + "start_line": 1557, + "end_line": 1651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "_swap_axes", + "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1654, + "end_line": 1691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1703, + "end_line": 1756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetMap", + "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 53, + "complexity": 12, + "token_count": 382, + "parameters": [ + "mit", + "op" + ], + "start_line": 1759, + "end_line": 1819, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 0 + }, + { + "name": "count_new_axes_0d", + "long_name": "count_new_axes_0d( PyObject * tuple)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 7, + "token_count": 124, + "parameters": [ + "tuple" + ], + "start_line": 1822, + "end_line": 1849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "add_new_axes_0d", + "long_name": "add_new_axes_0d( PyArrayObject * arr , int newaxis_count)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 121, + "parameters": [ + "arr", + "newaxis_count" + ], + "start_line": 1852, + "end_line": 1871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 1883, + "end_line": 1945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 107, + "complexity": 28, + "token_count": 674, + "parameters": [ + "self", + "op" + ], + "start_line": 1969, + "end_line": 2094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2109, + "end_line": 2214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 10, + "token_count": 182, + "parameters": [ + "self", + "op" + ], + "start_line": 2223, + "end_line": 2262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , _int_or_ssize_t * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2285, + "end_line": 2297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2300, + "end_line": 2315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2319, + "end_line": 2328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , _int_or_ssize_t segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2331, + "end_line": 2342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 1, + "token_count": 182, + "parameters": [ + "dict" + ], + "start_line": 2420, + "end_line": 2457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 2, + "token_count": 203, + "parameters": [], + "start_line": 2467, + "end_line": 2510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2513, + "end_line": 2536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericAccumulateFunction", + "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2540, + "end_line": 2563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericBinaryFunction", + "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 44, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2567, + "end_line": 2574, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericUnaryFunction", + "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 38, + "parameters": [ + "m1", + "op" + ], + "start_line": 2577, + "end_line": 2584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceBinaryFunction", + "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 46, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2587, + "end_line": 2595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceUnaryFunction", + "long_name": "PyArray_GenericInplaceUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 40, + "parameters": [ + "m1", + "op" + ], + "start_line": 2598, + "end_line": 2605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2608, + "end_line": 2611, + "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": 2614, + "end_line": 2617, + "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": 2620, + "end_line": 2623, + "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": 2626, + "end_line": 2629, + "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": 2632, + "end_line": 2635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power_is_scalar", + "long_name": "array_power_is_scalar( PyObject * o2 , double * exp)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 132, + "parameters": [ + "o2", + "exp" + ], + "start_line": 2642, + "end_line": 2665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "fast_scalar_power", + "long_name": "fast_scalar_power( PyArrayObject * a1 , PyObject * o2 , int inplace)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 12, + "token_count": 181, + "parameters": [ + "a1", + "o2", + "inplace" + ], + "start_line": 2669, + "end_line": 2703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2706, + "end_line": 2715, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2719, + "end_line": 2722, + "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": 2725, + "end_line": 2728, + "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": 2731, + "end_line": 2734, + "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": 2737, + "end_line": 2740, + "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": 2743, + "end_line": 2746, + "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": 2749, + "end_line": 2752, + "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": 2755, + "end_line": 2758, + "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": 2761, + "end_line": 2764, + "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": 2767, + "end_line": 2770, + "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": 2773, + "end_line": 2776, + "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": 2779, + "end_line": 2782, + "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": 2785, + "end_line": 2788, + "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": 2791, + "end_line": 2794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2797, + "end_line": 2806, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2809, + "end_line": 2812, + "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": 2815, + "end_line": 2818, + "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": 2821, + "end_line": 2824, + "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": 2827, + "end_line": 2830, + "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": 2833, + "end_line": 2836, + "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": 2839, + "end_line": 2842, + "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": 2845, + "end_line": 2848, + "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": 2851, + "end_line": 2855, + "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": 2858, + "end_line": 2862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_any_nonzero", + "long_name": "array_any_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 95, + "parameters": [ + "mp" + ], + "start_line": 2866, + "end_line": 2884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_array_nonzero", + "long_name": "_array_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 3, + "token_count": 72, + "parameters": [ + "mp" + ], + "start_line": 2887, + "end_line": 2904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_divmod", + "long_name": "array_divmod( PyArrayObject * op1 , PyObject * op2)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 89, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2909, + "end_line": 2924, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_int", + "long_name": "array_int( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2928, + "end_line": 2954, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_float", + "long_name": "array_float( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2957, + "end_line": 2982, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_long", + "long_name": "array_long( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 2985, + "end_line": 3007, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_oct", + "long_name": "array_oct( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3010, + "end_line": 3032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_hex", + "long_name": "array_hex( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3035, + "end_line": 3057, + "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": 3060, + "end_line": 3064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 12, + "token_count": 268, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 3125, + "end_line": 3166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 3170, + "end_line": 3192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 3195, + "end_line": 3207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dump_data", + "long_name": "dump_data( char ** string , int * n , int * max_n , char * data , int nd , intp * dimensions , intp * strides , PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 7, + "token_count": 310, + "parameters": [ + "string", + "n", + "max_n", + "data", + "nd", + "dimensions", + "strides", + "self" + ], + "start_line": 3240, + "end_line": 3287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_repr_builtin", + "long_name": "array_repr_builtin( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 4, + "token_count": 224, + "parameters": [ + "self" + ], + "start_line": 3290, + "end_line": 3326, + "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": 3335, + "end_line": 3352, + "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": 3355, + "end_line": 3367, + "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": 3370, + "end_line": 3382, + "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": 90, + "complexity": 19, + "token_count": 392, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3385, + "end_line": 3491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 171, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3494, + "end_line": 3523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntTupleFromIntp", + "long_name": "PyArray_IntTupleFromIntp( int len , intp * vals)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 109, + "parameters": [ + "len", + "vals" + ], + "start_line": 3529, + "end_line": 3549, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3557, + "end_line": 3592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3598, + "end_line": 3617, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 3621, + "end_line": 3639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 3642, + "end_line": 3659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_IsWriteable", + "long_name": "_IsWriteable( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 107, + "parameters": [ + "ap" + ], + "start_line": 3662, + "end_line": 3695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_UpdateFlags", + "long_name": "PyArray_UpdateFlags( PyArrayObject * ret , int flagmask)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 11, + "token_count": 157, + "parameters": [ + "ret", + "flagmask" + ], + "start_line": 3702, + "end_line": 3729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 117, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 3749, + "end_line": 3769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 3789, + "end_line": 3813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_New", + "long_name": "PyArray_New( PyTypeObject * subtype , int nd , intp * dims , int type_num , intp * strides , * data , int itemsize , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 4, + "token_count": 128, + "parameters": [ + "subtype", + "nd", + "dims", + "type_num", + "strides", + "data", + "itemsize", + "flags", + "obj" + ], + "start_line": 3819, + "end_line": 3841, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd , int isfortran)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 10, + "token_count": 311, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd", + "isfortran" + ], + "start_line": 3852, + "end_line": 3914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 132, + "complexity": 29, + "token_count": 785, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3922, + "end_line": 4088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 167, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape , int refcheck)", + "filename": "arrayobject.c", + "nloc": 83, + "complexity": 16, + "token_count": 511, + "parameters": [ + "self", + "newshape", + "refcheck" + ], + "start_line": 4101, + "end_line": 4200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 100, + "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": 4206, + "end_line": 4223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 8, + "token_count": 279, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4227, + "end_line": 4277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 21, + "token_count": 620, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4280, + "end_line": 4411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 132, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4415, + "end_line": 4423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ndim_get", + "long_name": "array_ndim_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4429, + "end_line": 4432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flags_get", + "long_name": "array_flags_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 4435, + "end_line": 4438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_get", + "long_name": "array_shape_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4441, + "end_line": 4444, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_set", + "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4448, + "end_line": 4477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "array_strides_get", + "long_name": "array_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4481, + "end_line": 4484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 9, + "token_count": 304, + "parameters": [ + "self", + "obj" + ], + "start_line": 4487, + "end_line": 4541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4545, + "end_line": 4552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4555, + "end_line": 4561, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4565, + "end_line": 4571, + "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": 4574, + "end_line": 4588, + "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": 4591, + "end_line": 4635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_itemsize_get", + "long_name": "array_itemsize_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 4639, + "end_line": 4642, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_size_get", + "long_name": "array_size_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4645, + "end_line": 4656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nbytes_get", + "long_name": "array_nbytes_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4659, + "end_line": 4670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4676, + "end_line": 4679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_descr_get", + "long_name": "array_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 4682, + "end_line": 4686, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "arg" + ], + "start_line": 4700, + "end_line": 4787, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 4790, + "end_line": 4808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_struct_get", + "long_name": "array_struct_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 2, + "token_count": 130, + "parameters": [ + "self" + ], + "start_line": 4811, + "end_line": 4829, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 4832, + "end_line": 4842, + "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": 4846, + "end_line": 4871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_real_set", + "long_name": "array_real_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 4, + "token_count": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 4875, + "end_line": 4908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_get", + "long_name": "array_imag_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self" + ], + "start_line": 4911, + "end_line": 4944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 4947, + "end_line": 4984, + "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": 4987, + "end_line": 4990, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flat_set", + "long_name": "array_flat_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 9, + "token_count": 348, + "parameters": [ + "self", + "val" + ], + "start_line": 4993, + "end_line": 5043, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_alloc", + "long_name": "array_alloc( PyTypeObject * type , int nitems)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 1, + "token_count": 39, + "parameters": [ + "type", + "nitems" + ], + "start_line": 5133, + "end_line": 5140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "discover_depth", + "long_name": "discover_depth( PyObject * s , int max , int stop_at_string , int stop_at_tuple)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 19, + "token_count": 243, + "parameters": [ + "s", + "max", + "stop_at_string", + "stop_at_tuple" + ], + "start_line": 5228, + "end_line": 5261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5264, + "end_line": 5286, + "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": 5293, + "end_line": 5319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_array_small_type", + "long_name": "_array_small_type( PyArray_Descr * chktype , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 169, + "parameters": [ + "chktype", + "mintype" + ], + "start_line": 5325, + "end_line": 5357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_python_scalar_type", + "long_name": "_array_find_python_scalar_type( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 8, + "token_count": 120, + "parameters": [ + "op" + ], + "start_line": 5360, + "end_line": 5383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 28, + "token_count": 634, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5395, + "end_line": 5525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "Assign_Array", + "long_name": "Assign_Array( PyArrayObject * self , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 121, + "parameters": [ + "self", + "v" + ], + "start_line": 5528, + "end_line": 5551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 189, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5556, + "end_line": 5594, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 24, + "token_count": 373, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5599, + "end_line": 5666, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 68, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 5673, + "end_line": 5682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_bufferedcast", + "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 18, + "token_count": 525, + "parameters": [ + "out", + "in" + ], + "start_line": 5688, + "end_line": 5781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5791, + "end_line": 5837, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastTo", + "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 241, + "parameters": [ + "out", + "mp" + ], + "start_line": 5847, + "end_line": 5900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 31, + "token_count": 658, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5905, + "end_line": 6031, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 501, + "parameters": [ + "str" + ], + "start_line": 6035, + "end_line": 6143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 6147, + "end_line": 6187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 6191, + "end_line": 6329, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6333, + "end_line": 6376, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 21, + "token_count": 410, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6382, + "end_line": 6466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6471, + "end_line": 6474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ObjectType", + "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 69, + "parameters": [ + "op", + "minimum_type" + ], + "start_line": 6481, + "end_line": 6494, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6540, + "end_line": 6556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 84, + "parameters": [ + "op" + ], + "start_line": 6569, + "end_line": 6585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastSafely", + "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 39, + "token_count": 444, + "parameters": [ + "fromtype", + "totype" + ], + "start_line": 6591, + "end_line": 6679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 6684, + "end_line": 6712, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastScalar", + "long_name": "PyArray_CanCastScalar( PyTypeObject * from , PyTypeObject * to)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 3, + "token_count": 68, + "parameters": [ + "from", + "to" + ], + "start_line": 6718, + "end_line": 6728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterNew", + "long_name": "PyArray_IterNew( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 269, + "parameters": [ + "obj" + ], + "start_line": 6740, + "end_line": 6778, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterAllButAxis", + "long_name": "PyArray_IterAllButAxis( PyObject * obj , int axis)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 88, + "parameters": [ + "obj", + "axis" + ], + "start_line": 6786, + "end_line": 6803, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_next", + "long_name": "arrayiter_next( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 48, + "parameters": [ + "it" + ], + "start_line": 6808, + "end_line": 6818, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_dealloc", + "long_name": "arrayiter_dealloc( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "it" + ], + "start_line": 6821, + "end_line": 6825, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 6828, + "end_line": 6831, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_Bool", + "long_name": "iter_subscript_Bool( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 7, + "token_count": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6835, + "end_line": 6885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_int", + "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 52, + "complexity": 8, + "token_count": 352, + "parameters": [ + "self", + "ind" + ], + "start_line": 6888, + "end_line": 6942, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 6946, + "end_line": 7079, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 134, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_Bool", + "long_name": "iter_ass_sub_Bool( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7083, + "end_line": 7115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_int", + "long_name": "iter_ass_sub_int( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 8, + "token_count": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7118, + "end_line": 7160, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 7163, + "end_line": 7297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "iter_array", + "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 214, + "parameters": [ + "it", + "op" + ], + "start_line": 7314, + "end_line": 7359, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "iter_copy", + "long_name": "iter_copy( PyArrayIterObject * it , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "it", + "args" + ], + "start_line": 7364, + "end_line": 7368, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7384, + "end_line": 7399, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7464, + "end_line": 7480, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Broadcast", + "long_name": "PyArray_Broadcast( PyArrayMultiIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 13, + "token_count": 464, + "parameters": [ + "mit" + ], + "start_line": 7487, + "end_line": 7556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterReset", + "long_name": "PyArray_MapIterReset( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7560, + "end_line": 7597, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7603, + "end_line": 7647, + "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": 107, + "complexity": 23, + "token_count": 715, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7665, + "end_line": 7804, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 140, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7810, + "end_line": 7882, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 7885, + "end_line": 8011, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 8015, + "end_line": 8024, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiIterNew", + "long_name": "PyArray_MultiIterNew( int n , ...)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 10, + "token_count": 231, + "parameters": [ + "n" + ], + "start_line": 8095, + "end_line": 8144, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_new", + "long_name": "arraymultiter_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 11, + "token_count": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8147, + "end_line": 8192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_next", + "long_name": "arraymultiter_next( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 111, + "parameters": [ + "multi" + ], + "start_line": 8195, + "end_line": 8214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_dealloc", + "long_name": "arraymultiter_dealloc( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 41, + "parameters": [ + "multi" + ], + "start_line": 8217, + "end_line": 8224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_size_get", + "long_name": "arraymultiter_size_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8227, + "end_line": 8237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_index_get", + "long_name": "arraymultiter_index_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8240, + "end_line": 8250, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_shape_get", + "long_name": "arraymultiter_shape_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 8253, + "end_line": 8256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_iters_get", + "long_name": "arraymultiter_iters_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 8259, + "end_line": 8271, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_reset", + "long_name": "arraymultiter_reset( PyArrayMultiIterObject * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 38, + "parameters": [ + "self", + "args" + ], + "start_line": 8301, + "end_line": 8308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewFromType", + "long_name": "PyArray_DescrNewFromType( int type_num)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 1, + "token_count": 37, + "parameters": [ + "type_num" + ], + "start_line": 8367, + "end_line": 8376, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNew", + "long_name": "PyArray_DescrNew( PyArray_Descr * base)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 151, + "parameters": [ + "base" + ], + "start_line": 8394, + "end_line": 8416, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_dealloc", + "long_name": "arraydescr_dealloc( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 8422, + "end_line": 8432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_subdescr_get", + "long_name": "arraydescr_subdescr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 8451, + "end_line": 8459, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8462, + "end_line": 8477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8480, + "end_line": 8502, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8505, + "end_line": 8513, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8516, + "end_line": 8523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 8526, + "end_line": 8545, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isbuiltin_get", + "long_name": "arraydescr_isbuiltin_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 8552, + "end_line": 8559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isnative_get", + "long_name": "arraydescr_isnative_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 8562, + "end_line": 8569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_fields_get", + "long_name": "arraydescr_fields_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 8572, + "end_line": 8579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_new", + "long_name": "arraydescr_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 272, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8627, + "end_line": 8679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 8685, + "end_line": 8746, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8754, + "end_line": 8796, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewByteorder", + "long_name": "PyArray_DescrNewByteorder( PyArray_Descr * self , char newendian)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 386, + "parameters": [ + "self", + "newendian" + ], + "start_line": 8816, + "end_line": 8882, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_newbyteorder", + "long_name": "arraydescr_newbyteorder( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 47, + "parameters": [ + "self", + "args" + ], + "start_line": 8893, + "end_line": 8901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_str", + "long_name": "arraydescr_str( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 6, + "token_count": 287, + "parameters": [ + "self" + ], + "start_line": 8916, + "end_line": 8961, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_repr", + "long_name": "arraydescr_repr( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 8964, + "end_line": 8973, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_compare", + "long_name": "arraydescr_compare( PyArray_Descr * self , PyObject * other)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "other" + ], + "start_line": 8976, + "end_line": 8986, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 8993, + "end_line": 9000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 9003, + "end_line": 9034, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFlagsObject", + "long_name": "PyArray_NewFlagsObject( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 3, + "token_count": 96, + "parameters": [ + "obj" + ], + "start_line": 9112, + "end_line": 9129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_dealloc", + "long_name": "arrayflags_dealloc( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 9132, + "end_line": 9136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_forc_get", + "long_name": "arrayflags_forc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 9160, + "end_line": 9172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_fnc_get", + "long_name": "arrayflags_fnc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9175, + "end_line": 9187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_farray_get", + "long_name": "arrayflags_farray_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 9190, + "end_line": 9203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_num_get", + "long_name": "arrayflags_num_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 9206, + "end_line": 9209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_updateifcopy_set", + "long_name": "arrayflags_updateifcopy_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9213, + "end_line": 9225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_aligned_set", + "long_name": "arrayflags_aligned_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9228, + "end_line": 9241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_writeable_set", + "long_name": "arrayflags_writeable_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9244, + "end_line": 9257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_getitem", + "long_name": "arrayflags_getitem( PyArrayFlagsObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 75, + "complexity": 31, + "token_count": 431, + "parameters": [ + "self", + "ind" + ], + "start_line": 9313, + "end_line": 9388, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_setitem", + "long_name": "arrayflags_setitem( PyArrayFlagsObject * self , PyObject * ind , PyObject * item)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 14, + "token_count": 219, + "parameters": [ + "self", + "ind", + "item" + ], + "start_line": 9391, + "end_line": 9411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_torf_", + "long_name": "_torf_( int flags , int val)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 27, + "parameters": [ + "flags", + "val" + ], + "start_line": 9414, + "end_line": 9418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_print", + "long_name": "arrayflags_print( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 1, + "token_count": 77, + "parameters": [ + "self" + ], + "start_line": 9421, + "end_line": 9433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_new", + "long_name": "arrayflags_new( PyTypeObject * self , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9448, + "end_line": 9460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 76, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 65, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 99, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 134, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 207, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 241, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 291, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 319, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 344, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 387, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 427, + "end_line": 509, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 516, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 593, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Size", + "long_name": "PyArray_Size( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 33, + "parameters": [ + "op" + ], + "start_line": 614, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 638, + "end_line": 718, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyObject", + "long_name": "PyArray_CopyObject( PyArrayObject * dest , PyObject * src_object)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 722, + "end_line": 736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDimsAndDataAndDescr", + "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 137, + "parameters": [ + "nd", + "d", + "descr", + "data" + ], + "start_line": 749, + "end_line": 775, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDims", + "long_name": "PyArray_FromDims( int nd , int * d , int type)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "nd", + "d", + "type" + ], + "start_line": 781, + "end_line": 795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewCopy", + "long_name": "PyArray_NewCopy( PyArrayObject * m1 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 804, + "end_line": 824, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 17, + "token_count": 616, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 833, + "end_line": 949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 965, + "end_line": 968, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Return", + "long_name": "PyArray_Return( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 91, + "parameters": [ + "mp" + ], + "start_line": 978, + "end_line": 1000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDataType", + "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 9, + "token_count": 229, + "parameters": [ + "type" + ], + "start_line": 1014, + "end_line": 1054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDescrForType", + "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 214, + "parameters": [ + "typenum", + "descr" + ], + "start_line": 1069, + "end_line": 1110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToFile", + "long_name": "PyArray_ToFile( PyArrayObject * self , FILE * fp , char * sep , char * format)", + "filename": "arrayobject.c", + "nloc": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1117, + "end_line": 1208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToList", + "long_name": "PyArray_ToList( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self" + ], + "start_line": 1214, + "end_line": 1243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToString", + "long_name": "PyArray_ToString( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 170, + "parameters": [ + "self" + ], + "start_line": 1246, + "end_line": 1282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_dealloc", + "long_name": "array_dealloc( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 1291, + "end_line": 1328, + "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": 1335, + "end_line": 1343, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_big_item", + "long_name": "array_big_item( PyArrayObject * self , intp i)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 4, + "token_count": 151, + "parameters": [ + "self", + "i" + ], + "start_line": 1346, + "end_line": 1371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , _int_or_ssize_t i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1374, + "end_line": 1377, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_ass_big_item", + "long_name": "array_ass_big_item( PyArrayObject * self , intp i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1380, + "end_line": 1415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , _int_or_ssize_t i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1428, + "end_line": 1431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "slice_coerce_index", + "long_name": "slice_coerce_index( PyObject * o , intp * v)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "o", + "v" + ], + "start_line": 1437, + "end_line": 1445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "slice_GetIndices", + "long_name": "slice_GetIndices( PySliceObject * r , intp length , intp * start , intp * stop , intp * step , intp * slicelength)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 24, + "token_count": 376, + "parameters": [ + "r", + "length", + "start", + "stop", + "step", + "slicelength" + ], + "start_line": 1451, + "end_line": 1501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "parse_subindex", + "long_name": "parse_subindex( PyObject * op , intp * step_size , intp * n_steps , intp max)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "step_size", + "n_steps", + "max" + ], + "start_line": 1508, + "end_line": 1553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "parse_index", + "long_name": "parse_index( PyArrayObject * self , PyObject * op , intp * dimensions , intp * strides , intp * offset_ptr)", + "filename": "arrayobject.c", + "nloc": 88, + "complexity": 20, + "token_count": 539, + "parameters": [ + "self", + "op", + "dimensions", + "strides", + "offset_ptr" + ], + "start_line": 1557, + "end_line": 1651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "_swap_axes", + "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1654, + "end_line": 1691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1703, + "end_line": 1756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetMap", + "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 53, + "complexity": 12, + "token_count": 382, + "parameters": [ + "mit", + "op" + ], + "start_line": 1759, + "end_line": 1819, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 0 + }, + { + "name": "count_new_axes_0d", + "long_name": "count_new_axes_0d( PyObject * tuple)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 7, + "token_count": 124, + "parameters": [ + "tuple" + ], + "start_line": 1822, + "end_line": 1849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "add_new_axes_0d", + "long_name": "add_new_axes_0d( PyArrayObject * arr , int newaxis_count)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 121, + "parameters": [ + "arr", + "newaxis_count" + ], + "start_line": 1852, + "end_line": 1871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 1883, + "end_line": 1945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 107, + "complexity": 28, + "token_count": 674, + "parameters": [ + "self", + "op" + ], + "start_line": 1969, + "end_line": 2094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2109, + "end_line": 2214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 10, + "token_count": 182, + "parameters": [ + "self", + "op" + ], + "start_line": 2223, + "end_line": 2262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , _int_or_ssize_t * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2285, + "end_line": 2297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2300, + "end_line": 2315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2319, + "end_line": 2328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , _int_or_ssize_t segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2331, + "end_line": 2342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 1, + "token_count": 182, + "parameters": [ + "dict" + ], + "start_line": 2420, + "end_line": 2457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 2, + "token_count": 203, + "parameters": [], + "start_line": 2467, + "end_line": 2510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2513, + "end_line": 2536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericAccumulateFunction", + "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2540, + "end_line": 2563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericBinaryFunction", + "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 44, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2567, + "end_line": 2574, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericUnaryFunction", + "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 38, + "parameters": [ + "m1", + "op" + ], + "start_line": 2577, + "end_line": 2584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceBinaryFunction", + "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 46, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2587, + "end_line": 2595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceUnaryFunction", + "long_name": "PyArray_GenericInplaceUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 40, + "parameters": [ + "m1", + "op" + ], + "start_line": 2598, + "end_line": 2605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2608, + "end_line": 2611, + "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": 2614, + "end_line": 2617, + "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": 2620, + "end_line": 2623, + "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": 2626, + "end_line": 2629, + "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": 2632, + "end_line": 2635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power_is_scalar", + "long_name": "array_power_is_scalar( PyObject * o2 , double * exp)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 132, + "parameters": [ + "o2", + "exp" + ], + "start_line": 2642, + "end_line": 2665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "fast_scalar_power", + "long_name": "fast_scalar_power( PyArrayObject * a1 , PyObject * o2 , int inplace)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 12, + "token_count": 181, + "parameters": [ + "a1", + "o2", + "inplace" + ], + "start_line": 2669, + "end_line": 2703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2706, + "end_line": 2715, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2719, + "end_line": 2722, + "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": 2725, + "end_line": 2728, + "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": 2731, + "end_line": 2734, + "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": 2737, + "end_line": 2740, + "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": 2743, + "end_line": 2746, + "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": 2749, + "end_line": 2752, + "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": 2755, + "end_line": 2758, + "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": 2761, + "end_line": 2764, + "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": 2767, + "end_line": 2770, + "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": 2773, + "end_line": 2776, + "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": 2779, + "end_line": 2782, + "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": 2785, + "end_line": 2788, + "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": 2791, + "end_line": 2794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2797, + "end_line": 2806, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2809, + "end_line": 2812, + "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": 2815, + "end_line": 2818, + "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": 2821, + "end_line": 2824, + "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": 2827, + "end_line": 2830, + "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": 2833, + "end_line": 2836, + "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": 2839, + "end_line": 2842, + "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": 2845, + "end_line": 2848, + "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": 2851, + "end_line": 2855, + "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": 2858, + "end_line": 2862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_any_nonzero", + "long_name": "array_any_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 95, + "parameters": [ + "mp" + ], + "start_line": 2866, + "end_line": 2884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_array_nonzero", + "long_name": "_array_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 3, + "token_count": 72, + "parameters": [ + "mp" + ], + "start_line": 2887, + "end_line": 2904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_divmod", + "long_name": "array_divmod( PyArrayObject * op1 , PyObject * op2)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 89, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2909, + "end_line": 2924, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_int", + "long_name": "array_int( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2928, + "end_line": 2954, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_float", + "long_name": "array_float( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2957, + "end_line": 2982, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_long", + "long_name": "array_long( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 2985, + "end_line": 3007, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_oct", + "long_name": "array_oct( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3010, + "end_line": 3032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_hex", + "long_name": "array_hex( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3035, + "end_line": 3057, + "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": 3060, + "end_line": 3064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 12, + "token_count": 268, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 3125, + "end_line": 3166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 3170, + "end_line": 3192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 3195, + "end_line": 3207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dump_data", + "long_name": "dump_data( char ** string , int * n , int * max_n , char * data , int nd , intp * dimensions , intp * strides , PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 7, + "token_count": 310, + "parameters": [ + "string", + "n", + "max_n", + "data", + "nd", + "dimensions", + "strides", + "self" + ], + "start_line": 3240, + "end_line": 3287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_repr_builtin", + "long_name": "array_repr_builtin( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 4, + "token_count": 224, + "parameters": [ + "self" + ], + "start_line": 3290, + "end_line": 3326, + "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": 3335, + "end_line": 3352, + "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": 3355, + "end_line": 3367, + "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": 3370, + "end_line": 3382, + "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": 90, + "complexity": 19, + "token_count": 392, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3385, + "end_line": 3491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 171, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3494, + "end_line": 3523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntTupleFromIntp", + "long_name": "PyArray_IntTupleFromIntp( int len , intp * vals)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 109, + "parameters": [ + "len", + "vals" + ], + "start_line": 3529, + "end_line": 3549, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3557, + "end_line": 3592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3598, + "end_line": 3617, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 3621, + "end_line": 3639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 3642, + "end_line": 3659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_IsWriteable", + "long_name": "_IsWriteable( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 107, + "parameters": [ + "ap" + ], + "start_line": 3662, + "end_line": 3695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_UpdateFlags", + "long_name": "PyArray_UpdateFlags( PyArrayObject * ret , int flagmask)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 11, + "token_count": 157, + "parameters": [ + "ret", + "flagmask" + ], + "start_line": 3702, + "end_line": 3729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 117, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 3749, + "end_line": 3769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 3789, + "end_line": 3813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_New", + "long_name": "PyArray_New( PyTypeObject * subtype , int nd , intp * dims , int type_num , intp * strides , * data , int itemsize , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 4, + "token_count": 128, + "parameters": [ + "subtype", + "nd", + "dims", + "type_num", + "strides", + "data", + "itemsize", + "flags", + "obj" + ], + "start_line": 3819, + "end_line": 3841, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd , int isfortran)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 10, + "token_count": 311, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd", + "isfortran" + ], + "start_line": 3852, + "end_line": 3914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 132, + "complexity": 29, + "token_count": 785, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3922, + "end_line": 4088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 167, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape , int refcheck)", + "filename": "arrayobject.c", + "nloc": 83, + "complexity": 16, + "token_count": 511, + "parameters": [ + "self", + "newshape", + "refcheck" + ], + "start_line": 4101, + "end_line": 4200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 100, + "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": 4206, + "end_line": 4223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 8, + "token_count": 279, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4227, + "end_line": 4277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 21, + "token_count": 620, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4280, + "end_line": 4411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 132, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4415, + "end_line": 4423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ndim_get", + "long_name": "array_ndim_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4429, + "end_line": 4432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flags_get", + "long_name": "array_flags_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 4435, + "end_line": 4438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_get", + "long_name": "array_shape_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4441, + "end_line": 4444, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_set", + "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4448, + "end_line": 4477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "array_strides_get", + "long_name": "array_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4481, + "end_line": 4484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 9, + "token_count": 304, + "parameters": [ + "self", + "obj" + ], + "start_line": 4487, + "end_line": 4541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4545, + "end_line": 4552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4555, + "end_line": 4561, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4565, + "end_line": 4571, + "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": 4574, + "end_line": 4588, + "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": 4591, + "end_line": 4635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_itemsize_get", + "long_name": "array_itemsize_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 4639, + "end_line": 4642, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_size_get", + "long_name": "array_size_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4645, + "end_line": 4656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nbytes_get", + "long_name": "array_nbytes_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4659, + "end_line": 4670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4676, + "end_line": 4679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_descr_get", + "long_name": "array_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 4682, + "end_line": 4686, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "arg" + ], + "start_line": 4700, + "end_line": 4787, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 4790, + "end_line": 4808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_struct_get", + "long_name": "array_struct_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 2, + "token_count": 130, + "parameters": [ + "self" + ], + "start_line": 4811, + "end_line": 4829, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 4832, + "end_line": 4842, + "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": 4846, + "end_line": 4871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_real_set", + "long_name": "array_real_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 4, + "token_count": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 4875, + "end_line": 4908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_get", + "long_name": "array_imag_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self" + ], + "start_line": 4911, + "end_line": 4944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 4947, + "end_line": 4984, + "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": 4987, + "end_line": 4990, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flat_set", + "long_name": "array_flat_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 9, + "token_count": 348, + "parameters": [ + "self", + "val" + ], + "start_line": 4993, + "end_line": 5043, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_alloc", + "long_name": "array_alloc( PyTypeObject * type , int nitems)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 1, + "token_count": 39, + "parameters": [ + "type", + "nitems" + ], + "start_line": 5133, + "end_line": 5140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "discover_depth", + "long_name": "discover_depth( PyObject * s , int max , int stop_at_string , int stop_at_tuple)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 19, + "token_count": 243, + "parameters": [ + "s", + "max", + "stop_at_string", + "stop_at_tuple" + ], + "start_line": 5228, + "end_line": 5261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5264, + "end_line": 5286, + "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": 5293, + "end_line": 5319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_array_small_type", + "long_name": "_array_small_type( PyArray_Descr * chktype , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 169, + "parameters": [ + "chktype", + "mintype" + ], + "start_line": 5325, + "end_line": 5357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_python_scalar_type", + "long_name": "_array_find_python_scalar_type( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 8, + "token_count": 120, + "parameters": [ + "op" + ], + "start_line": 5360, + "end_line": 5383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 28, + "token_count": 634, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5395, + "end_line": 5525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "Assign_Array", + "long_name": "Assign_Array( PyArrayObject * self , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 121, + "parameters": [ + "self", + "v" + ], + "start_line": 5528, + "end_line": 5551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 189, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5556, + "end_line": 5594, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 24, + "token_count": 373, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5599, + "end_line": 5666, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 68, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 5673, + "end_line": 5682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_bufferedcast", + "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 18, + "token_count": 525, + "parameters": [ + "out", + "in" + ], + "start_line": 5688, + "end_line": 5781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5791, + "end_line": 5837, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastTo", + "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 241, + "parameters": [ + "out", + "mp" + ], + "start_line": 5847, + "end_line": 5900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 31, + "token_count": 658, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5905, + "end_line": 6031, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 501, + "parameters": [ + "str" + ], + "start_line": 6035, + "end_line": 6143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 6147, + "end_line": 6187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 6191, + "end_line": 6329, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6333, + "end_line": 6376, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 21, + "token_count": 410, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6382, + "end_line": 6466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6471, + "end_line": 6474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ObjectType", + "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 69, + "parameters": [ + "op", + "minimum_type" + ], + "start_line": 6481, + "end_line": 6494, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6540, + "end_line": 6556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 84, + "parameters": [ + "op" + ], + "start_line": 6569, + "end_line": 6585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastSafely", + "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 39, + "token_count": 444, + "parameters": [ + "fromtype", + "totype" + ], + "start_line": 6591, + "end_line": 6679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 6684, + "end_line": 6712, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterNew", + "long_name": "PyArray_IterNew( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 269, + "parameters": [ + "obj" + ], + "start_line": 6725, + "end_line": 6763, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterAllButAxis", + "long_name": "PyArray_IterAllButAxis( PyObject * obj , int axis)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 88, + "parameters": [ + "obj", + "axis" + ], + "start_line": 6771, + "end_line": 6788, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_next", + "long_name": "arrayiter_next( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 48, + "parameters": [ + "it" + ], + "start_line": 6793, + "end_line": 6803, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_dealloc", + "long_name": "arrayiter_dealloc( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "it" + ], + "start_line": 6806, + "end_line": 6810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 6813, + "end_line": 6816, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_Bool", + "long_name": "iter_subscript_Bool( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 7, + "token_count": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6820, + "end_line": 6870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_int", + "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 52, + "complexity": 8, + "token_count": 352, + "parameters": [ + "self", + "ind" + ], + "start_line": 6873, + "end_line": 6927, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 6931, + "end_line": 7064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 134, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_Bool", + "long_name": "iter_ass_sub_Bool( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7068, + "end_line": 7100, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_int", + "long_name": "iter_ass_sub_int( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 8, + "token_count": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7103, + "end_line": 7145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 7148, + "end_line": 7282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "iter_array", + "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 214, + "parameters": [ + "it", + "op" + ], + "start_line": 7299, + "end_line": 7344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "iter_copy", + "long_name": "iter_copy( PyArrayIterObject * it , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "it", + "args" + ], + "start_line": 7349, + "end_line": 7353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7369, + "end_line": 7384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7449, + "end_line": 7465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Broadcast", + "long_name": "PyArray_Broadcast( PyArrayMultiIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 13, + "token_count": 464, + "parameters": [ + "mit" + ], + "start_line": 7472, + "end_line": 7541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterReset", + "long_name": "PyArray_MapIterReset( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7545, + "end_line": 7582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7588, + "end_line": 7632, + "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": 107, + "complexity": 23, + "token_count": 715, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7650, + "end_line": 7789, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 140, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7795, + "end_line": 7867, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 7870, + "end_line": 7996, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 8000, + "end_line": 8009, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiIterNew", + "long_name": "PyArray_MultiIterNew( int n , ...)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 10, + "token_count": 231, + "parameters": [ + "n" + ], + "start_line": 8080, + "end_line": 8129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_new", + "long_name": "arraymultiter_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 11, + "token_count": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8132, + "end_line": 8177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_next", + "long_name": "arraymultiter_next( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 111, + "parameters": [ + "multi" + ], + "start_line": 8180, + "end_line": 8199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_dealloc", + "long_name": "arraymultiter_dealloc( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 41, + "parameters": [ + "multi" + ], + "start_line": 8202, + "end_line": 8209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_size_get", + "long_name": "arraymultiter_size_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8212, + "end_line": 8222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_index_get", + "long_name": "arraymultiter_index_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8225, + "end_line": 8235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_shape_get", + "long_name": "arraymultiter_shape_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 8238, + "end_line": 8241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_iters_get", + "long_name": "arraymultiter_iters_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 8244, + "end_line": 8256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_reset", + "long_name": "arraymultiter_reset( PyArrayMultiIterObject * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 38, + "parameters": [ + "self", + "args" + ], + "start_line": 8286, + "end_line": 8293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewFromType", + "long_name": "PyArray_DescrNewFromType( int type_num)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 1, + "token_count": 37, + "parameters": [ + "type_num" + ], + "start_line": 8352, + "end_line": 8361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNew", + "long_name": "PyArray_DescrNew( PyArray_Descr * base)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 151, + "parameters": [ + "base" + ], + "start_line": 8379, + "end_line": 8401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_dealloc", + "long_name": "arraydescr_dealloc( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 8407, + "end_line": 8417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_subdescr_get", + "long_name": "arraydescr_subdescr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 8436, + "end_line": 8444, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8447, + "end_line": 8462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8465, + "end_line": 8487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8490, + "end_line": 8498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8501, + "end_line": 8508, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 8511, + "end_line": 8530, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isbuiltin_get", + "long_name": "arraydescr_isbuiltin_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 8537, + "end_line": 8544, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isnative_get", + "long_name": "arraydescr_isnative_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 8547, + "end_line": 8554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_fields_get", + "long_name": "arraydescr_fields_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 8557, + "end_line": 8564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_new", + "long_name": "arraydescr_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 272, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8612, + "end_line": 8664, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 8670, + "end_line": 8731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8739, + "end_line": 8781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewByteorder", + "long_name": "PyArray_DescrNewByteorder( PyArray_Descr * self , char newendian)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 386, + "parameters": [ + "self", + "newendian" + ], + "start_line": 8801, + "end_line": 8867, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_newbyteorder", + "long_name": "arraydescr_newbyteorder( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 47, + "parameters": [ + "self", + "args" + ], + "start_line": 8878, + "end_line": 8886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_str", + "long_name": "arraydescr_str( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 6, + "token_count": 287, + "parameters": [ + "self" + ], + "start_line": 8901, + "end_line": 8946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_repr", + "long_name": "arraydescr_repr( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 8949, + "end_line": 8958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_compare", + "long_name": "arraydescr_compare( PyArray_Descr * self , PyObject * other)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "other" + ], + "start_line": 8961, + "end_line": 8971, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 8978, + "end_line": 8985, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 8988, + "end_line": 9019, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFlagsObject", + "long_name": "PyArray_NewFlagsObject( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 3, + "token_count": 96, + "parameters": [ + "obj" + ], + "start_line": 9097, + "end_line": 9114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_dealloc", + "long_name": "arrayflags_dealloc( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 9117, + "end_line": 9121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_forc_get", + "long_name": "arrayflags_forc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 9145, + "end_line": 9157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_fnc_get", + "long_name": "arrayflags_fnc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9160, + "end_line": 9172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_farray_get", + "long_name": "arrayflags_farray_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 9175, + "end_line": 9188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_num_get", + "long_name": "arrayflags_num_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 9191, + "end_line": 9194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_updateifcopy_set", + "long_name": "arrayflags_updateifcopy_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9198, + "end_line": 9210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_aligned_set", + "long_name": "arrayflags_aligned_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9213, + "end_line": 9226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_writeable_set", + "long_name": "arrayflags_writeable_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9229, + "end_line": 9242, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_getitem", + "long_name": "arrayflags_getitem( PyArrayFlagsObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 75, + "complexity": 31, + "token_count": 431, + "parameters": [ + "self", + "ind" + ], + "start_line": 9298, + "end_line": 9373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_setitem", + "long_name": "arrayflags_setitem( PyArrayFlagsObject * self , PyObject * ind , PyObject * item)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 14, + "token_count": 219, + "parameters": [ + "self", + "ind", + "item" + ], + "start_line": 9376, + "end_line": 9396, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_torf_", + "long_name": "_torf_( int flags , int val)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 27, + "parameters": [ + "flags", + "val" + ], + "start_line": 9399, + "end_line": 9403, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_print", + "long_name": "arrayflags_print( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 1, + "token_count": 77, + "parameters": [ + "self" + ], + "start_line": 9406, + "end_line": 9418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_new", + "long_name": "arrayflags_new( PyTypeObject * self , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9433, + "end_line": 9445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "PyArray_CanCastScalar", + "long_name": "PyArray_CanCastScalar( PyTypeObject * from , PyTypeObject * to)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 3, + "token_count": 68, + "parameters": [ + "from", + "to" + ], + "start_line": 6718, + "end_line": 6728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "nloc": 7551, + "complexity": 1629, + "token_count": 43835, + "diff_parsed": { + "added": [ + "/*OBJECT_API", + " See if array scalars can be cast.", + " */", + "static Bool", + "PyArray_CanCastScalar(PyTypeObject *from, PyTypeObject *to)", + "{", + "\tint fromtype;", + "\tint totype;", + "", + "\tfromtype = _typenum_fromtypeobj((PyObject *)from, 0);", + "\ttotype = _typenum_fromtypeobj((PyObject *)to, 0);", + "\tif (fromtype == PyArray_NOTYPE || totype == PyArray_NOTYPE)", + "\t\treturn FALSE;", + "\treturn (Bool) PyArray_CanCastSafely(fromtype, totype);", + "}" + ], + "deleted": [] + } + }, + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -14,20 +14,24 @@\n \n /* The general strategy is to\n \n-1) Check to see if it's a scalar of the same type and do \n- a quick exit. \n-2) Check to see if it's a Python scalar and do a\n- quick exit.\n-3) Check to see if it's another array scalar, and cast it\n- and exit\n-4) Check to see if it's a 0-d array and convert it \n- and exit.\n+1) Make self the array scalar and \"other\" the other data-type\n+2) If both are the same data-type, then do a quick exit.\n+3) If other is another array scalar, then\n+ a) If it can be cast then cast and calculate\n+ b) Otherwise, return NotImplemented \n+ (or call the appropriate function on other... ---\n+ shortcut what Python will do anyway). \n+4) If other is a 0-d array\n+ -- Cast it to an array scalar and do #3\n+5) If other is a Python scalar\n+ -- Cast it to an array scalar and do #3\n 5) Go through the ufunc machinery for all other cases. \n \n */\n \n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n+#Name=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble##\n **/\n \n static PyObject *\n", + "added_lines": 12, + "deleted_lines": 8, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n */\n\n#include \"numpy/arrayobject.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n/* The general strategy is to\n\n1) Make self the array scalar and \"other\" the other data-type\n2) If both are the same data-type, then do a quick exit.\n3) If other is another array scalar, then\n a) If it can be cast then cast and calculate\n b) Otherwise, return NotImplemented \n (or call the appropriate function on other... ---\n shortcut what Python will do anyway). \n4) If other is a 0-d array\n -- Cast it to an array scalar and do #3\n5) If other is a Python scalar\n -- Cast it to an array scalar and do #3\n5) Go through the ufunc machinery for all other cases. \n\n*/\n\n/**begin repeat\n#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n#Name=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble##\n**/\n\nstatic PyObject *\n@name@_add(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_subtract(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_multiply(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_divide(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_remainder(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_divmod(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_negative(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_copy(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_absolute(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_nonzero_number(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_invert(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_lshift(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_rshift(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_and(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_xor(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_or(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_int(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_long(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_float(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_oct(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_hex(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_floor_divide(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_true_divide(PyObject *a, PyObject *b)\n{\n}\n\n#if PY_VERSION_HEX >= 0x02050000\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n}\n#endif\n\n\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n}\n/**end repeat**/\n\n\n\n\n/**begin repeat\n#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_copy, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero_number, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n\t(lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n\nstatic void\nadd_scalarmath(void)\n{\n/**begin repeat\n#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n**/\n\tPyArr@NAME@Type_Type.tp_as_number = @name@_as_number;\n\tPyArr@NAME@Type_Type.tp_richcompare = @name@_richcompare;\n/**end repeat**/\n}\n\n\n\nstatic struct PyMethodDef methods[] = {\n\t{\"alter_pyscalars\", (PyCFunction) alter_pyscalars,\n\t METH_VARARGS , doc_alterpyscalars},\n\t{NULL, NULL, 0}\n};\n\nDL_EXPORT(void) initscalarmath(void) {\n\tPyObject *m;\n\n\tm = Py_initModule(\"scalarmath\", methods);\n\t\n\tif (import_array() < 0) return;\n\tif (import_umath() < 0) return;\n\n\tadd_scalarmath();\n\t\n\treturn;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n */\n\n#include \"numpy/arrayobject.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n/* The general strategy is to\n\n1) Check to see if it's a scalar of the same type and do \n a quick exit. \n2) Check to see if it's a Python scalar and do a\n quick exit.\n3) Check to see if it's another array scalar, and cast it\n and exit\n4) Check to see if it's a 0-d array and convert it \n and exit.\n5) Go through the ufunc machinery for all other cases. \n\n*/\n\n/**begin repeat\n#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n\nstatic PyObject *\n@name@_add(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_subtract(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_multiply(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_divide(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_remainder(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_divmod(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_negative(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_copy(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_absolute(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_nonzero_number(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_invert(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_lshift(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_rshift(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_and(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_xor(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_or(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_int(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_long(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_float(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_oct(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_hex(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_floor_divide(PyObject *a, PyObject *b)\n{\n}\n\nstatic PyObject *\n@name@_true_divide(PyObject *a, PyObject *b)\n{\n}\n\n#if PY_VERSION_HEX >= 0x02050000\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n}\n#endif\n\n\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n}\n/**end repeat**/\n\n\n\n\n/**begin repeat\n#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_copy, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero_number, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n\t(lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n\nstatic void\nadd_scalarmath(void)\n{\n/**begin repeat\n#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#\n#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n**/\n\tPyArr@NAME@Type_Type.tp_as_number = @name@_as_number;\n\tPyArr@NAME@Type_Type.tp_richcompare = @name@_richcompare;\n/**end repeat**/\n}\n\n\n\nstatic struct PyMethodDef methods[] = {\n\t{\"alter_pyscalars\", (PyCFunction) alter_pyscalars,\n\t METH_VARARGS , doc_alterpyscalars},\n\t{NULL, NULL, 0}\n};\n\nDL_EXPORT(void) initscalarmath(void) {\n\tPyObject *m;\n\n\tm = Py_initModule(\"scalarmath\", methods);\n\t\n\tif (import_array() < 0) return;\n\tif (import_umath() < 0) return;\n\n\tadd_scalarmath();\n\t\n\treturn;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "1) Make self the array scalar and \"other\" the other data-type", + "2) If both are the same data-type, then do a quick exit.", + "3) If other is another array scalar, then", + " a) If it can be cast then cast and calculate", + " b) Otherwise, return NotImplemented", + " (or call the appropriate function on other... ---", + " shortcut what Python will do anyway).", + "4) If other is a 0-d array", + " -- Cast it to an array scalar and do #3", + "5) If other is a Python scalar", + " -- Cast it to an array scalar and do #3", + "#Name=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble##" + ], + "deleted": [ + "1) Check to see if it's a scalar of the same type and do", + " a quick exit.", + "2) Check to see if it's a Python scalar and do a", + " quick exit.", + "3) Check to see if it's another array scalar, and cast it", + " and exit", + "4) Check to see if it's a 0-d array and convert it", + " and exit." + ] + } + } + ] + }, + { + "hash": "267a8f5d47beb4ca8badd7859b044581708d7b52", + "msg": "change use of deprecated NewAxis to newaxis", + "author": { + "name": "Tim Leslie", + "email": "tim.leslie@gmail.com" + }, + "committer": { + "name": "Tim Leslie", + "email": "tim.leslie@gmail.com" + }, + "author_date": "2006-03-18T04:18:57+00:00", + "author_timezone": 0, + "committer_date": "2006-03-18T04:18:57+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "116482559bc3a3856022b0a7b25429605d351c02" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 6, + "insertions": 6, + "lines": 12, + "files": 3, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/lib/index_tricks.py", + "new_path": "numpy/lib/index_tricks.py", + "filename": "index_tricks.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -113,11 +113,11 @@ def __getitem__(self,key):\n step = (key[k].stop - start)/float(step-1)\n nn[k] = (nn[k]*step+start)\n if self.sparse:\n- slobj = [_nx.NewAxis]*len(size)\n+ slobj = [_nx.newaxis]*len(size)\n for k in range(len(size)):\n slobj[k] = slice(None,None)\n nn[k] = nn[k][slobj]\n- slobj[k] = _nx.NewAxis\n+ slobj[k] = _nx.newaxis\n return nn\n except (IndexError, TypeError):\n step = key.step\n", + "added_lines": 2, + "deleted_lines": 2, + "source_code": "## Automatically adapted for numpy Sep 19, 2005 by convertcode.py\n\n__all__ = ['mgrid','ogrid','r_', 'c_', 'index_exp', 'ix_','ndenumerate','ndindex']\n\nimport sys\nimport types\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import asarray, ScalarType\n\nimport function_base\nimport numpy.core.defmatrix as matrix\nmakemat = matrix.matrix\n\ndef ix_(*args):\n \"\"\" Construct an open mesh from multiple sequences.\n\n This function takes n 1-d sequences and returns n outputs with n\n dimensions each such that the shape is 1 in all but one dimension and\n the dimension with the non-unit shape value cycles through all n\n dimensions.\n\n Using ix_() one can quickly construct index arrays that will index\n the cross product.\n\n a[ix_([1,3,7],[2,5,8])] returns the array\n\n a[1,2] a[1,5] a[1,8]\n a[3,2] a[3,5] a[3,8]\n a[7,2] a[7,5] a[7,8]\n \"\"\"\n out = []\n nd = len(args)\n baseshape = [1]*nd\n for k in range(nd):\n new = _nx.array(args[k])\n if (new.ndim != 1):\n raise ValueError, \"Cross index must be 1 dimensional\"\n baseshape[k] = len(new)\n new.shape = tuple(baseshape)\n out.append(new)\n baseshape[k] = 1\n return tuple(out)\n\nclass nd_grid(object):\n \"\"\" Construct a \"meshgrid\" in N-dimensions.\n\n grid = nd_grid() creates an instance which will return a mesh-grid\n when indexed. The dimension and number of the output arrays are equal\n to the number of indexing dimensions. If the step length is not a\n complex number, then the stop is not inclusive.\n\n However, if the step length is a COMPLEX NUMBER (e.g. 5j), then the\n integer part of it's magnitude is interpreted as specifying the\n number of points to create between the start and stop values, where\n the stop value IS INCLUSIVE.\n\n If instantiated with an argument of sparse=True, the mesh-grid is\n open (or not fleshed out) so that only one-dimension of each returned\n argument is greater than 1\n\n Example:\n\n >>> mgrid = nd_grid()\n >>> mgrid[0:5,0:5]\n array([[[0, 0, 0, 0, 0],\n [1, 1, 1, 1, 1],\n [2, 2, 2, 2, 2],\n [3, 3, 3, 3, 3],\n [4, 4, 4, 4, 4]],\n [[0, 1, 2, 3, 4],\n [0, 1, 2, 3, 4],\n [0, 1, 2, 3, 4],\n [0, 1, 2, 3, 4],\n [0, 1, 2, 3, 4]]])\n >>> mgrid[-1:1:5j]\n array([-1. , -0.5, 0. , 0.5, 1. ])\n\n >>> ogrid = nd_grid(sparse=True)\n >>> ogrid[0:5,0:5]\n [array([[0],[1],[2],[3],[4]]), array([[0, 1, 2, 3, 4]])]\n \"\"\"\n def __init__(self, sparse=False):\n self.sparse = sparse\n def __getitem__(self,key):\n try:\n size = []\n typecode = _nx.Int\n for k in range(len(key)):\n step = key[k].step\n start = key[k].start\n if start is None: start=0\n if step is None: step=1\n if type(step) is type(1j):\n size.append(int(abs(step)))\n typecode = _nx.Float\n else:\n size.append(int((key[k].stop - start)/(step*1.0)))\n if isinstance(step,types.FloatType) or \\\n isinstance(start, types.FloatType) or \\\n isinstance(key[k].stop, types.FloatType):\n typecode = _nx.Float\n if self.sparse:\n nn = map(lambda x,t: _nx.arange(x,dtype=t),size,(typecode,)*len(size))\n else:\n nn = _nx.indices(size,typecode)\n for k in range(len(size)):\n step = key[k].step\n start = key[k].start\n if start is None: start=0\n if step is None: step=1\n if type(step) is type(1j):\n step = int(abs(step))\n step = (key[k].stop - start)/float(step-1)\n nn[k] = (nn[k]*step+start)\n if self.sparse:\n slobj = [_nx.newaxis]*len(size)\n for k in range(len(size)):\n slobj[k] = slice(None,None)\n nn[k] = nn[k][slobj]\n slobj[k] = _nx.newaxis\n return nn\n except (IndexError, TypeError):\n step = key.step\n stop = key.stop\n start = key.start\n if start is None: start = 0\n if type(step) is type(1j):\n step = abs(step)\n length = int(step)\n step = (key.stop-start)/float(step-1)\n stop = key.stop+step\n return _nx.arange(0,length,1,_nx.Float)*step + start\n else:\n return _nx.arange(start, stop, step)\n\n def __getslice__(self,i,j):\n return _nx.arange(i,j)\n\n def __len__(self):\n return 0\n\nmgrid = nd_grid(sparse=False)\nogrid = nd_grid(sparse=True)\n\nclass concatenator(object):\n \"\"\"Translates slice objects to concatenation along an axis.\n \"\"\"\n def _retval(self, res):\n if self.matrix:\n oldndim = res.ndim\n res = makemat(res)\n if oldndim == 1 and self.col:\n res = res.T\n self.axis=self._axis\n self.matrix=self._matrix\n self.col=0\n return res\n\n def __init__(self, axis=0, matrix=False):\n self._axis = axis\n self._matrix = matrix\n self.axis = axis\n self.matrix = matrix\n self.col = 0\n\n def __getitem__(self,key):\n if isinstance(key,types.StringType):\n frame = sys._getframe().f_back\n mymat = matrix.bmat(key,frame.f_globals,frame.f_locals)\n return mymat\n if type(key) is not types.TupleType:\n key = (key,)\n objs = []\n scalars = []\n final_dtypedescr = None\n for k in range(len(key)):\n scalar = False\n if type(key[k]) is types.SliceType:\n step = key[k].step\n start = key[k].start\n stop = key[k].stop\n if start is None: start = 0\n if step is None:\n step = 1\n if type(step) is type(1j):\n size = int(abs(step))\n newobj = function_base.linspace(start, stop, num=size)\n else:\n newobj = _nx.arange(start, stop, step)\n elif type(key[k]) is types.StringType:\n if (key[k] in 'rc'):\n self.matrix = True\n self.col = (key[k] == 'c')\n continue\n try:\n self.axis = int(key[k])\n continue\n except:\n raise ValueError, \"Unknown special directive.\"\n elif type(key[k]) in ScalarType:\n newobj = asarray([key[k]])\n scalars.append(k)\n scalar = True\n else:\n newobj = key[k]\n objs.append(newobj)\n if isinstance(newobj, _nx.ndarray) and not scalar:\n if final_dtypedescr is None:\n final_dtypedescr = newobj.dtype\n elif newobj.dtype > final_dtypedescr:\n final_dtypedescr = newobj.dtype\n if final_dtypedescr is not None:\n for k in scalars:\n objs[k] = objs[k].astype(final_dtypedescr)\n res = _nx.concatenate(tuple(objs),axis=self.axis)\n return self._retval(res)\n\n def __getslice__(self,i,j):\n res = _nx.arange(i,j)\n return self._retval(res)\n\n def __len__(self):\n return 0\n\n# separate classes are used here instead of just making r_ = concatentor(0),\n# etc. because otherwise we couldn't get the doc string to come out right\n# in help(r_)\n\nclass r_class(concatenator):\n \"\"\"Translates slice objects to concatenation along the first axis.\n\n For example:\n >>> r_[array([1,2,3]), 0, 0, array([4,5,6])]\n array([1, 2, 3, 0, 0, 4, 5, 6])\n \"\"\"\n def __init__(self):\n concatenator.__init__(self, 0)\n\nr_ = r_class()\n\nclass c_class(concatenator):\n \"\"\"Translates slice objects to concatenation along the second axis.\n\n For example:\n >>> c_[array([[1],[2],[3]]), array([[4],[5],[6]])]\n array([[1, 4],\n [2, 5],\n [3, 6]])\n \"\"\"\n def __init__(self):\n concatenator.__init__(self, -1)\n\nc_ = c_class()\n\n\nclass ndenumerate(object):\n \"\"\"\n A simple nd index iterator over an array.\n\n Example:\n >>> a = array([[1,2],[3,4]])\n >>> for index, x in ndenumerate(a):\n ... print index, x\n (0, 0) 1\n (0, 1) 2\n (1, 0) 3\n (1, 1) 4\n \"\"\"\n def __init__(self, arr):\n self.iter = asarray(arr).flat\n\n def next(self):\n return self.iter.coords, self.iter.next()\n\n def __iter__(self):\n return self\n\nclass ndindex(object):\n \"\"\"Pass in a sequence of integers corresponding\n to the number of dimensions in the counter. This iterator\n will then return an N-dimensional counter.\n\n Example:\n >>> for index in ndindex(4,3,2):\n print index\n (0,0,0)\n (0,0,1)\n (0,1,0)\n ...\n (3,1,1)\n (3,2,0)\n (3,2,1)\n \"\"\"\n\n def __init__(self, *args):\n self.nd = len(args)\n self.ind = [0]*self.nd\n self.index = 0\n self.maxvals = args\n tot = 1\n for k in range(self.nd):\n tot *= args[k]\n self.total = tot\n\n def _incrementone(self, axis):\n if (axis < 0): # base case\n return\n if (self.ind[axis] < self.maxvals[axis]-1):\n self.ind[axis]+=1\n else:\n self.ind[axis] = 0\n self._incrementone(axis-1)\n\n def ndincr(self):\n self._incrementone(self.nd-1)\n\n def next(self):\n if (self.index >= self.total):\n raise StopIteration\n val = tuple(self.ind)\n self.index+=1\n self.ndincr()\n return val\n\n def __iter__(self):\n return self\n\n\n# You can do all this with slice() plus a few special objects,\n# but there's a lot to remember. This version is simpler because\n# it uses the standard array indexing syntax.\n#\n# Written by Konrad Hinsen \n# last revision: 1999-7-23\n#\n# Cosmetic changes by T. Oliphant 2001\n#\n#\n# This module provides a convenient method for constructing\n# array indices algorithmically. It provides one importable object,\n# 'index_expression'.\n\nclass _index_expression_class(object):\n \"\"\"\n A nicer way to build up index tuples for arrays.\n\n For any index combination, including slicing and axis insertion,\n 'a[indices]' is the same as 'a[index_exp[indices]]' for any\n array 'a'. However, 'index_exp[indices]' can be used anywhere\n in Python code and returns a tuple of slice objects that can be\n used in the construction of complex index expressions.\n \"\"\"\n maxint = sys.maxint\n\n def __getitem__(self, item):\n if type(item) != type(()):\n return (item,)\n else:\n return item\n\n def __len__(self):\n return self.maxint\n\n def __getslice__(self, start, stop):\n if stop == self.maxint:\n stop = None\n return self[start:stop:None]\n\nindex_exp = _index_expression_class()\n\n# End contribution from Konrad.\n", + "source_code_before": "## Automatically adapted for numpy Sep 19, 2005 by convertcode.py\n\n__all__ = ['mgrid','ogrid','r_', 'c_', 'index_exp', 'ix_','ndenumerate','ndindex']\n\nimport sys\nimport types\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import asarray, ScalarType\n\nimport function_base\nimport numpy.core.defmatrix as matrix\nmakemat = matrix.matrix\n\ndef ix_(*args):\n \"\"\" Construct an open mesh from multiple sequences.\n\n This function takes n 1-d sequences and returns n outputs with n\n dimensions each such that the shape is 1 in all but one dimension and\n the dimension with the non-unit shape value cycles through all n\n dimensions.\n\n Using ix_() one can quickly construct index arrays that will index\n the cross product.\n\n a[ix_([1,3,7],[2,5,8])] returns the array\n\n a[1,2] a[1,5] a[1,8]\n a[3,2] a[3,5] a[3,8]\n a[7,2] a[7,5] a[7,8]\n \"\"\"\n out = []\n nd = len(args)\n baseshape = [1]*nd\n for k in range(nd):\n new = _nx.array(args[k])\n if (new.ndim != 1):\n raise ValueError, \"Cross index must be 1 dimensional\"\n baseshape[k] = len(new)\n new.shape = tuple(baseshape)\n out.append(new)\n baseshape[k] = 1\n return tuple(out)\n\nclass nd_grid(object):\n \"\"\" Construct a \"meshgrid\" in N-dimensions.\n\n grid = nd_grid() creates an instance which will return a mesh-grid\n when indexed. The dimension and number of the output arrays are equal\n to the number of indexing dimensions. If the step length is not a\n complex number, then the stop is not inclusive.\n\n However, if the step length is a COMPLEX NUMBER (e.g. 5j), then the\n integer part of it's magnitude is interpreted as specifying the\n number of points to create between the start and stop values, where\n the stop value IS INCLUSIVE.\n\n If instantiated with an argument of sparse=True, the mesh-grid is\n open (or not fleshed out) so that only one-dimension of each returned\n argument is greater than 1\n\n Example:\n\n >>> mgrid = nd_grid()\n >>> mgrid[0:5,0:5]\n array([[[0, 0, 0, 0, 0],\n [1, 1, 1, 1, 1],\n [2, 2, 2, 2, 2],\n [3, 3, 3, 3, 3],\n [4, 4, 4, 4, 4]],\n [[0, 1, 2, 3, 4],\n [0, 1, 2, 3, 4],\n [0, 1, 2, 3, 4],\n [0, 1, 2, 3, 4],\n [0, 1, 2, 3, 4]]])\n >>> mgrid[-1:1:5j]\n array([-1. , -0.5, 0. , 0.5, 1. ])\n\n >>> ogrid = nd_grid(sparse=True)\n >>> ogrid[0:5,0:5]\n [array([[0],[1],[2],[3],[4]]), array([[0, 1, 2, 3, 4]])]\n \"\"\"\n def __init__(self, sparse=False):\n self.sparse = sparse\n def __getitem__(self,key):\n try:\n size = []\n typecode = _nx.Int\n for k in range(len(key)):\n step = key[k].step\n start = key[k].start\n if start is None: start=0\n if step is None: step=1\n if type(step) is type(1j):\n size.append(int(abs(step)))\n typecode = _nx.Float\n else:\n size.append(int((key[k].stop - start)/(step*1.0)))\n if isinstance(step,types.FloatType) or \\\n isinstance(start, types.FloatType) or \\\n isinstance(key[k].stop, types.FloatType):\n typecode = _nx.Float\n if self.sparse:\n nn = map(lambda x,t: _nx.arange(x,dtype=t),size,(typecode,)*len(size))\n else:\n nn = _nx.indices(size,typecode)\n for k in range(len(size)):\n step = key[k].step\n start = key[k].start\n if start is None: start=0\n if step is None: step=1\n if type(step) is type(1j):\n step = int(abs(step))\n step = (key[k].stop - start)/float(step-1)\n nn[k] = (nn[k]*step+start)\n if self.sparse:\n slobj = [_nx.NewAxis]*len(size)\n for k in range(len(size)):\n slobj[k] = slice(None,None)\n nn[k] = nn[k][slobj]\n slobj[k] = _nx.NewAxis\n return nn\n except (IndexError, TypeError):\n step = key.step\n stop = key.stop\n start = key.start\n if start is None: start = 0\n if type(step) is type(1j):\n step = abs(step)\n length = int(step)\n step = (key.stop-start)/float(step-1)\n stop = key.stop+step\n return _nx.arange(0,length,1,_nx.Float)*step + start\n else:\n return _nx.arange(start, stop, step)\n\n def __getslice__(self,i,j):\n return _nx.arange(i,j)\n\n def __len__(self):\n return 0\n\nmgrid = nd_grid(sparse=False)\nogrid = nd_grid(sparse=True)\n\nclass concatenator(object):\n \"\"\"Translates slice objects to concatenation along an axis.\n \"\"\"\n def _retval(self, res):\n if self.matrix:\n oldndim = res.ndim\n res = makemat(res)\n if oldndim == 1 and self.col:\n res = res.T\n self.axis=self._axis\n self.matrix=self._matrix\n self.col=0\n return res\n\n def __init__(self, axis=0, matrix=False):\n self._axis = axis\n self._matrix = matrix\n self.axis = axis\n self.matrix = matrix\n self.col = 0\n\n def __getitem__(self,key):\n if isinstance(key,types.StringType):\n frame = sys._getframe().f_back\n mymat = matrix.bmat(key,frame.f_globals,frame.f_locals)\n return mymat\n if type(key) is not types.TupleType:\n key = (key,)\n objs = []\n scalars = []\n final_dtypedescr = None\n for k in range(len(key)):\n scalar = False\n if type(key[k]) is types.SliceType:\n step = key[k].step\n start = key[k].start\n stop = key[k].stop\n if start is None: start = 0\n if step is None:\n step = 1\n if type(step) is type(1j):\n size = int(abs(step))\n newobj = function_base.linspace(start, stop, num=size)\n else:\n newobj = _nx.arange(start, stop, step)\n elif type(key[k]) is types.StringType:\n if (key[k] in 'rc'):\n self.matrix = True\n self.col = (key[k] == 'c')\n continue\n try:\n self.axis = int(key[k])\n continue\n except:\n raise ValueError, \"Unknown special directive.\"\n elif type(key[k]) in ScalarType:\n newobj = asarray([key[k]])\n scalars.append(k)\n scalar = True\n else:\n newobj = key[k]\n objs.append(newobj)\n if isinstance(newobj, _nx.ndarray) and not scalar:\n if final_dtypedescr is None:\n final_dtypedescr = newobj.dtype\n elif newobj.dtype > final_dtypedescr:\n final_dtypedescr = newobj.dtype\n if final_dtypedescr is not None:\n for k in scalars:\n objs[k] = objs[k].astype(final_dtypedescr)\n res = _nx.concatenate(tuple(objs),axis=self.axis)\n return self._retval(res)\n\n def __getslice__(self,i,j):\n res = _nx.arange(i,j)\n return self._retval(res)\n\n def __len__(self):\n return 0\n\n# separate classes are used here instead of just making r_ = concatentor(0),\n# etc. because otherwise we couldn't get the doc string to come out right\n# in help(r_)\n\nclass r_class(concatenator):\n \"\"\"Translates slice objects to concatenation along the first axis.\n\n For example:\n >>> r_[array([1,2,3]), 0, 0, array([4,5,6])]\n array([1, 2, 3, 0, 0, 4, 5, 6])\n \"\"\"\n def __init__(self):\n concatenator.__init__(self, 0)\n\nr_ = r_class()\n\nclass c_class(concatenator):\n \"\"\"Translates slice objects to concatenation along the second axis.\n\n For example:\n >>> c_[array([[1],[2],[3]]), array([[4],[5],[6]])]\n array([[1, 4],\n [2, 5],\n [3, 6]])\n \"\"\"\n def __init__(self):\n concatenator.__init__(self, -1)\n\nc_ = c_class()\n\n\nclass ndenumerate(object):\n \"\"\"\n A simple nd index iterator over an array.\n\n Example:\n >>> a = array([[1,2],[3,4]])\n >>> for index, x in ndenumerate(a):\n ... print index, x\n (0, 0) 1\n (0, 1) 2\n (1, 0) 3\n (1, 1) 4\n \"\"\"\n def __init__(self, arr):\n self.iter = asarray(arr).flat\n\n def next(self):\n return self.iter.coords, self.iter.next()\n\n def __iter__(self):\n return self\n\nclass ndindex(object):\n \"\"\"Pass in a sequence of integers corresponding\n to the number of dimensions in the counter. This iterator\n will then return an N-dimensional counter.\n\n Example:\n >>> for index in ndindex(4,3,2):\n print index\n (0,0,0)\n (0,0,1)\n (0,1,0)\n ...\n (3,1,1)\n (3,2,0)\n (3,2,1)\n \"\"\"\n\n def __init__(self, *args):\n self.nd = len(args)\n self.ind = [0]*self.nd\n self.index = 0\n self.maxvals = args\n tot = 1\n for k in range(self.nd):\n tot *= args[k]\n self.total = tot\n\n def _incrementone(self, axis):\n if (axis < 0): # base case\n return\n if (self.ind[axis] < self.maxvals[axis]-1):\n self.ind[axis]+=1\n else:\n self.ind[axis] = 0\n self._incrementone(axis-1)\n\n def ndincr(self):\n self._incrementone(self.nd-1)\n\n def next(self):\n if (self.index >= self.total):\n raise StopIteration\n val = tuple(self.ind)\n self.index+=1\n self.ndincr()\n return val\n\n def __iter__(self):\n return self\n\n\n# You can do all this with slice() plus a few special objects,\n# but there's a lot to remember. This version is simpler because\n# it uses the standard array indexing syntax.\n#\n# Written by Konrad Hinsen \n# last revision: 1999-7-23\n#\n# Cosmetic changes by T. Oliphant 2001\n#\n#\n# This module provides a convenient method for constructing\n# array indices algorithmically. It provides one importable object,\n# 'index_expression'.\n\nclass _index_expression_class(object):\n \"\"\"\n A nicer way to build up index tuples for arrays.\n\n For any index combination, including slicing and axis insertion,\n 'a[indices]' is the same as 'a[index_exp[indices]]' for any\n array 'a'. However, 'index_exp[indices]' can be used anywhere\n in Python code and returns a tuple of slice objects that can be\n used in the construction of complex index expressions.\n \"\"\"\n maxint = sys.maxint\n\n def __getitem__(self, item):\n if type(item) != type(()):\n return (item,)\n else:\n return item\n\n def __len__(self):\n return self.maxint\n\n def __getslice__(self, start, stop):\n if stop == self.maxint:\n stop = None\n return self[start:stop:None]\n\nindex_exp = _index_expression_class()\n\n# End contribution from Konrad.\n", + "methods": [ + { + "name": "ix_", + "long_name": "ix_( * args )", + "filename": "index_tricks.py", + "nloc": 13, + "complexity": 3, + "token_count": 90, + "parameters": [ + "args" + ], + "start_line": 14, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , sparse = False )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "sparse" + ], + "start_line": 82, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , key )", + "filename": "index_tricks.py", + "nloc": 51, + "complexity": 18, + "token_count": 472, + "parameters": [ + "self", + "key" + ], + "start_line": 84, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 136, + "end_line": 137, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 139, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_retval", + "long_name": "_retval( self , res )", + "filename": "index_tricks.py", + "nloc": 10, + "complexity": 4, + "token_count": 58, + "parameters": [ + "self", + "res" + ], + "start_line": 148, + "end_line": 157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , axis = 0 , matrix = False )", + "filename": "index_tricks.py", + "nloc": 6, + "complexity": 1, + "token_count": 38, + "parameters": [ + "self", + "axis", + "matrix" + ], + "start_line": 159, + "end_line": 164, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , key )", + "filename": "index_tricks.py", + "nloc": 51, + "complexity": 18, + "token_count": 377, + "parameters": [ + "self", + "key" + ], + "start_line": 166, + "end_line": 216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "index_tricks.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 218, + "end_line": 220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 222, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 236, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 250, + "end_line": 251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , arr )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "arr" + ], + "start_line": 269, + "end_line": 270, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "next", + "long_name": "next( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 272, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__iter__", + "long_name": "__iter__( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 275, + "end_line": 276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , * args )", + "filename": "index_tricks.py", + "nloc": 9, + "complexity": 2, + "token_count": 62, + "parameters": [ + "self", + "args" + ], + "start_line": 295, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "_incrementone", + "long_name": "_incrementone( self , axis )", + "filename": "index_tricks.py", + "nloc": 8, + "complexity": 3, + "token_count": 60, + "parameters": [ + "self", + "axis" + ], + "start_line": 305, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "ndincr", + "long_name": "ndincr( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 314, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "next", + "long_name": "next( self )", + "filename": "index_tricks.py", + "nloc": 7, + "complexity": 2, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 317, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "__iter__", + "long_name": "__iter__( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 325, + "end_line": 326, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , item )", + "filename": "index_tricks.py", + "nloc": 5, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self", + "item" + ], + "start_line": 355, + "end_line": 359, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 361, + "end_line": 362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , start , stop )", + "filename": "index_tricks.py", + "nloc": 4, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self", + "start", + "stop" + ], + "start_line": 364, + "end_line": 367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "ix_", + "long_name": "ix_( * args )", + "filename": "index_tricks.py", + "nloc": 13, + "complexity": 3, + "token_count": 90, + "parameters": [ + "args" + ], + "start_line": 14, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , sparse = False )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "sparse" + ], + "start_line": 82, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , key )", + "filename": "index_tricks.py", + "nloc": 51, + "complexity": 18, + "token_count": 472, + "parameters": [ + "self", + "key" + ], + "start_line": 84, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 136, + "end_line": 137, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 139, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_retval", + "long_name": "_retval( self , res )", + "filename": "index_tricks.py", + "nloc": 10, + "complexity": 4, + "token_count": 58, + "parameters": [ + "self", + "res" + ], + "start_line": 148, + "end_line": 157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , axis = 0 , matrix = False )", + "filename": "index_tricks.py", + "nloc": 6, + "complexity": 1, + "token_count": 38, + "parameters": [ + "self", + "axis", + "matrix" + ], + "start_line": 159, + "end_line": 164, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , key )", + "filename": "index_tricks.py", + "nloc": 51, + "complexity": 18, + "token_count": 377, + "parameters": [ + "self", + "key" + ], + "start_line": 166, + "end_line": 216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "index_tricks.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 218, + "end_line": 220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 222, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 236, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 250, + "end_line": 251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , arr )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "arr" + ], + "start_line": 269, + "end_line": 270, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "next", + "long_name": "next( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 272, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__iter__", + "long_name": "__iter__( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 275, + "end_line": 276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , * args )", + "filename": "index_tricks.py", + "nloc": 9, + "complexity": 2, + "token_count": 62, + "parameters": [ + "self", + "args" + ], + "start_line": 295, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "_incrementone", + "long_name": "_incrementone( self , axis )", + "filename": "index_tricks.py", + "nloc": 8, + "complexity": 3, + "token_count": 60, + "parameters": [ + "self", + "axis" + ], + "start_line": 305, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "ndincr", + "long_name": "ndincr( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 314, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "next", + "long_name": "next( self )", + "filename": "index_tricks.py", + "nloc": 7, + "complexity": 2, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 317, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "__iter__", + "long_name": "__iter__( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 325, + "end_line": 326, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , item )", + "filename": "index_tricks.py", + "nloc": 5, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self", + "item" + ], + "start_line": 355, + "end_line": 359, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 361, + "end_line": 362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , start , stop )", + "filename": "index_tricks.py", + "nloc": 4, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self", + "start", + "stop" + ], + "start_line": 364, + "end_line": 367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "__getitem__", + "long_name": "__getitem__( self , key )", + "filename": "index_tricks.py", + "nloc": 51, + "complexity": 18, + "token_count": 472, + "parameters": [ + "self", + "key" + ], + "start_line": 84, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + } + ], + "nloc": 301, + "complexity": 68, + "token_count": 1588, + "diff_parsed": { + "added": [ + " slobj = [_nx.newaxis]*len(size)", + " slobj[k] = _nx.newaxis" + ], + "deleted": [ + " slobj = [_nx.NewAxis]*len(size)", + " slobj[k] = _nx.NewAxis" + ] + } + }, + { + "old_path": "numpy/lib/tests/test_shape_base.py", + "new_path": "numpy/lib/tests/test_shape_base.py", + "filename": "test_shape_base.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -212,7 +212,7 @@ def check_1D_array(self):\n def check_2D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n res=map(atleast_3d,[a,b])\n- desired = [a[:,:,NewAxis],b[:,:,NewAxis]]\n+ desired = [a[:,:,newaxis],b[:,:,newaxis]]\n assert_array_equal(res,desired)\n def check_3D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "\nfrom numpy.testing import *\nset_package_path()\nimport numpy.lib;\nfrom numpy.lib import *\nfrom numpy.core import *\nrestore_path()\n\nclass test_apply_along_axis(ScipyTestCase):\n def check_simple(self):\n a = ones((20,10),'d')\n assert_array_equal(apply_along_axis(len,0,a),len(a)*ones(shape(a)[1]))\n def check_simple101(self,level=11):\n # This test causes segmentation fault (Numeric 23.3,23.6,Python 2.3.4)\n # when enabled and shape(a)[1]>100. See Issue 202.\n a = ones((10,101),'d')\n assert_array_equal(apply_along_axis(len,0,a),len(a)*ones(shape(a)[1]))\n\nclass test_array_split(ScipyTestCase):\n def check_integer_0_split(self):\n a = arange(10)\n try:\n res = array_split(a,0)\n assert(0) # it should have thrown a value error\n except ValueError:\n pass\n def check_integer_split(self):\n a = arange(10)\n res = array_split(a,1)\n desired = [arange(10)]\n compare_results(res,desired)\n\n res = array_split(a,2)\n desired = [arange(5),arange(5,10)]\n compare_results(res,desired)\n\n res = array_split(a,3)\n desired = [arange(4),arange(4,7),arange(7,10)]\n compare_results(res,desired)\n\n res = array_split(a,4)\n desired = [arange(3),arange(3,6),arange(6,8),arange(8,10)]\n compare_results(res,desired)\n\n res = array_split(a,5)\n desired = [arange(2),arange(2,4),arange(4,6),arange(6,8),arange(8,10)]\n compare_results(res,desired)\n\n res = array_split(a,6)\n desired = [arange(2),arange(2,4),arange(4,6),arange(6,8),arange(8,9),\n arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,7)\n desired = [arange(2),arange(2,4),arange(4,6),arange(6,7),arange(7,8),\n arange(8,9), arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,8)\n desired = [arange(2),arange(2,4),arange(4,5),arange(5,6),arange(6,7),\n arange(7,8), arange(8,9), arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,9)\n desired = [arange(2),arange(2,3),arange(3,4),arange(4,5),arange(5,6),\n arange(6,7), arange(7,8), arange(8,9), arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,10)\n desired = [arange(1),arange(1,2),arange(2,3),arange(3,4),\n arange(4,5),arange(5,6), arange(6,7), arange(7,8),\n arange(8,9), arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,11)\n desired = [arange(1),arange(1,2),arange(2,3),arange(3,4),\n arange(4,5),arange(5,6), arange(6,7), arange(7,8),\n arange(8,9), arange(9,10),array([])]\n compare_results(res,desired)\n def check_integer_split_2D_rows(self):\n a = array([arange(10),arange(10)])\n res = array_split(a,3,axis=0)\n desired = [array([arange(10)]),array([arange(10)]),array([])]\n compare_results(res,desired)\n def check_integer_split_2D_cols(self):\n a = array([arange(10),arange(10)])\n res = array_split(a,3,axis=-1)\n desired = [array([arange(4),arange(4)]),\n array([arange(4,7),arange(4,7)]),\n array([arange(7,10),arange(7,10)])]\n compare_results(res,desired)\n def check_integer_split_2D_default(self):\n \"\"\" This will fail if we change default axis\n \"\"\"\n a = array([arange(10),arange(10)])\n res = array_split(a,3)\n desired = [array([arange(10)]),array([arange(10)]),array([])]\n compare_results(res,desired)\n #perhaps should check higher dimensions\n\n def check_index_split_simple(self):\n a = arange(10)\n indices = [1,5,7]\n res = array_split(a,indices,axis=-1)\n desired = [arange(0,1),arange(1,5),arange(5,7),arange(7,10)]\n compare_results(res,desired)\n\n def check_index_split_low_bound(self):\n a = arange(10)\n indices = [0,5,7]\n res = array_split(a,indices,axis=-1)\n desired = [array([]),arange(0,5),arange(5,7),arange(7,10)]\n compare_results(res,desired)\n def check_index_split_high_bound(self):\n a = arange(10)\n indices = [0,5,7,10,12]\n res = array_split(a,indices,axis=-1)\n desired = [array([]),arange(0,5),arange(5,7),arange(7,10),\n array([]),array([])]\n compare_results(res,desired)\n\nclass test_split(ScipyTestCase):\n \"\"\"* This function is essentially the same as array_split,\n except that it test if splitting will result in an\n equal split. Only test for this case.\n *\"\"\"\n def check_equal_split(self):\n a = arange(10)\n res = split(a,2)\n desired = [arange(5),arange(5,10)]\n compare_results(res,desired)\n\n def check_unequal_split(self):\n a = arange(10)\n try:\n res = split(a,3)\n assert(0) # should raise an error\n except ValueError:\n pass\n\nclass test_atleast_1d(ScipyTestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=map(atleast_1d,[a,b])\n desired = [array([1]),array([2])]\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1,2]); b = array([2,3]);\n res=map(atleast_1d,[a,b])\n desired = [array([1,2]),array([2,3])]\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n res=map(atleast_1d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n def check_3D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n a = array([a,a]);b = array([b,b]);\n res=map(atleast_1d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n def check_r1array(self):\n \"\"\" Test to make sure equivalent Travis O's r1array function\n \"\"\"\n assert(atleast_1d(3).shape == (1,))\n assert(atleast_1d(3j).shape == (1,))\n assert(atleast_1d(3L).shape == (1,))\n assert(atleast_1d(3.0).shape == (1,))\n assert(atleast_1d([[2,3],[4,5]]).shape == (2,2))\n\nclass test_atleast_2d(ScipyTestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=map(atleast_2d,[a,b])\n desired = [array([[1]]),array([[2]])]\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1,2]); b = array([2,3]);\n res=map(atleast_2d,[a,b])\n desired = [array([[1,2]]),array([[2,3]])]\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n res=map(atleast_2d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n def check_3D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n a = array([a,a]);b = array([b,b]);\n res=map(atleast_2d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n def check_r2array(self):\n \"\"\" Test to make sure equivalent Travis O's r2array function\n \"\"\"\n assert(atleast_2d(3).shape == (1,1))\n assert(atleast_2d([3j,1]).shape == (1,2))\n assert(atleast_2d([[[3,1],[4,5]],[[3,5],[1,2]]]).shape == (2,2,2))\n\nclass test_atleast_3d(ScipyTestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=map(atleast_3d,[a,b])\n desired = [array([[[1]]]),array([[[2]]])]\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1,2]); b = array([2,3]);\n res=map(atleast_3d,[a,b])\n desired = [array([[[1],[2]]]),array([[[2],[3]]])]\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n res=map(atleast_3d,[a,b])\n desired = [a[:,:,newaxis],b[:,:,newaxis]]\n assert_array_equal(res,desired)\n def check_3D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n a = array([a,a]);b = array([b,b]);\n res=map(atleast_3d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n\nclass test_hstack(ScipyTestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=hstack([a,b])\n desired = array([1,2])\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1]); b = array([2]);\n res=hstack([a,b])\n desired = array([1,2])\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1],[2]]); b = array([[1],[2]]);\n res=hstack([a,b])\n desired = array([[1,1],[2,2]])\n assert_array_equal(res,desired)\n\nclass test_vstack(ScipyTestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=vstack([a,b])\n desired = array([[1],[2]])\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1]); b = array([2]);\n res=vstack([a,b])\n desired = array([[1],[2]])\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1],[2]]); b = array([[1],[2]]);\n res=vstack([a,b])\n desired = array([[1],[2],[1],[2]])\n assert_array_equal(res,desired)\n def check_2D_array2(self):\n a = array([1,2]); b = array([1,2]);\n res=vstack([a,b])\n desired = array([[1,2],[1,2]])\n assert_array_equal(res,desired)\n\nclass test_dstack(ScipyTestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=dstack([a,b])\n desired = array([[[1,2]]])\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1]); b = array([2]);\n res=dstack([a,b])\n desired = array([[[1,2]]])\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1],[2]]); b = array([[1],[2]]);\n res=dstack([a,b])\n desired = array([[[1,1]],[[2,2,]]])\n assert_array_equal(res,desired)\n def check_2D_array2(self):\n a = array([1,2]); b = array([1,2]);\n res=dstack([a,b])\n desired = array([[[1,1],[2,2]]])\n assert_array_equal(res,desired)\n\n\"\"\" array_split has more comprehensive test of splitting.\n only do simple test on hsplit, vsplit, and dsplit\n\"\"\"\nclass test_hsplit(ScipyTestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_0D_array(self):\n a= array(1)\n try:\n hsplit(a,2)\n assert(0)\n except ValueError:\n pass\n def check_1D_array(self):\n a= array([1,2,3,4])\n res = hsplit(a,2)\n desired = [array([1,2]),array([3,4])]\n compare_results(res,desired)\n def check_2D_array(self):\n a= array([[1,2,3,4],\n [1,2,3,4]])\n res = hsplit(a,2)\n desired = [array([[1,2],[1,2]]),array([[3,4],[3,4]])]\n compare_results(res,desired)\n\nclass test_vsplit(ScipyTestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_1D_array(self):\n a= array([1,2,3,4])\n try:\n vsplit(a,2)\n assert(0)\n except ValueError:\n pass\n def check_2D_array(self):\n a= array([[1,2,3,4],\n [1,2,3,4]])\n res = vsplit(a,2)\n desired = [array([[1,2,3,4]]),array([[1,2,3,4]])]\n compare_results(res,desired)\n\nclass test_dsplit(ScipyTestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_2D_array(self):\n a= array([[1,2,3,4],\n [1,2,3,4]])\n try:\n dsplit(a,2)\n assert(0)\n except ValueError:\n pass\n def check_3D_array(self):\n a= array([[[1,2,3,4],\n [1,2,3,4]],\n [[1,2,3,4],\n [1,2,3,4]]])\n res = dsplit(a,2)\n desired = [array([[[1,2],[1,2]],[[1,2],[1,2]]]),\n array([[[3,4],[3,4]],[[3,4],[3,4]]])]\n compare_results(res,desired)\n\nclass test_squeeze(ScipyTestCase):\n def check_basic(self):\n a = rand(20,10,10,1,1)\n b = rand(20,1,10,1,20)\n c = rand(1,1,20,10)\n assert_array_equal(squeeze(a),reshape(a,(20,10,10)))\n assert_array_equal(squeeze(b),reshape(b,(20,10,20)))\n assert_array_equal(squeeze(c),reshape(c,(20,10)))\n\n# Utility\n\ndef compare_results(res,desired):\n for i in range(len(desired)):\n assert_array_equal(res[i],desired[i])\n\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", + "source_code_before": "\nfrom numpy.testing import *\nset_package_path()\nimport numpy.lib;\nfrom numpy.lib import *\nfrom numpy.core import *\nrestore_path()\n\nclass test_apply_along_axis(ScipyTestCase):\n def check_simple(self):\n a = ones((20,10),'d')\n assert_array_equal(apply_along_axis(len,0,a),len(a)*ones(shape(a)[1]))\n def check_simple101(self,level=11):\n # This test causes segmentation fault (Numeric 23.3,23.6,Python 2.3.4)\n # when enabled and shape(a)[1]>100. See Issue 202.\n a = ones((10,101),'d')\n assert_array_equal(apply_along_axis(len,0,a),len(a)*ones(shape(a)[1]))\n\nclass test_array_split(ScipyTestCase):\n def check_integer_0_split(self):\n a = arange(10)\n try:\n res = array_split(a,0)\n assert(0) # it should have thrown a value error\n except ValueError:\n pass\n def check_integer_split(self):\n a = arange(10)\n res = array_split(a,1)\n desired = [arange(10)]\n compare_results(res,desired)\n\n res = array_split(a,2)\n desired = [arange(5),arange(5,10)]\n compare_results(res,desired)\n\n res = array_split(a,3)\n desired = [arange(4),arange(4,7),arange(7,10)]\n compare_results(res,desired)\n\n res = array_split(a,4)\n desired = [arange(3),arange(3,6),arange(6,8),arange(8,10)]\n compare_results(res,desired)\n\n res = array_split(a,5)\n desired = [arange(2),arange(2,4),arange(4,6),arange(6,8),arange(8,10)]\n compare_results(res,desired)\n\n res = array_split(a,6)\n desired = [arange(2),arange(2,4),arange(4,6),arange(6,8),arange(8,9),\n arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,7)\n desired = [arange(2),arange(2,4),arange(4,6),arange(6,7),arange(7,8),\n arange(8,9), arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,8)\n desired = [arange(2),arange(2,4),arange(4,5),arange(5,6),arange(6,7),\n arange(7,8), arange(8,9), arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,9)\n desired = [arange(2),arange(2,3),arange(3,4),arange(4,5),arange(5,6),\n arange(6,7), arange(7,8), arange(8,9), arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,10)\n desired = [arange(1),arange(1,2),arange(2,3),arange(3,4),\n arange(4,5),arange(5,6), arange(6,7), arange(7,8),\n arange(8,9), arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,11)\n desired = [arange(1),arange(1,2),arange(2,3),arange(3,4),\n arange(4,5),arange(5,6), arange(6,7), arange(7,8),\n arange(8,9), arange(9,10),array([])]\n compare_results(res,desired)\n def check_integer_split_2D_rows(self):\n a = array([arange(10),arange(10)])\n res = array_split(a,3,axis=0)\n desired = [array([arange(10)]),array([arange(10)]),array([])]\n compare_results(res,desired)\n def check_integer_split_2D_cols(self):\n a = array([arange(10),arange(10)])\n res = array_split(a,3,axis=-1)\n desired = [array([arange(4),arange(4)]),\n array([arange(4,7),arange(4,7)]),\n array([arange(7,10),arange(7,10)])]\n compare_results(res,desired)\n def check_integer_split_2D_default(self):\n \"\"\" This will fail if we change default axis\n \"\"\"\n a = array([arange(10),arange(10)])\n res = array_split(a,3)\n desired = [array([arange(10)]),array([arange(10)]),array([])]\n compare_results(res,desired)\n #perhaps should check higher dimensions\n\n def check_index_split_simple(self):\n a = arange(10)\n indices = [1,5,7]\n res = array_split(a,indices,axis=-1)\n desired = [arange(0,1),arange(1,5),arange(5,7),arange(7,10)]\n compare_results(res,desired)\n\n def check_index_split_low_bound(self):\n a = arange(10)\n indices = [0,5,7]\n res = array_split(a,indices,axis=-1)\n desired = [array([]),arange(0,5),arange(5,7),arange(7,10)]\n compare_results(res,desired)\n def check_index_split_high_bound(self):\n a = arange(10)\n indices = [0,5,7,10,12]\n res = array_split(a,indices,axis=-1)\n desired = [array([]),arange(0,5),arange(5,7),arange(7,10),\n array([]),array([])]\n compare_results(res,desired)\n\nclass test_split(ScipyTestCase):\n \"\"\"* This function is essentially the same as array_split,\n except that it test if splitting will result in an\n equal split. Only test for this case.\n *\"\"\"\n def check_equal_split(self):\n a = arange(10)\n res = split(a,2)\n desired = [arange(5),arange(5,10)]\n compare_results(res,desired)\n\n def check_unequal_split(self):\n a = arange(10)\n try:\n res = split(a,3)\n assert(0) # should raise an error\n except ValueError:\n pass\n\nclass test_atleast_1d(ScipyTestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=map(atleast_1d,[a,b])\n desired = [array([1]),array([2])]\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1,2]); b = array([2,3]);\n res=map(atleast_1d,[a,b])\n desired = [array([1,2]),array([2,3])]\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n res=map(atleast_1d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n def check_3D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n a = array([a,a]);b = array([b,b]);\n res=map(atleast_1d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n def check_r1array(self):\n \"\"\" Test to make sure equivalent Travis O's r1array function\n \"\"\"\n assert(atleast_1d(3).shape == (1,))\n assert(atleast_1d(3j).shape == (1,))\n assert(atleast_1d(3L).shape == (1,))\n assert(atleast_1d(3.0).shape == (1,))\n assert(atleast_1d([[2,3],[4,5]]).shape == (2,2))\n\nclass test_atleast_2d(ScipyTestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=map(atleast_2d,[a,b])\n desired = [array([[1]]),array([[2]])]\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1,2]); b = array([2,3]);\n res=map(atleast_2d,[a,b])\n desired = [array([[1,2]]),array([[2,3]])]\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n res=map(atleast_2d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n def check_3D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n a = array([a,a]);b = array([b,b]);\n res=map(atleast_2d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n def check_r2array(self):\n \"\"\" Test to make sure equivalent Travis O's r2array function\n \"\"\"\n assert(atleast_2d(3).shape == (1,1))\n assert(atleast_2d([3j,1]).shape == (1,2))\n assert(atleast_2d([[[3,1],[4,5]],[[3,5],[1,2]]]).shape == (2,2,2))\n\nclass test_atleast_3d(ScipyTestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=map(atleast_3d,[a,b])\n desired = [array([[[1]]]),array([[[2]]])]\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1,2]); b = array([2,3]);\n res=map(atleast_3d,[a,b])\n desired = [array([[[1],[2]]]),array([[[2],[3]]])]\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n res=map(atleast_3d,[a,b])\n desired = [a[:,:,NewAxis],b[:,:,NewAxis]]\n assert_array_equal(res,desired)\n def check_3D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n a = array([a,a]);b = array([b,b]);\n res=map(atleast_3d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n\nclass test_hstack(ScipyTestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=hstack([a,b])\n desired = array([1,2])\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1]); b = array([2]);\n res=hstack([a,b])\n desired = array([1,2])\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1],[2]]); b = array([[1],[2]]);\n res=hstack([a,b])\n desired = array([[1,1],[2,2]])\n assert_array_equal(res,desired)\n\nclass test_vstack(ScipyTestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=vstack([a,b])\n desired = array([[1],[2]])\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1]); b = array([2]);\n res=vstack([a,b])\n desired = array([[1],[2]])\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1],[2]]); b = array([[1],[2]]);\n res=vstack([a,b])\n desired = array([[1],[2],[1],[2]])\n assert_array_equal(res,desired)\n def check_2D_array2(self):\n a = array([1,2]); b = array([1,2]);\n res=vstack([a,b])\n desired = array([[1,2],[1,2]])\n assert_array_equal(res,desired)\n\nclass test_dstack(ScipyTestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=dstack([a,b])\n desired = array([[[1,2]]])\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1]); b = array([2]);\n res=dstack([a,b])\n desired = array([[[1,2]]])\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1],[2]]); b = array([[1],[2]]);\n res=dstack([a,b])\n desired = array([[[1,1]],[[2,2,]]])\n assert_array_equal(res,desired)\n def check_2D_array2(self):\n a = array([1,2]); b = array([1,2]);\n res=dstack([a,b])\n desired = array([[[1,1],[2,2]]])\n assert_array_equal(res,desired)\n\n\"\"\" array_split has more comprehensive test of splitting.\n only do simple test on hsplit, vsplit, and dsplit\n\"\"\"\nclass test_hsplit(ScipyTestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_0D_array(self):\n a= array(1)\n try:\n hsplit(a,2)\n assert(0)\n except ValueError:\n pass\n def check_1D_array(self):\n a= array([1,2,3,4])\n res = hsplit(a,2)\n desired = [array([1,2]),array([3,4])]\n compare_results(res,desired)\n def check_2D_array(self):\n a= array([[1,2,3,4],\n [1,2,3,4]])\n res = hsplit(a,2)\n desired = [array([[1,2],[1,2]]),array([[3,4],[3,4]])]\n compare_results(res,desired)\n\nclass test_vsplit(ScipyTestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_1D_array(self):\n a= array([1,2,3,4])\n try:\n vsplit(a,2)\n assert(0)\n except ValueError:\n pass\n def check_2D_array(self):\n a= array([[1,2,3,4],\n [1,2,3,4]])\n res = vsplit(a,2)\n desired = [array([[1,2,3,4]]),array([[1,2,3,4]])]\n compare_results(res,desired)\n\nclass test_dsplit(ScipyTestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_2D_array(self):\n a= array([[1,2,3,4],\n [1,2,3,4]])\n try:\n dsplit(a,2)\n assert(0)\n except ValueError:\n pass\n def check_3D_array(self):\n a= array([[[1,2,3,4],\n [1,2,3,4]],\n [[1,2,3,4],\n [1,2,3,4]]])\n res = dsplit(a,2)\n desired = [array([[[1,2],[1,2]],[[1,2],[1,2]]]),\n array([[[3,4],[3,4]],[[3,4],[3,4]]])]\n compare_results(res,desired)\n\nclass test_squeeze(ScipyTestCase):\n def check_basic(self):\n a = rand(20,10,10,1,1)\n b = rand(20,1,10,1,20)\n c = rand(1,1,20,10)\n assert_array_equal(squeeze(a),reshape(a,(20,10,10)))\n assert_array_equal(squeeze(b),reshape(b,(20,10,20)))\n assert_array_equal(squeeze(c),reshape(c,(20,10)))\n\n# Utility\n\ndef compare_results(res,desired):\n for i in range(len(desired)):\n assert_array_equal(res[i],desired[i])\n\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", + "methods": [ + { + "name": "check_simple", + "long_name": "check_simple( self )", + "filename": "test_shape_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 10, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_simple101", + "long_name": "check_simple101( self , level = 11 )", + "filename": "test_shape_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 48, + "parameters": [ + "self", + "level" + ], + "start_line": 13, + "end_line": 17, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_integer_0_split", + "long_name": "check_integer_0_split( self )", + "filename": "test_shape_base.py", + "nloc": 7, + "complexity": 2, + "token_count": 29, + "parameters": [ + "self" + ], + "start_line": 20, + "end_line": 26, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_integer_split", + "long_name": "check_integer_split( self )", + "filename": "test_shape_base.py", + "nloc": 43, + "complexity": 1, + "token_count": 637, + "parameters": [ + "self" + ], + "start_line": 27, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 1 + }, + { + "name": "check_integer_split_2D_rows", + "long_name": "check_integer_split_2D_rows( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 80, + "end_line": 84, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_integer_split_2D_cols", + "long_name": "check_integer_split_2D_cols( self )", + "filename": "test_shape_base.py", + "nloc": 7, + "complexity": 1, + "token_count": 96, + "parameters": [ + "self" + ], + "start_line": 85, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_integer_split_2D_default", + "long_name": "check_integer_split_2D_default( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 65, + "parameters": [ + "self" + ], + "start_line": 92, + "end_line": 98, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_index_split_simple", + "long_name": "check_index_split_simple( self )", + "filename": "test_shape_base.py", + "nloc": 6, + "complexity": 1, + "token_count": 70, + "parameters": [ + "self" + ], + "start_line": 101, + "end_line": 106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_index_split_low_bound", + "long_name": "check_index_split_low_bound( self )", + "filename": "test_shape_base.py", + "nloc": 6, + "complexity": 1, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 108, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_index_split_high_bound", + "long_name": "check_index_split_high_bound( self )", + "filename": "test_shape_base.py", + "nloc": 7, + "complexity": 1, + "token_count": 85, + "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": "check_equal_split", + "long_name": "check_equal_split( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 127, + "end_line": 131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_unequal_split", + "long_name": "check_unequal_split( self )", + "filename": "test_shape_base.py", + "nloc": 7, + "complexity": 2, + "token_count": 29, + "parameters": [ + "self" + ], + "start_line": 133, + "end_line": 139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_0D_array", + "long_name": "check_0D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 142, + "end_line": 146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_1D_array", + "long_name": "check_1D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 147, + "end_line": 151, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 152, + "end_line": 156, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_3D_array", + "long_name": "check_3D_array( self )", + "filename": "test_shape_base.py", + "nloc": 6, + "complexity": 1, + "token_count": 90, + "parameters": [ + "self" + ], + "start_line": 157, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_r1array", + "long_name": "check_r1array( self )", + "filename": "test_shape_base.py", + "nloc": 6, + "complexity": 1, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 163, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_0D_array", + "long_name": "check_0D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 58, + "parameters": [ + "self" + ], + "start_line": 173, + "end_line": 177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_1D_array", + "long_name": "check_1D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 70, + "parameters": [ + "self" + ], + "start_line": 178, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 183, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_3D_array", + "long_name": "check_3D_array( self )", + "filename": "test_shape_base.py", + "nloc": 6, + "complexity": 1, + "token_count": 90, + "parameters": [ + "self" + ], + "start_line": 188, + "end_line": 193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_r2array", + "long_name": "check_r2array( self )", + "filename": "test_shape_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 194, + "end_line": 199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_0D_array", + "long_name": "check_0D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 62, + "parameters": [ + "self" + ], + "start_line": 202, + "end_line": 206, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_1D_array", + "long_name": "check_1D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 207, + "end_line": 211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 82, + "parameters": [ + "self" + ], + "start_line": 212, + "end_line": 216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_3D_array", + "long_name": "check_3D_array( self )", + "filename": "test_shape_base.py", + "nloc": 6, + "complexity": 1, + "token_count": 90, + "parameters": [ + "self" + ], + "start_line": 217, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_0D_array", + "long_name": "check_0D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 225, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_1D_array", + "long_name": "check_1D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 230, + "end_line": 234, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 235, + "end_line": 239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_0D_array", + "long_name": "check_0D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 242, + "end_line": 246, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_1D_array", + "long_name": "check_1D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 53, + "parameters": [ + "self" + ], + "start_line": 247, + "end_line": 251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 73, + "parameters": [ + "self" + ], + "start_line": 252, + "end_line": 256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array2", + "long_name": "check_2D_array2( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 257, + "end_line": 261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_0D_array", + "long_name": "check_0D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 264, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_1D_array", + "long_name": "check_1D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 53, + "parameters": [ + "self" + ], + "start_line": 269, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 74, + "parameters": [ + "self" + ], + "start_line": 274, + "end_line": 278, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array2", + "long_name": "check_2D_array2( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 279, + "end_line": 283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_0D_array", + "long_name": "check_0D_array( self )", + "filename": "test_shape_base.py", + "nloc": 7, + "complexity": 2, + "token_count": 27, + "parameters": [ + "self" + ], + "start_line": 291, + "end_line": 297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_1D_array", + "long_name": "check_1D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 298, + "end_line": 302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 6, + "complexity": 1, + "token_count": 82, + "parameters": [ + "self" + ], + "start_line": 303, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_1D_array", + "long_name": "check_1D_array( self )", + "filename": "test_shape_base.py", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 313, + "end_line": 319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 6, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 320, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 330, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_3D_array", + "long_name": "check_3D_array( self )", + "filename": "test_shape_base.py", + "nloc": 9, + "complexity": 1, + "token_count": 138, + "parameters": [ + "self" + ], + "start_line": 338, + "end_line": 346, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_basic", + "long_name": "check_basic( self )", + "filename": "test_shape_base.py", + "nloc": 7, + "complexity": 1, + "token_count": 103, + "parameters": [ + "self" + ], + "start_line": 349, + "end_line": 355, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "compare_results", + "long_name": "compare_results( res , desired )", + "filename": "test_shape_base.py", + "nloc": 3, + "complexity": 2, + "token_count": 30, + "parameters": [ + "res", + "desired" + ], + "start_line": 359, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "check_simple", + "long_name": "check_simple( self )", + "filename": "test_shape_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 10, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_simple101", + "long_name": "check_simple101( self , level = 11 )", + "filename": "test_shape_base.py", + "nloc": 3, + "complexity": 1, + "token_count": 48, + "parameters": [ + "self", + "level" + ], + "start_line": 13, + "end_line": 17, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_integer_0_split", + "long_name": "check_integer_0_split( self )", + "filename": "test_shape_base.py", + "nloc": 7, + "complexity": 2, + "token_count": 29, + "parameters": [ + "self" + ], + "start_line": 20, + "end_line": 26, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_integer_split", + "long_name": "check_integer_split( self )", + "filename": "test_shape_base.py", + "nloc": 43, + "complexity": 1, + "token_count": 637, + "parameters": [ + "self" + ], + "start_line": 27, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 1 + }, + { + "name": "check_integer_split_2D_rows", + "long_name": "check_integer_split_2D_rows( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 80, + "end_line": 84, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_integer_split_2D_cols", + "long_name": "check_integer_split_2D_cols( self )", + "filename": "test_shape_base.py", + "nloc": 7, + "complexity": 1, + "token_count": 96, + "parameters": [ + "self" + ], + "start_line": 85, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_integer_split_2D_default", + "long_name": "check_integer_split_2D_default( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 65, + "parameters": [ + "self" + ], + "start_line": 92, + "end_line": 98, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_index_split_simple", + "long_name": "check_index_split_simple( self )", + "filename": "test_shape_base.py", + "nloc": 6, + "complexity": 1, + "token_count": 70, + "parameters": [ + "self" + ], + "start_line": 101, + "end_line": 106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_index_split_low_bound", + "long_name": "check_index_split_low_bound( self )", + "filename": "test_shape_base.py", + "nloc": 6, + "complexity": 1, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 108, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_index_split_high_bound", + "long_name": "check_index_split_high_bound( self )", + "filename": "test_shape_base.py", + "nloc": 7, + "complexity": 1, + "token_count": 85, + "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": "check_equal_split", + "long_name": "check_equal_split( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 127, + "end_line": 131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_unequal_split", + "long_name": "check_unequal_split( self )", + "filename": "test_shape_base.py", + "nloc": 7, + "complexity": 2, + "token_count": 29, + "parameters": [ + "self" + ], + "start_line": 133, + "end_line": 139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_0D_array", + "long_name": "check_0D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 142, + "end_line": 146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_1D_array", + "long_name": "check_1D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 147, + "end_line": 151, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 152, + "end_line": 156, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_3D_array", + "long_name": "check_3D_array( self )", + "filename": "test_shape_base.py", + "nloc": 6, + "complexity": 1, + "token_count": 90, + "parameters": [ + "self" + ], + "start_line": 157, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_r1array", + "long_name": "check_r1array( self )", + "filename": "test_shape_base.py", + "nloc": 6, + "complexity": 1, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 163, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_0D_array", + "long_name": "check_0D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 58, + "parameters": [ + "self" + ], + "start_line": 173, + "end_line": 177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_1D_array", + "long_name": "check_1D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 70, + "parameters": [ + "self" + ], + "start_line": 178, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 183, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_3D_array", + "long_name": "check_3D_array( self )", + "filename": "test_shape_base.py", + "nloc": 6, + "complexity": 1, + "token_count": 90, + "parameters": [ + "self" + ], + "start_line": 188, + "end_line": 193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_r2array", + "long_name": "check_r2array( self )", + "filename": "test_shape_base.py", + "nloc": 4, + "complexity": 1, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 194, + "end_line": 199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_0D_array", + "long_name": "check_0D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 62, + "parameters": [ + "self" + ], + "start_line": 202, + "end_line": 206, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_1D_array", + "long_name": "check_1D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 207, + "end_line": 211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 82, + "parameters": [ + "self" + ], + "start_line": 212, + "end_line": 216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_3D_array", + "long_name": "check_3D_array( self )", + "filename": "test_shape_base.py", + "nloc": 6, + "complexity": 1, + "token_count": 90, + "parameters": [ + "self" + ], + "start_line": 217, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_0D_array", + "long_name": "check_0D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 225, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_1D_array", + "long_name": "check_1D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 230, + "end_line": 234, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 235, + "end_line": 239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_0D_array", + "long_name": "check_0D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 242, + "end_line": 246, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_1D_array", + "long_name": "check_1D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 53, + "parameters": [ + "self" + ], + "start_line": 247, + "end_line": 251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 73, + "parameters": [ + "self" + ], + "start_line": 252, + "end_line": 256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array2", + "long_name": "check_2D_array2( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 257, + "end_line": 261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_0D_array", + "long_name": "check_0D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 264, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_1D_array", + "long_name": "check_1D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 53, + "parameters": [ + "self" + ], + "start_line": 269, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 74, + "parameters": [ + "self" + ], + "start_line": 274, + "end_line": 278, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array2", + "long_name": "check_2D_array2( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 279, + "end_line": 283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_0D_array", + "long_name": "check_0D_array( self )", + "filename": "test_shape_base.py", + "nloc": 7, + "complexity": 2, + "token_count": 27, + "parameters": [ + "self" + ], + "start_line": 291, + "end_line": 297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_1D_array", + "long_name": "check_1D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 298, + "end_line": 302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 6, + "complexity": 1, + "token_count": 82, + "parameters": [ + "self" + ], + "start_line": 303, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_1D_array", + "long_name": "check_1D_array( self )", + "filename": "test_shape_base.py", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 313, + "end_line": 319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 6, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 320, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 8, + "complexity": 2, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 330, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_3D_array", + "long_name": "check_3D_array( self )", + "filename": "test_shape_base.py", + "nloc": 9, + "complexity": 1, + "token_count": 138, + "parameters": [ + "self" + ], + "start_line": 338, + "end_line": 346, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_basic", + "long_name": "check_basic( self )", + "filename": "test_shape_base.py", + "nloc": 7, + "complexity": 1, + "token_count": 103, + "parameters": [ + "self" + ], + "start_line": 349, + "end_line": 355, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "compare_results", + "long_name": "compare_results( res , desired )", + "filename": "test_shape_base.py", + "nloc": 3, + "complexity": 2, + "token_count": 30, + "parameters": [ + "res", + "desired" + ], + "start_line": 359, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "check_2D_array", + "long_name": "check_2D_array( self )", + "filename": "test_shape_base.py", + "nloc": 5, + "complexity": 1, + "token_count": 82, + "parameters": [ + "self" + ], + "start_line": 212, + "end_line": 216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + } + ], + "nloc": 324, + "complexity": 52, + "token_count": 3734, + "diff_parsed": { + "added": [ + " desired = [a[:,:,newaxis],b[:,:,newaxis]]" + ], + "deleted": [ + " desired = [a[:,:,NewAxis],b[:,:,NewAxis]]" + ] + } + }, + { + "old_path": "numpy/linalg/linalg.py", + "new_path": "numpy/linalg/linalg.py", + "filename": "linalg.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -82,7 +82,7 @@ def _assertSquareness(*arrays):\n def solve(a, b):\n one_eq = len(b.shape) == 1\n if one_eq:\n- b = b[:, NewAxis]\n+ b = b[:, newaxis]\n _assertRank2(a, b)\n _assertSquareness(a)\n n_eq = a.shape[0]\n@@ -400,7 +400,7 @@ def pinv(a, rcond = 1.e-10):\n else:\n s[i] = 0.;\n return wrap(dot(transpose(vt),\n- multiply(s[:, NewAxis],transpose(u))))\n+ multiply(s[:, newaxis],transpose(u))))\n \n # Determinant\n \n@@ -440,7 +440,7 @@ def lstsq(a, b, rcond=1.e-10):\n b, wrap = _makearray(b)\n one_eq = len(b.shape) == 1\n if one_eq:\n- b = b[:, NewAxis]\n+ b = b[:, newaxis]\n _assertRank2(a, b)\n m = a.shape[0]\n n = a.shape[1]\n", + "added_lines": 3, + "deleted_lines": 3, + "source_code": "\n\"\"\"Lite version of scipy.linalg.\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n__all__ = ['solve',\n 'inv', 'cholesky',\n 'eigvals',\n 'eigvalsh', 'pinv',\n 'det', 'svd',\n 'eig', 'eigh','lstsq', 'norm',\n 'LinAlgError'\n ]\n\nfrom numpy.core import *\nfrom numpy.lib import *\nimport lapack_lite\n\n# Error object\nclass LinAlgError(Exception):\n pass\n\n# Helper routines\n_array_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\n_array_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\n_array_type = [['f', 'd'], ['F', 'D']]\n\ndef _makearray(a):\n new = asarray(a)\n wrap = getattr(a, \"__array_wrap__\", new.__array_wrap__)\n return new, wrap\n\ndef _commonType(*arrays):\n kind = 0\n# precision = 0\n# force higher precision in lite version\n precision = 1\n for a in arrays:\n t = a.dtype.char\n kind = max(kind, _array_kind[t])\n precision = max(precision, _array_precision[t])\n return _array_type[kind][precision]\n\ndef _castCopyAndTranspose(type, *arrays):\n if len(arrays) == 1:\n return transpose(arrays[0]).astype(type)\n else:\n return [transpose(a).astype(type) for a in arrays]\n\n# _fastCopyAndTranpose is an optimized version of _castCopyAndTranspose.\n# It assumes the input is 2D (as all the calls in here are).\n\n_fastCT = fastCopyAndTranspose\n\ndef _fastCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.dtype.char == type:\n cast_arrays = cast_arrays + (_fastCT(a),)\n else:\n cast_arrays = cast_arrays + (_fastCT(a.astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\ndef _assertRank2(*arrays):\n for a in arrays:\n if len(a.shape) != 2:\n raise LinAlgError, 'Array must be two-dimensional'\n\ndef _assertSquareness(*arrays):\n for a in arrays:\n if max(a.shape) != min(a.shape):\n raise LinAlgError, 'Array must be square'\n\n# Linear equations\n\ndef solve(a, b):\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, newaxis]\n _assertRank2(a, b)\n _assertSquareness(a)\n n_eq = a.shape[0]\n n_rhs = b.shape[1]\n if n_eq != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n# lapack_routine = _findLapackRoutine('gesv', t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesv\n else:\n lapack_routine = lapack_lite.dgesv\n a, b = _fastCopyAndTranspose(t, a, b)\n pivots = zeros(n_eq, 'i')\n results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Singular matrix'\n if one_eq:\n return ravel(b) # I see no need to copy here\n else:\n return transpose(b) # no need to copy\n\n\n# Matrix inversion\n\ndef inv(a):\n a, wrap = _makearray(a)\n return wrap(solve(a, identity(a.shape[0])))\n\n# Cholesky decomposition\n\ndef cholesky(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _castCopyAndTranspose(t, a)\n m = a.shape[0]\n n = a.shape[1]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zpotrf\n else:\n lapack_routine = lapack_lite.dpotrf\n results = lapack_routine('L', n, a, m, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Matrix is not positive definite - Cholesky decomposition cannot be computed'\n return transpose(triu(a,k=0)).copy()\n\n\n# Eigenvalues\ndef eigvals(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n dummy = zeros((1,), t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n rwork = zeros((n,),real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n else:\n w = wr+1j*wi\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\n\ndef eigvalsh(a, UPLO='L'):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\ndef _convertarray(a):\n if issubclass(a.dtype.type, complexfloating):\n if a.dtype.char == 'D':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('D'))\n else:\n if a.dtype.char == 'd':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('d'))\n return a, a.dtype.char\n\n# Eigenvectors\n\ndef eig(a):\n \"\"\"eig(a) returns u,v where u is the eigenvalues and\nv is a matrix of eigenvectors with vector v[:,i] corresponds to\neigenvalue u[i]. Satisfies the equation dot(a, v[:,i]) = u[i]*v[:,i]\n\"\"\"\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n a,t = _convertarray(a) # convert to float_ or complex_ type\n real_t = 'd'\n n = a.shape[0]\n dummy = zeros((1,), t)\n if t == 'D': # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n v = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n rwork = zeros((2*n,),real_t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n vr = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n v = vr\n else:\n w = wr+1j*wi\n v = array(vr,Complex)\n ind = nonzero(\n equal(\n equal(wi,0.0) # true for real e-vals\n ,0) # true for complex e-vals\n ) # indices of complex e-vals\n for i in range(len(ind)/2):\n v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]]\n v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]]\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(v.transpose())\n\n\ndef eigh(a, UPLO='L'):\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(a.transpose())\n\n\n# Singular value decomposition\n\ndef svd(a, full_matrices=1, compute_uv=1):\n a, wrap = _makearray(a)\n _assertRank2(a)\n m, n = a.shape\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n s = zeros((min(n,m),), real_t)\n if compute_uv:\n if full_matrices:\n nu = m\n nvt = n\n option = 'A'\n else:\n nu = min(n,m)\n nvt = min(n,m)\n option = 'S'\n u = zeros((nu, m), t)\n vt = zeros((n, nvt), t)\n else:\n option = 'N'\n nu = 1\n nvt = 1\n u = empty((1,1),t) \n vt = empty((1,1),t) \n\n iwork = zeros((8*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesdd\n rwork = zeros((5*min(m,n)*min(m,n) + 5*min(m,n),), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, rwork, iwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, rwork, iwork, 0)\n else:\n lapack_routine = lapack_lite.dgesdd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, iwork, 0)\n lwork = int(work[0])\n if option == 'N' and lwork==1:\n # there seems to be a bug in dgesdd of lapack\n # (NNemec, 060310)\n # returning the wrong lwork size for option == 'N'\n results = lapack_routine('A', m, n, a, m, s, u, m, vt, n,\n work, -1, iwork, 0)\n lwork = int(work[0])\n assert lwork > 1\n\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, iwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge'\n if compute_uv:\n return wrap(transpose(u)), s, \\\n wrap(transpose(vt)) # why copy here?\n else:\n return s\n\n# Generalized inverse\n\ndef pinv(a, rcond = 1.e-10):\n a, wrap = _makearray(a)\n if a.dtype.char in typecodes['Complex']:\n a = conjugate(a)\n u, s, vt = svd(a, 0)\n m = u.shape[0]\n n = vt.shape[1]\n cutoff = rcond*maximum.reduce(s)\n for i in range(min(n,m)):\n if s[i] > cutoff:\n s[i] = 1./s[i]\n else:\n s[i] = 0.;\n return wrap(dot(transpose(vt),\n multiply(s[:, newaxis],transpose(u))))\n\n# Determinant\n\ndef det(a):\n a = asarray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zgetrf\n else:\n lapack_routine = lapack_lite.dgetrf\n pivots = zeros((n,), 'i')\n results = lapack_routine(n, n, a, n, pivots, 0)\n sign = add.reduce(not_equal(pivots, arrayrange(1, n+1))) % 2\n return (1.-2.*sign)*multiply.reduce(diagonal(a),axis=-1)\n\n# Linear Least Squares\n\ndef lstsq(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n import math\n a = asarray(a)\n b, wrap = _makearray(b)\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, newaxis]\n _assertRank2(a, b)\n m = a.shape[0]\n n = a.shape[1]\n n_rhs = b.shape[1]\n ldb = max(n,m)\n if m != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n real_t = _array_type[0][_array_precision[t]]\n bstar = zeros((ldb,n_rhs),t)\n bstar[:b.shape[0],:n_rhs] = b.copy()\n a,bstar = _castCopyAndTranspose(t, a, bstar)\n s = zeros((min(m,n),),real_t)\n nlvl = max( 0, int( math.log( float(min( m,n ))/2. ) ) + 1 )\n iwork = zeros((3*min(m,n)*nlvl+11*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgelsd\n lwork = 1\n rwork = zeros((lwork,), real_t)\n work = zeros((lwork,),t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,rwork,iwork,0 )\n lwork = int(abs(work[0]))\n rwork = zeros((lwork,),real_t)\n a_real = zeros((m,n),real_t)\n bstar_real = zeros((ldb,n_rhs,),real_t)\n results = lapack_lite.dgelsd( m, n, n_rhs, a_real, m, bstar_real,ldb , s, rcond,\n 0,rwork,-1,iwork,0 )\n lrwork = int(rwork[0])\n work = zeros((lwork,), t)\n rwork = zeros((lrwork,), real_t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,rwork,iwork,0 )\n else:\n lapack_routine = lapack_lite.dgelsd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,iwork,0 )\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,iwork,0 )\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge in Linear Least Squares'\n resids = array([],t)\n if one_eq:\n x = ravel(bstar)[:n].copy()\n if (results['rank']==n) and (m>n):\n resids = array([sum((ravel(bstar)[n:])**2)])\n else:\n x = transpose(bstar)[:n,:].copy()\n if (results['rank']==n) and (m>n):\n resids = sum((transpose(bstar)[n:,:])**2).copy()\n return wrap(x),resids,results['rank'],s[:min(n,m)].copy()\n\ndef norm(x, ord=None):\n \"\"\" norm(x, ord=None) -> n\n\n Matrix or vector norm.\n\n Inputs:\n\n x -- a rank-1 (vector) or rank-2 (matrix) array\n ord -- the order of the norm.\n\n Comments:\n For arrays of any rank, if ord is None:\n calculate the square norm (Euclidean norm for vectors, Frobenius norm for matrices)\n\n For vectors ord can be any real number including Inf or -Inf.\n ord = Inf, computes the maximum of the magnitudes\n ord = -Inf, computes minimum of the magnitudes\n ord is finite, computes sum(abs(x)**ord)**(1.0/ord)\n\n For matrices ord can only be one of the following values:\n ord = 2 computes the largest singular value\n ord = -2 computes the smallest singular value\n ord = 1 computes the largest column sum of absolute values\n ord = -1 computes the smallest column sum of absolute values\n ord = Inf computes the largest row sum of absolute values\n ord = -Inf computes the smallest row sum of absolute values\n ord = 'fro' computes the frobenius norm sqrt(sum(diag(X.H * X)))\n\n For values ord < 0, the result is, strictly speaking, not a\n mathematical 'norm', but it may still be useful for numerical purposes.\n \"\"\"\n x = asarray(x)\n nd = len(x.shape) \n if ord is None: # check the default case first and handle it immediately\n return sqrt(add.reduce((x.conj() * x).ravel().real))\n\n if nd == 1:\n if ord == Inf:\n return abs(x).max()\n elif ord == -Inf:\n return abs(x).min()\n elif ord == 1:\n return abs(x).sum() # special case for speedup\n elif ord == 2:\n return sqrt(((x.conj()*x).real).sum()) # special case for speedup\n else:\n return ((abs(x)**ord).sum())**(1.0/ord)\n elif nd == 2:\n if ord == 2:\n return svd(x,compute_uv=0).max()\n elif ord == -2:\n return svd(x,compute_uv=0).min()\n elif ord == 1:\n return abs(x).sum(axis=0).max()\n elif ord == Inf:\n return abs(x).sum(axis=1).max()\n elif ord == -1:\n return abs(x).sum(axis=0).min()\n elif ord == -Inf:\n return abs(x).sum(axis=1).min()\n elif ord in ['fro','f']:\n return sqrt(add.reduce((x.conj() * x).real.ravel()))\n else:\n raise ValueError, \"Invalid norm order for matrices.\"\n else:\n raise ValueError, \"Improper number of dimensions to norm.\"\n\nif __name__ == '__main__':\n def test(a, b):\n\n print \"All numbers printed should be (almost) zero:\"\n\n x = solve(a, b)\n check = b - matrixmultiply(a, x)\n print check\n\n\n a_inv = inv(a)\n check = matrixmultiply(a, a_inv)-identity(a.shape[0])\n print check\n\n\n ev = eigvals(a)\n\n evalues, evectors = eig(a)\n check = ev-evalues\n print check\n\n evectors = transpose(evectors)\n check = matrixmultiply(a, evectors)-evectors*evalues\n print check\n\n\n u, s, vt = svd(a,0)\n check = a - matrixmultiply(u*s, vt)\n print check\n\n\n a_ginv = pinv(a)\n check = matrixmultiply(a, a_ginv)-identity(a.shape[0])\n print check\n\n\n det = det(a)\n check = det-multiply.reduce(evalues)\n print check\n\n x, residuals, rank, sv = lstsq(a, b)\n check = b - matrixmultiply(a, x)\n print check\n print rank-a.shape[0]\n print sv-s\n\n a = array([[1.,2.], [3.,4.]])\n b = array([2., 1.])\n test(a, b)\n\n a = a+0j\n b = b+0j\n test(a, b)\n", + "source_code_before": "\n\"\"\"Lite version of scipy.linalg.\n\"\"\"\n# This module is a lite version of the linalg.py module in SciPy which contains\n# high-level Python interface to the LAPACK library. The lite version\n# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,\n# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.\n\n__all__ = ['solve',\n 'inv', 'cholesky',\n 'eigvals',\n 'eigvalsh', 'pinv',\n 'det', 'svd',\n 'eig', 'eigh','lstsq', 'norm',\n 'LinAlgError'\n ]\n\nfrom numpy.core import *\nfrom numpy.lib import *\nimport lapack_lite\n\n# Error object\nclass LinAlgError(Exception):\n pass\n\n# Helper routines\n_array_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\n_array_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\n_array_type = [['f', 'd'], ['F', 'D']]\n\ndef _makearray(a):\n new = asarray(a)\n wrap = getattr(a, \"__array_wrap__\", new.__array_wrap__)\n return new, wrap\n\ndef _commonType(*arrays):\n kind = 0\n# precision = 0\n# force higher precision in lite version\n precision = 1\n for a in arrays:\n t = a.dtype.char\n kind = max(kind, _array_kind[t])\n precision = max(precision, _array_precision[t])\n return _array_type[kind][precision]\n\ndef _castCopyAndTranspose(type, *arrays):\n if len(arrays) == 1:\n return transpose(arrays[0]).astype(type)\n else:\n return [transpose(a).astype(type) for a in arrays]\n\n# _fastCopyAndTranpose is an optimized version of _castCopyAndTranspose.\n# It assumes the input is 2D (as all the calls in here are).\n\n_fastCT = fastCopyAndTranspose\n\ndef _fastCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.dtype.char == type:\n cast_arrays = cast_arrays + (_fastCT(a),)\n else:\n cast_arrays = cast_arrays + (_fastCT(a.astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\ndef _assertRank2(*arrays):\n for a in arrays:\n if len(a.shape) != 2:\n raise LinAlgError, 'Array must be two-dimensional'\n\ndef _assertSquareness(*arrays):\n for a in arrays:\n if max(a.shape) != min(a.shape):\n raise LinAlgError, 'Array must be square'\n\n# Linear equations\n\ndef solve(a, b):\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n _assertSquareness(a)\n n_eq = a.shape[0]\n n_rhs = b.shape[1]\n if n_eq != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n# lapack_routine = _findLapackRoutine('gesv', t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesv\n else:\n lapack_routine = lapack_lite.dgesv\n a, b = _fastCopyAndTranspose(t, a, b)\n pivots = zeros(n_eq, 'i')\n results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Singular matrix'\n if one_eq:\n return ravel(b) # I see no need to copy here\n else:\n return transpose(b) # no need to copy\n\n\n# Matrix inversion\n\ndef inv(a):\n a, wrap = _makearray(a)\n return wrap(solve(a, identity(a.shape[0])))\n\n# Cholesky decomposition\n\ndef cholesky(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _castCopyAndTranspose(t, a)\n m = a.shape[0]\n n = a.shape[1]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zpotrf\n else:\n lapack_routine = lapack_lite.dpotrf\n results = lapack_routine('L', n, a, m, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Matrix is not positive definite - Cholesky decomposition cannot be computed'\n return transpose(triu(a,k=0)).copy()\n\n\n# Eigenvalues\ndef eigvals(a):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n dummy = zeros((1,), t)\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n rwork = zeros((n,),real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, w,\n dummy, 1, dummy, 1, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', 'N', n, a, n, wr, wi,\n dummy, 1, dummy, 1, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n else:\n w = wr+1j*wi\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\n\ndef eigvalsh(a, UPLO='L'):\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine('N', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w\n\ndef _convertarray(a):\n if issubclass(a.dtype.type, complexfloating):\n if a.dtype.char == 'D':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('D'))\n else:\n if a.dtype.char == 'd':\n a = _fastCT(a)\n else:\n a = _fastCT(a.astype('d'))\n return a, a.dtype.char\n\n# Eigenvectors\n\ndef eig(a):\n \"\"\"eig(a) returns u,v where u is the eigenvalues and\nv is a matrix of eigenvectors with vector v[:,i] corresponds to\neigenvalue u[i]. Satisfies the equation dot(a, v[:,i]) = u[i]*v[:,i]\n\"\"\"\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n a,t = _convertarray(a) # convert to float_ or complex_ type\n real_t = 'd'\n n = a.shape[0]\n dummy = zeros((1,), t)\n if t == 'D': # Complex routines take different arguments\n lapack_routine = lapack_lite.zgeev\n w = zeros((n,), t)\n v = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n rwork = zeros((2*n,),real_t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, -1, rwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, w,\n dummy, 1, v, n, work, lwork, rwork, 0)\n else:\n lapack_routine = lapack_lite.dgeev\n wr = zeros((n,), t)\n wi = zeros((n,), t)\n vr = zeros((n,n), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, -1, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('N', 'V', n, a, n, wr, wi,\n dummy, 1, vr, n, work, lwork, 0)\n if logical_and.reduce(equal(wi, 0.)):\n w = wr\n v = vr\n else:\n w = wr+1j*wi\n v = array(vr,Complex)\n ind = nonzero(\n equal(\n equal(wi,0.0) # true for real e-vals\n ,0) # true for complex e-vals\n ) # indices of complex e-vals\n for i in range(len(ind)/2):\n v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]]\n v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]]\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(v.transpose())\n\n\ndef eigh(a, UPLO='L'):\n a, wrap = _makearray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _castCopyAndTranspose(t, a)\n n = a.shape[0]\n liwork = 5*n+3\n iwork = zeros((liwork,),'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zheevd\n w = zeros((n,), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n lrwork = 1\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, rwork, -1, iwork, liwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n lrwork = int(rwork[0])\n rwork = zeros((lrwork,),real_t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, rwork, lrwork, iwork, liwork, 0)\n else:\n lapack_routine = lapack_lite.dsyevd\n w = zeros((n,), t)\n lwork = 1\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, -1, iwork, liwork, 0)\n lwork = int(work[0])\n work = zeros((lwork,),t)\n results = lapack_routine('V', UPLO, n, a, n,w, work, lwork, iwork, liwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'Eigenvalues did not converge'\n return w,wrap(a.transpose())\n\n\n# Singular value decomposition\n\ndef svd(a, full_matrices=1, compute_uv=1):\n a, wrap = _makearray(a)\n _assertRank2(a)\n m, n = a.shape\n t =_commonType(a)\n real_t = _array_type[0][_array_precision[t]]\n a = _fastCopyAndTranspose(t, a)\n s = zeros((min(n,m),), real_t)\n if compute_uv:\n if full_matrices:\n nu = m\n nvt = n\n option = 'A'\n else:\n nu = min(n,m)\n nvt = min(n,m)\n option = 'S'\n u = zeros((nu, m), t)\n vt = zeros((n, nvt), t)\n else:\n option = 'N'\n nu = 1\n nvt = 1\n u = empty((1,1),t) \n vt = empty((1,1),t) \n\n iwork = zeros((8*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgesdd\n rwork = zeros((5*min(m,n)*min(m,n) + 5*min(m,n),), real_t)\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, rwork, iwork, 0)\n lwork = int(abs(work[0]))\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, rwork, iwork, 0)\n else:\n lapack_routine = lapack_lite.dgesdd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, -1, iwork, 0)\n lwork = int(work[0])\n if option == 'N' and lwork==1:\n # there seems to be a bug in dgesdd of lapack\n # (NNemec, 060310)\n # returning the wrong lwork size for option == 'N'\n results = lapack_routine('A', m, n, a, m, s, u, m, vt, n,\n work, -1, iwork, 0)\n lwork = int(work[0])\n assert lwork > 1\n\n work = zeros((lwork,), t)\n results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,\n work, lwork, iwork, 0)\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge'\n if compute_uv:\n return wrap(transpose(u)), s, \\\n wrap(transpose(vt)) # why copy here?\n else:\n return s\n\n# Generalized inverse\n\ndef pinv(a, rcond = 1.e-10):\n a, wrap = _makearray(a)\n if a.dtype.char in typecodes['Complex']:\n a = conjugate(a)\n u, s, vt = svd(a, 0)\n m = u.shape[0]\n n = vt.shape[1]\n cutoff = rcond*maximum.reduce(s)\n for i in range(min(n,m)):\n if s[i] > cutoff:\n s[i] = 1./s[i]\n else:\n s[i] = 0.;\n return wrap(dot(transpose(vt),\n multiply(s[:, NewAxis],transpose(u))))\n\n# Determinant\n\ndef det(a):\n a = asarray(a)\n _assertRank2(a)\n _assertSquareness(a)\n t =_commonType(a)\n a = _fastCopyAndTranspose(t, a)\n n = a.shape[0]\n if _array_kind[t] == 1:\n lapack_routine = lapack_lite.zgetrf\n else:\n lapack_routine = lapack_lite.dgetrf\n pivots = zeros((n,), 'i')\n results = lapack_routine(n, n, a, n, pivots, 0)\n sign = add.reduce(not_equal(pivots, arrayrange(1, n+1))) % 2\n return (1.-2.*sign)*multiply.reduce(diagonal(a),axis=-1)\n\n# Linear Least Squares\n\ndef lstsq(a, b, rcond=1.e-10):\n \"\"\"returns x,resids,rank,s\nwhere x minimizes 2-norm(|b - Ax|)\n resids is the sum square residuals\n rank is the rank of A\n s is the rank of the singular values of A in descending order\n\nIf b is a matrix then x is also a matrix with corresponding columns.\nIf the rank of A is less than the number of columns of A or greater than\nthe number of rows, then residuals will be returned as an empty array\notherwise resids = sum((b-dot(A,x)**2).\nSingular values less than s[0]*rcond are treated as zero.\n\"\"\"\n import math\n a = asarray(a)\n b, wrap = _makearray(b)\n one_eq = len(b.shape) == 1\n if one_eq:\n b = b[:, NewAxis]\n _assertRank2(a, b)\n m = a.shape[0]\n n = a.shape[1]\n n_rhs = b.shape[1]\n ldb = max(n,m)\n if m != b.shape[0]:\n raise LinAlgError, 'Incompatible dimensions'\n t =_commonType(a, b)\n real_t = _array_type[0][_array_precision[t]]\n bstar = zeros((ldb,n_rhs),t)\n bstar[:b.shape[0],:n_rhs] = b.copy()\n a,bstar = _castCopyAndTranspose(t, a, bstar)\n s = zeros((min(m,n),),real_t)\n nlvl = max( 0, int( math.log( float(min( m,n ))/2. ) ) + 1 )\n iwork = zeros((3*min(m,n)*nlvl+11*min(m,n),), 'i')\n if _array_kind[t] == 1: # Complex routines take different arguments\n lapack_routine = lapack_lite.zgelsd\n lwork = 1\n rwork = zeros((lwork,), real_t)\n work = zeros((lwork,),t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,rwork,iwork,0 )\n lwork = int(abs(work[0]))\n rwork = zeros((lwork,),real_t)\n a_real = zeros((m,n),real_t)\n bstar_real = zeros((ldb,n_rhs,),real_t)\n results = lapack_lite.dgelsd( m, n, n_rhs, a_real, m, bstar_real,ldb , s, rcond,\n 0,rwork,-1,iwork,0 )\n lrwork = int(rwork[0])\n work = zeros((lwork,), t)\n rwork = zeros((lrwork,), real_t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,rwork,iwork,0 )\n else:\n lapack_routine = lapack_lite.dgelsd\n lwork = 1\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,-1,iwork,0 )\n lwork = int(work[0])\n work = zeros((lwork,), t)\n results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond,\n 0,work,lwork,iwork,0 )\n if results['info'] > 0:\n raise LinAlgError, 'SVD did not converge in Linear Least Squares'\n resids = array([],t)\n if one_eq:\n x = ravel(bstar)[:n].copy()\n if (results['rank']==n) and (m>n):\n resids = array([sum((ravel(bstar)[n:])**2)])\n else:\n x = transpose(bstar)[:n,:].copy()\n if (results['rank']==n) and (m>n):\n resids = sum((transpose(bstar)[n:,:])**2).copy()\n return wrap(x),resids,results['rank'],s[:min(n,m)].copy()\n\ndef norm(x, ord=None):\n \"\"\" norm(x, ord=None) -> n\n\n Matrix or vector norm.\n\n Inputs:\n\n x -- a rank-1 (vector) or rank-2 (matrix) array\n ord -- the order of the norm.\n\n Comments:\n For arrays of any rank, if ord is None:\n calculate the square norm (Euclidean norm for vectors, Frobenius norm for matrices)\n\n For vectors ord can be any real number including Inf or -Inf.\n ord = Inf, computes the maximum of the magnitudes\n ord = -Inf, computes minimum of the magnitudes\n ord is finite, computes sum(abs(x)**ord)**(1.0/ord)\n\n For matrices ord can only be one of the following values:\n ord = 2 computes the largest singular value\n ord = -2 computes the smallest singular value\n ord = 1 computes the largest column sum of absolute values\n ord = -1 computes the smallest column sum of absolute values\n ord = Inf computes the largest row sum of absolute values\n ord = -Inf computes the smallest row sum of absolute values\n ord = 'fro' computes the frobenius norm sqrt(sum(diag(X.H * X)))\n\n For values ord < 0, the result is, strictly speaking, not a\n mathematical 'norm', but it may still be useful for numerical purposes.\n \"\"\"\n x = asarray(x)\n nd = len(x.shape) \n if ord is None: # check the default case first and handle it immediately\n return sqrt(add.reduce((x.conj() * x).ravel().real))\n\n if nd == 1:\n if ord == Inf:\n return abs(x).max()\n elif ord == -Inf:\n return abs(x).min()\n elif ord == 1:\n return abs(x).sum() # special case for speedup\n elif ord == 2:\n return sqrt(((x.conj()*x).real).sum()) # special case for speedup\n else:\n return ((abs(x)**ord).sum())**(1.0/ord)\n elif nd == 2:\n if ord == 2:\n return svd(x,compute_uv=0).max()\n elif ord == -2:\n return svd(x,compute_uv=0).min()\n elif ord == 1:\n return abs(x).sum(axis=0).max()\n elif ord == Inf:\n return abs(x).sum(axis=1).max()\n elif ord == -1:\n return abs(x).sum(axis=0).min()\n elif ord == -Inf:\n return abs(x).sum(axis=1).min()\n elif ord in ['fro','f']:\n return sqrt(add.reduce((x.conj() * x).real.ravel()))\n else:\n raise ValueError, \"Invalid norm order for matrices.\"\n else:\n raise ValueError, \"Improper number of dimensions to norm.\"\n\nif __name__ == '__main__':\n def test(a, b):\n\n print \"All numbers printed should be (almost) zero:\"\n\n x = solve(a, b)\n check = b - matrixmultiply(a, x)\n print check\n\n\n a_inv = inv(a)\n check = matrixmultiply(a, a_inv)-identity(a.shape[0])\n print check\n\n\n ev = eigvals(a)\n\n evalues, evectors = eig(a)\n check = ev-evalues\n print check\n\n evectors = transpose(evectors)\n check = matrixmultiply(a, evectors)-evectors*evalues\n print check\n\n\n u, s, vt = svd(a,0)\n check = a - matrixmultiply(u*s, vt)\n print check\n\n\n a_ginv = pinv(a)\n check = matrixmultiply(a, a_ginv)-identity(a.shape[0])\n print check\n\n\n det = det(a)\n check = det-multiply.reduce(evalues)\n print check\n\n x, residuals, rank, sv = lstsq(a, b)\n check = b - matrixmultiply(a, x)\n print check\n print rank-a.shape[0]\n print sv-s\n\n a = array([[1.,2.], [3.,4.]])\n b = array([2., 1.])\n test(a, b)\n\n a = a+0j\n b = b+0j\n test(a, b)\n", + "methods": [ + { + "name": "_makearray", + "long_name": "_makearray( a )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a" + ], + "start_line": 31, + "end_line": 34, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_commonType", + "long_name": "_commonType( * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 2, + "token_count": 54, + "parameters": [ + "arrays" + ], + "start_line": 36, + "end_line": 45, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_castCopyAndTranspose", + "long_name": "_castCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 5, + "complexity": 3, + "token_count": 47, + "parameters": [ + "type", + "arrays" + ], + "start_line": 47, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_fastCopyAndTranspose", + "long_name": "_fastCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 11, + "complexity": 4, + "token_count": 72, + "parameters": [ + "type", + "arrays" + ], + "start_line": 58, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_assertRank2", + "long_name": "_assertRank2( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 25, + "parameters": [ + "arrays" + ], + "start_line": 70, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_assertSquareness", + "long_name": "_assertSquareness( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 30, + "parameters": [ + "arrays" + ], + "start_line": 75, + "end_line": 78, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "solve", + "long_name": "solve( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 82, + "end_line": 106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "inv", + "long_name": "inv( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 111, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cholesky", + "long_name": "cholesky( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 3, + "token_count": 105, + "parameters": [ + "a" + ], + "start_line": 117, + "end_line": 131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "eigvals", + "long_name": "eigvals( a )", + "filename": "linalg.py", + "nloc": 39, + "complexity": 4, + "token_count": 363, + "parameters": [ + "a" + ], + "start_line": 135, + "end_line": 173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "eigvalsh", + "long_name": "eigvalsh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 34, + "complexity": 3, + "token_count": 345, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 176, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convertarray", + "long_name": "_convertarray( a )", + "filename": "linalg.py", + "nloc": 12, + "complexity": 4, + "token_count": 83, + "parameters": [ + "a" + ], + "start_line": 211, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "eig", + "long_name": "eig( a )", + "filename": "linalg.py", + "nloc": 51, + "complexity": 5, + "token_count": 499, + "parameters": [ + "a" + ], + "start_line": 226, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "eigh", + "long_name": "eigh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 3, + "token_count": 362, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 283, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "svd", + "long_name": "svd( a , full_matrices = 1 , compute_uv = 1 )", + "filename": "linalg.py", + "nloc": 59, + "complexity": 8, + "token_count": 539, + "parameters": [ + "a", + "full_matrices", + "compute_uv" + ], + "start_line": 322, + "end_line": 385, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "pinv", + "long_name": "pinv( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 389, + "end_line": 403, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "det", + "long_name": "det( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 407, + "end_line": 421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "lstsq", + "long_name": "lstsq( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 425, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "norm", + "long_name": "norm( x , ord = None )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 15, + "token_count": 325, + "parameters": [ + "x", + "ord" + ], + "start_line": 500, + "end_line": 565, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "test", + "long_name": "test( a , b )", + "filename": "linalg.py", + "nloc": 29, + "complexity": 1, + "token_count": 205, + "parameters": [ + "a", + "b" + ], + "start_line": 568, + "end_line": 611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "_makearray", + "long_name": "_makearray( a )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a" + ], + "start_line": 31, + "end_line": 34, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_commonType", + "long_name": "_commonType( * arrays )", + "filename": "linalg.py", + "nloc": 8, + "complexity": 2, + "token_count": 54, + "parameters": [ + "arrays" + ], + "start_line": 36, + "end_line": 45, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_castCopyAndTranspose", + "long_name": "_castCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 5, + "complexity": 3, + "token_count": 47, + "parameters": [ + "type", + "arrays" + ], + "start_line": 47, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_fastCopyAndTranspose", + "long_name": "_fastCopyAndTranspose( type , * arrays )", + "filename": "linalg.py", + "nloc": 11, + "complexity": 4, + "token_count": 72, + "parameters": [ + "type", + "arrays" + ], + "start_line": 58, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_assertRank2", + "long_name": "_assertRank2( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 25, + "parameters": [ + "arrays" + ], + "start_line": 70, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_assertSquareness", + "long_name": "_assertSquareness( * arrays )", + "filename": "linalg.py", + "nloc": 4, + "complexity": 3, + "token_count": 30, + "parameters": [ + "arrays" + ], + "start_line": 75, + "end_line": 78, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "solve", + "long_name": "solve( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 82, + "end_line": 106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "inv", + "long_name": "inv( a )", + "filename": "linalg.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a" + ], + "start_line": 111, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cholesky", + "long_name": "cholesky( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 3, + "token_count": 105, + "parameters": [ + "a" + ], + "start_line": 117, + "end_line": 131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "eigvals", + "long_name": "eigvals( a )", + "filename": "linalg.py", + "nloc": 39, + "complexity": 4, + "token_count": 363, + "parameters": [ + "a" + ], + "start_line": 135, + "end_line": 173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "eigvalsh", + "long_name": "eigvalsh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 34, + "complexity": 3, + "token_count": 345, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 176, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convertarray", + "long_name": "_convertarray( a )", + "filename": "linalg.py", + "nloc": 12, + "complexity": 4, + "token_count": 83, + "parameters": [ + "a" + ], + "start_line": 211, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "eig", + "long_name": "eig( a )", + "filename": "linalg.py", + "nloc": 51, + "complexity": 5, + "token_count": 499, + "parameters": [ + "a" + ], + "start_line": 226, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "eigh", + "long_name": "eigh( a , UPLO = 'L' )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 3, + "token_count": 362, + "parameters": [ + "a", + "UPLO" + ], + "start_line": 283, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "svd", + "long_name": "svd( a , full_matrices = 1 , compute_uv = 1 )", + "filename": "linalg.py", + "nloc": 59, + "complexity": 8, + "token_count": 539, + "parameters": [ + "a", + "full_matrices", + "compute_uv" + ], + "start_line": 322, + "end_line": 385, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "pinv", + "long_name": "pinv( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 389, + "end_line": 403, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "det", + "long_name": "det( a )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 2, + "token_count": 135, + "parameters": [ + "a" + ], + "start_line": 407, + "end_line": 421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "lstsq", + "long_name": "lstsq( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 425, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "norm", + "long_name": "norm( x , ord = None )", + "filename": "linalg.py", + "nloc": 35, + "complexity": 15, + "token_count": 325, + "parameters": [ + "x", + "ord" + ], + "start_line": 500, + "end_line": 565, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "test", + "long_name": "test( a , b )", + "filename": "linalg.py", + "nloc": 29, + "complexity": 1, + "token_count": 205, + "parameters": [ + "a", + "b" + ], + "start_line": 568, + "end_line": 611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "lstsq", + "long_name": "lstsq( a , b , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 62, + "complexity": 10, + "token_count": 729, + "parameters": [ + "a", + "b", + "rcond" + ], + "start_line": 425, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "solve", + "long_name": "solve( a , b )", + "filename": "linalg.py", + "nloc": 24, + "complexity": 6, + "token_count": 163, + "parameters": [ + "a", + "b" + ], + "start_line": 82, + "end_line": 106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "pinv", + "long_name": "pinv( a , rcond = 1 . e - 10 )", + "filename": "linalg.py", + "nloc": 15, + "complexity": 4, + "token_count": 146, + "parameters": [ + "a", + "rcond" + ], + "start_line": 389, + "end_line": 403, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + } + ], + "nloc": 490, + "complexity": 85, + "token_count": 4489, + "diff_parsed": { + "added": [ + " b = b[:, newaxis]", + " multiply(s[:, newaxis],transpose(u))))", + " b = b[:, newaxis]" + ], + "deleted": [ + " b = b[:, NewAxis]", + " multiply(s[:, NewAxis],transpose(u))))", + " b = b[:, NewAxis]" + ] + } + } + ] + }, + { + "hash": "06f4407a27139efcc9adfc5b3b504fe38a712bd4", + "msg": "For version checking of compilers, first look for a .version_match method\nto call, then check the version_pattern regex if not found. Also add a\nsimple_version_match function to ccompiler which does a fuzzy match.\n\nUpdate the GNU Fortran compilers to use version_match.", + "author": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "committer": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "author_date": "2006-03-18T22:43:25+00:00", + "author_timezone": 0, + "committer_date": "2006-03-18T22:43:25+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "267a8f5d47beb4ca8badd7859b044581708d7b52" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 16, + "insertions": 47, + "lines": 63, + "files": 2, + "dmm_unit_size": 0.3, + "dmm_unit_complexity": 0.3, + "dmm_unit_interfacing": 0.6666666666666666, + "modified_files": [ + { + "old_path": "numpy/distutils/ccompiler.py", + "new_path": "numpy/distutils/ccompiler.py", + "filename": "ccompiler.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -206,26 +206,55 @@ def CCompiler_customize(self, dist, need_cxx=0):\n CCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n \n+def simple_version_match(pat=r'[-.\\d]+', ignore=None, start=''):\n+ def matcher(self, version_string):\n+ pos = 0\n+ if start:\n+ m = re.match(start, version_string)\n+ if not m:\n+ return None\n+ pos = m.end()\n+ while 1:\n+ m = re.search(pat, version_string[pos:])\n+ if not m:\n+ return None\n+ if ignore and re.match(ignore, m.group(0)):\n+ pos = m.end()\n+ continue\n+ break\n+ return m.group(0)\n+ return matcher\n+\n def CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n- if not (hasattr(self,'version_cmd') and\n- hasattr(self,'version_pattern')):\n- #log.warn('%s does not provide version_cmd and version_pattern attributes' \\\n- # % (self.__class__))\n+ try:\n+ version_cmd = self.version_cmd\n+ except AttributeError:\n return\n+ cmd = ' '.join(version_cmd)\n+ try:\n+ matcher = self.version_match\n+ except AttributeError:\n+ try:\n+ pat = self.version_pattern\n+ except AttributeError:\n+ return\n+ def matcher(version_string):\n+ m = re.match(pat, version_string)\n+ if not m:\n+ return None\n+ version = m.group('version')\n+ return version\n \n- cmd = ' '.join(self.version_cmd)\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n- m = re.match(self.version_pattern,output)\n- if m:\n- version = m.group('version')\n- if not m:\n- raise ValueError(\"compiler version not matched (%r)\" % (version,))\n- version = LooseVersion(version)\n+ version = matcher(output)\n+ if not version:\n+ raise ValueError(\"compiler version not matched (%r)\" % (version,))\n+ version = LooseVersion(version)\n self.version = version\n return version\n \n", + "added_lines": 40, + "deleted_lines": 11, + "source_code": "import re\nimport os\nimport sys\nimport new\n\nfrom distutils.ccompiler import *\nfrom distutils import ccompiler\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.version import LooseVersion\n\nimport log\nfrom exec_command import exec_command\nfrom misc_util import cyg2win32, is_sequence, mingw32\nfrom distutils.spawn import _nt_quote_args\n\n# hack to set compiler optimizing options. Needs to integrated with something.\nimport distutils.sysconfig\n_old_init_posix = distutils.sysconfig._init_posix\ndef _new_init_posix():\n _old_init_posix()\n distutils.sysconfig._config_vars['OPT'] = '-Wall -g -O2'\n#distutils.sysconfig._init_posix = _new_init_posix\n\n# Using customized CCompiler.spawn.\ndef CCompiler_spawn(self, cmd, display=None):\n if display is None:\n display = cmd\n if is_sequence(display):\n display = ' '.join(list(display))\n log.info(display)\n if is_sequence(cmd) and os.name == 'nt':\n cmd = _nt_quote_args(list(cmd))\n s,o = exec_command(cmd)\n if s:\n if is_sequence(cmd):\n cmd = ' '.join(list(cmd))\n print o\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\nCCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n\ndef CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):\n if output_dir is None:\n output_dir = ''\n obj_names = []\n for src_name in source_filenames:\n base, ext = os.path.splitext(os.path.normpath(src_name))\n base = os.path.splitdrive(base)[1] # Chop off the drive\n base = base[os.path.isabs(base):] # If abs, chop off leading /\n if base.startswith('..'):\n # Resolve starting relative path components, middle ones\n # (if any) have been handled by os.path.normpath above.\n i = base.rfind('..')+2\n d = base[:i]\n d = os.path.basename(os.path.abspath(d))\n base = d + base[i:]\n if ext not in self.src_extensions:\n raise UnknownFileError, \\\n \"unknown file type '%s' (from '%s')\" % (ext, src_name)\n if strip_dir:\n base = os.path.basename(base)\n obj_name = os.path.join(output_dir,base + self.obj_extension)\n obj_names.append(obj_name)\n return obj_names\n\nCCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,\n None,CCompiler)\n\ndef CCompiler_compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n # This method is effective only with Python >=2.3 distutils.\n # Any changes here should be applied also to fcompiler.compile\n # method to support pre Python 2.3 distutils.\n if not sources:\n return []\n from fcompiler import FCompiler\n if isinstance(self, FCompiler):\n display = []\n for fc in ['f77','f90','fix']:\n fcomp = getattr(self,'compiler_'+fc)\n if fcomp is None:\n continue\n display.append(\"%s(%s) options: '%s'\" % (os.path.basename(fcomp[0]),\n fc,\n ' '.join(fcomp[1:])))\n display = '\\n'.join(display)\n else:\n ccomp = self.compiler_so\n display = \"%s options: '%s'\" % (os.path.basename(ccomp[0]),\n ' '.join(ccomp[1:]))\n log.info(display)\n macros, objects, extra_postargs, pp_opts, build = \\\n self._setup_compile(output_dir, macros, include_dirs, sources,\n depends, extra_postargs)\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n display = \"compile options: '%s'\" % (' '.join(cc_args))\n if extra_postargs:\n display += \"\\nextra options: '%s'\" % (' '.join(extra_postargs))\n log.info(display)\n\n # build any sources in same order as they were originally specified\n # especially important for fortran .f90 files using modules\n if isinstance(self, FCompiler):\n objects_to_build = build.keys()\n for obj in objects:\n if obj in objects_to_build:\n src, ext = build[obj]\n if self.compiler_type=='absoft':\n obj = cyg2win32(obj)\n src = cyg2win32(src)\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n else:\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n\n # Return *all* object filenames, not just the ones we just built.\n return objects\n\nCCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)\n\ndef CCompiler_customize_cmd(self, cmd):\n \"\"\" Customize compiler using distutils command.\n \"\"\"\n log.info('customize %s using %s' % (self.__class__.__name__,\n cmd.__class__.__name__))\n if getattr(cmd,'include_dirs',None) is not None:\n self.set_include_dirs(cmd.include_dirs)\n if getattr(cmd,'define',None) is not None:\n for (name,value) in cmd.define:\n self.define_macro(name, value)\n if getattr(cmd,'undef',None) is not None:\n for macro in cmd.undef:\n self.undefine_macro(macro)\n if getattr(cmd,'libraries',None) is not None:\n self.set_libraries(self.libraries + cmd.libraries)\n if getattr(cmd,'library_dirs',None) is not None:\n self.set_library_dirs(self.library_dirs + cmd.library_dirs)\n if getattr(cmd,'rpath',None) is not None:\n self.set_runtime_library_dirs(cmd.rpath)\n if getattr(cmd,'link_objects',None) is not None:\n self.set_link_objects(cmd.link_objects)\n return\n\nCCompiler.customize_cmd = new.instancemethod(\\\n CCompiler_customize_cmd,None,CCompiler)\n\ndef _compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,repr(v)))\n lines = []\n format = '%-' + repr(mx+1) + 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef CCompiler_show_customization(self):\n if 0:\n for attrname in ['include_dirs','define','undef',\n 'libraries','library_dirs',\n 'rpath','link_objects']:\n attr = getattr(self,attrname,None)\n if not attr:\n continue\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n if log._global_log.threshold<2:\n print '*'*80\n print self.__class__\n print _compiler_to_string(self)\n print '*'*80\n\nCCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n\n\ndef CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)\n return\n\nCCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n\ndef simple_version_match(pat=r'[-.\\d]+', ignore=None, start=''):\n def matcher(self, version_string):\n pos = 0\n if start:\n m = re.match(start, version_string)\n if not m:\n return None\n pos = m.end()\n while 1:\n m = re.search(pat, version_string[pos:])\n if not m:\n return None\n if ignore and re.match(ignore, m.group(0)):\n pos = m.end()\n continue\n break\n return m.group(0)\n return matcher\n\ndef CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n try:\n version_cmd = self.version_cmd\n except AttributeError:\n return\n cmd = ' '.join(version_cmd)\n try:\n matcher = self.version_match\n except AttributeError:\n try:\n pat = self.version_pattern\n except AttributeError:\n return\n def matcher(version_string):\n m = re.match(pat, version_string)\n if not m:\n return None\n version = m.group('version')\n return version\n\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n version = matcher(output)\n if not version:\n raise ValueError(\"compiler version not matched (%r)\" % (version,))\n version = LooseVersion(version)\n self.version = version\n return version\n\nCCompiler.get_version = new.instancemethod(\\\n CCompiler_get_version,None,CCompiler)\n\ncompiler_class['intel'] = ('intelccompiler','IntelCCompiler',\n \"Intel C Compiler for 32-bit applications\")\ncompiler_class['intele'] = ('intelccompiler','IntelItaniumCCompiler',\n \"Intel C Itanium Compiler for Itanium-based applications\")\nccompiler._default_compilers = ccompiler._default_compilers \\\n + (('linux.*','intel'),('linux.*','intele'))\n\nif sys.platform == 'win32':\n compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',\n \"Mingw32 port of GNU C Compiler for Win32\"\\\n \"(for MSC built Python)\")\n if mingw32():\n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n log.info('Setting mingw32 as default compiler for nt.')\n ccompiler._default_compilers = (('nt', 'mingw32'),) \\\n + ccompiler._default_compilers\n\n\n_distutils_new_compiler = new_compiler\ndef new_compiler (plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n # Try first C compilers from numpy.distutils.\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_compiler(plat)\n (module_name, class_name, long_description) = compiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile C/C++ code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n module_name = \"numpy.distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n print msg,'in numpy.distutils, trying from distutils..'\n module_name = module_name[6:]\n try:\n __import__(module_name)\n except ImportError, msg:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n try:\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile C/C++ code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\nccompiler.new_compiler = new_compiler\n\n\n_distutils_gen_lib_options = gen_lib_options\ndef gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries):\n r = _distutils_gen_lib_options(compiler, library_dirs,\n runtime_library_dirs, libraries)\n lib_opts = []\n for i in r:\n if is_sequence(i):\n lib_opts.extend(list(i))\n else:\n lib_opts.append(i)\n return lib_opts\nccompiler.gen_lib_options = gen_lib_options\n\n\n##Fix distutils.util.split_quoted:\nimport re,string\n_wordchars_re = re.compile(r'[^\\\\\\'\\\"%s ]*' % string.whitespace)\n_squote_re = re.compile(r\"'(?:[^'\\\\]|\\\\.)*'\")\n_dquote_re = re.compile(r'\"(?:[^\"\\\\]|\\\\.)*\"')\n_has_white_re = re.compile(r'\\s')\ndef split_quoted(s):\n s = string.strip(s)\n words = []\n pos = 0\n\n while s:\n m = _wordchars_re.match(s, pos)\n end = m.end()\n if end == len(s):\n words.append(s[:end])\n break\n\n if s[end] in string.whitespace: # unescaped, unquoted whitespace: now\n words.append(s[:end]) # we definitely have a word delimiter\n s = string.lstrip(s[end:])\n pos = 0\n\n elif s[end] == '\\\\': # preserve whatever is being escaped;\n # will become part of the current word\n s = s[:end] + s[end+1:]\n pos = end+1\n\n else:\n if s[end] == \"'\": # slurp singly-quoted string\n m = _squote_re.match(s, end)\n elif s[end] == '\"': # slurp doubly-quoted string\n m = _dquote_re.match(s, end)\n else:\n raise RuntimeError, \\\n \"this can't happen (bad char '%c')\" % s[end]\n\n if m is None:\n raise ValueError, \\\n \"bad string (mismatched %s quotes?)\" % s[end]\n\n (beg, end) = m.span()\n if _has_white_re.search(s[beg+1:end-1]):\n s = s[:beg] + s[beg+1:end-1] + s[end:]\n pos = m.end() - 2\n else:\n # Keeping quotes when a quoted word does not contain\n # white-space. XXX: send a patch to distutils\n pos = m.end()\n\n if pos >= len(s):\n words.append(s)\n break\n\n return words\nccompiler.split_quoted = split_quoted\n", + "source_code_before": "import re\nimport os\nimport sys\nimport new\n\nfrom distutils.ccompiler import *\nfrom distutils import ccompiler\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.version import LooseVersion\n\nimport log\nfrom exec_command import exec_command\nfrom misc_util import cyg2win32, is_sequence, mingw32\nfrom distutils.spawn import _nt_quote_args\n\n# hack to set compiler optimizing options. Needs to integrated with something.\nimport distutils.sysconfig\n_old_init_posix = distutils.sysconfig._init_posix\ndef _new_init_posix():\n _old_init_posix()\n distutils.sysconfig._config_vars['OPT'] = '-Wall -g -O2'\n#distutils.sysconfig._init_posix = _new_init_posix\n\n# Using customized CCompiler.spawn.\ndef CCompiler_spawn(self, cmd, display=None):\n if display is None:\n display = cmd\n if is_sequence(display):\n display = ' '.join(list(display))\n log.info(display)\n if is_sequence(cmd) and os.name == 'nt':\n cmd = _nt_quote_args(list(cmd))\n s,o = exec_command(cmd)\n if s:\n if is_sequence(cmd):\n cmd = ' '.join(list(cmd))\n print o\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\nCCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n\ndef CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):\n if output_dir is None:\n output_dir = ''\n obj_names = []\n for src_name in source_filenames:\n base, ext = os.path.splitext(os.path.normpath(src_name))\n base = os.path.splitdrive(base)[1] # Chop off the drive\n base = base[os.path.isabs(base):] # If abs, chop off leading /\n if base.startswith('..'):\n # Resolve starting relative path components, middle ones\n # (if any) have been handled by os.path.normpath above.\n i = base.rfind('..')+2\n d = base[:i]\n d = os.path.basename(os.path.abspath(d))\n base = d + base[i:]\n if ext not in self.src_extensions:\n raise UnknownFileError, \\\n \"unknown file type '%s' (from '%s')\" % (ext, src_name)\n if strip_dir:\n base = os.path.basename(base)\n obj_name = os.path.join(output_dir,base + self.obj_extension)\n obj_names.append(obj_name)\n return obj_names\n\nCCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,\n None,CCompiler)\n\ndef CCompiler_compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n # This method is effective only with Python >=2.3 distutils.\n # Any changes here should be applied also to fcompiler.compile\n # method to support pre Python 2.3 distutils.\n if not sources:\n return []\n from fcompiler import FCompiler\n if isinstance(self, FCompiler):\n display = []\n for fc in ['f77','f90','fix']:\n fcomp = getattr(self,'compiler_'+fc)\n if fcomp is None:\n continue\n display.append(\"%s(%s) options: '%s'\" % (os.path.basename(fcomp[0]),\n fc,\n ' '.join(fcomp[1:])))\n display = '\\n'.join(display)\n else:\n ccomp = self.compiler_so\n display = \"%s options: '%s'\" % (os.path.basename(ccomp[0]),\n ' '.join(ccomp[1:]))\n log.info(display)\n macros, objects, extra_postargs, pp_opts, build = \\\n self._setup_compile(output_dir, macros, include_dirs, sources,\n depends, extra_postargs)\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n display = \"compile options: '%s'\" % (' '.join(cc_args))\n if extra_postargs:\n display += \"\\nextra options: '%s'\" % (' '.join(extra_postargs))\n log.info(display)\n\n # build any sources in same order as they were originally specified\n # especially important for fortran .f90 files using modules\n if isinstance(self, FCompiler):\n objects_to_build = build.keys()\n for obj in objects:\n if obj in objects_to_build:\n src, ext = build[obj]\n if self.compiler_type=='absoft':\n obj = cyg2win32(obj)\n src = cyg2win32(src)\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n else:\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n\n # Return *all* object filenames, not just the ones we just built.\n return objects\n\nCCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)\n\ndef CCompiler_customize_cmd(self, cmd):\n \"\"\" Customize compiler using distutils command.\n \"\"\"\n log.info('customize %s using %s' % (self.__class__.__name__,\n cmd.__class__.__name__))\n if getattr(cmd,'include_dirs',None) is not None:\n self.set_include_dirs(cmd.include_dirs)\n if getattr(cmd,'define',None) is not None:\n for (name,value) in cmd.define:\n self.define_macro(name, value)\n if getattr(cmd,'undef',None) is not None:\n for macro in cmd.undef:\n self.undefine_macro(macro)\n if getattr(cmd,'libraries',None) is not None:\n self.set_libraries(self.libraries + cmd.libraries)\n if getattr(cmd,'library_dirs',None) is not None:\n self.set_library_dirs(self.library_dirs + cmd.library_dirs)\n if getattr(cmd,'rpath',None) is not None:\n self.set_runtime_library_dirs(cmd.rpath)\n if getattr(cmd,'link_objects',None) is not None:\n self.set_link_objects(cmd.link_objects)\n return\n\nCCompiler.customize_cmd = new.instancemethod(\\\n CCompiler_customize_cmd,None,CCompiler)\n\ndef _compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,repr(v)))\n lines = []\n format = '%-' + repr(mx+1) + 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef CCompiler_show_customization(self):\n if 0:\n for attrname in ['include_dirs','define','undef',\n 'libraries','library_dirs',\n 'rpath','link_objects']:\n attr = getattr(self,attrname,None)\n if not attr:\n continue\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n if log._global_log.threshold<2:\n print '*'*80\n print self.__class__\n print _compiler_to_string(self)\n print '*'*80\n\nCCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n\n\ndef CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)\n return\n\nCCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n\ndef CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n if not (hasattr(self,'version_cmd') and\n hasattr(self,'version_pattern')):\n #log.warn('%s does not provide version_cmd and version_pattern attributes' \\\n # % (self.__class__))\n return\n\n cmd = ' '.join(self.version_cmd)\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n m = re.match(self.version_pattern,output)\n if m:\n version = m.group('version')\n if not m:\n raise ValueError(\"compiler version not matched (%r)\" % (version,))\n version = LooseVersion(version)\n self.version = version\n return version\n\nCCompiler.get_version = new.instancemethod(\\\n CCompiler_get_version,None,CCompiler)\n\ncompiler_class['intel'] = ('intelccompiler','IntelCCompiler',\n \"Intel C Compiler for 32-bit applications\")\ncompiler_class['intele'] = ('intelccompiler','IntelItaniumCCompiler',\n \"Intel C Itanium Compiler for Itanium-based applications\")\nccompiler._default_compilers = ccompiler._default_compilers \\\n + (('linux.*','intel'),('linux.*','intele'))\n\nif sys.platform == 'win32':\n compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',\n \"Mingw32 port of GNU C Compiler for Win32\"\\\n \"(for MSC built Python)\")\n if mingw32():\n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n log.info('Setting mingw32 as default compiler for nt.')\n ccompiler._default_compilers = (('nt', 'mingw32'),) \\\n + ccompiler._default_compilers\n\n\n_distutils_new_compiler = new_compiler\ndef new_compiler (plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n # Try first C compilers from numpy.distutils.\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_compiler(plat)\n (module_name, class_name, long_description) = compiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile C/C++ code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n module_name = \"numpy.distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n print msg,'in numpy.distutils, trying from distutils..'\n module_name = module_name[6:]\n try:\n __import__(module_name)\n except ImportError, msg:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n try:\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile C/C++ code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\nccompiler.new_compiler = new_compiler\n\n\n_distutils_gen_lib_options = gen_lib_options\ndef gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries):\n r = _distutils_gen_lib_options(compiler, library_dirs,\n runtime_library_dirs, libraries)\n lib_opts = []\n for i in r:\n if is_sequence(i):\n lib_opts.extend(list(i))\n else:\n lib_opts.append(i)\n return lib_opts\nccompiler.gen_lib_options = gen_lib_options\n\n\n##Fix distutils.util.split_quoted:\nimport re,string\n_wordchars_re = re.compile(r'[^\\\\\\'\\\"%s ]*' % string.whitespace)\n_squote_re = re.compile(r\"'(?:[^'\\\\]|\\\\.)*'\")\n_dquote_re = re.compile(r'\"(?:[^\"\\\\]|\\\\.)*\"')\n_has_white_re = re.compile(r'\\s')\ndef split_quoted(s):\n s = string.strip(s)\n words = []\n pos = 0\n\n while s:\n m = _wordchars_re.match(s, pos)\n end = m.end()\n if end == len(s):\n words.append(s[:end])\n break\n\n if s[end] in string.whitespace: # unescaped, unquoted whitespace: now\n words.append(s[:end]) # we definitely have a word delimiter\n s = string.lstrip(s[end:])\n pos = 0\n\n elif s[end] == '\\\\': # preserve whatever is being escaped;\n # will become part of the current word\n s = s[:end] + s[end+1:]\n pos = end+1\n\n else:\n if s[end] == \"'\": # slurp singly-quoted string\n m = _squote_re.match(s, end)\n elif s[end] == '\"': # slurp doubly-quoted string\n m = _dquote_re.match(s, end)\n else:\n raise RuntimeError, \\\n \"this can't happen (bad char '%c')\" % s[end]\n\n if m is None:\n raise ValueError, \\\n \"bad string (mismatched %s quotes?)\" % s[end]\n\n (beg, end) = m.span()\n if _has_white_re.search(s[beg+1:end-1]):\n s = s[:beg] + s[beg+1:end-1] + s[end:]\n pos = m.end() - 2\n else:\n # Keeping quotes when a quoted word does not contain\n # white-space. XXX: send a patch to distutils\n pos = m.end()\n\n if pos >= len(s):\n words.append(s)\n break\n\n return words\nccompiler.split_quoted = split_quoted\n", + "methods": [ + { + "name": "_new_init_posix", + "long_name": "_new_init_posix( )", + "filename": "ccompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 17, + "parameters": [], + "start_line": 19, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_spawn", + "long_name": "CCompiler_spawn( self , cmd , display = None )", + "filename": "ccompiler.py", + "nloc": 15, + "complexity": 7, + "token_count": 104, + "parameters": [ + "self", + "cmd", + "display" + ], + "start_line": 25, + "end_line": 39, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_object_filenames", + "long_name": "CCompiler_object_filenames( self , source_filenames , strip_dir = 0 , output_dir = '' )", + "filename": "ccompiler.py", + "nloc": 21, + "complexity": 6, + "token_count": 185, + "parameters": [ + "self", + "source_filenames", + "strip_dir", + "output_dir" + ], + "start_line": 42, + "end_line": 64, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_compile", + "long_name": "CCompiler_compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", + "filename": "ccompiler.py", + "nloc": 42, + "complexity": 11, + "token_count": 342, + "parameters": [ + "self", + "sources", + "output_dir", + "macros", + "include_dirs", + "debug", + "extra_preargs", + "extra_postargs", + "depends" + ], + "start_line": 69, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_customize_cmd", + "long_name": "CCompiler_customize_cmd( self , cmd )", + "filename": "ccompiler.py", + "nloc": 20, + "complexity": 10, + "token_count": 200, + "parameters": [ + "self", + "cmd" + ], + "start_line": 122, + "end_line": 143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "_compiler_to_string", + "long_name": "_compiler_to_string( compiler )", + "filename": "ccompiler.py", + "nloc": 19, + "complexity": 6, + "token_count": 139, + "parameters": [ + "compiler" + ], + "start_line": 148, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_show_customization", + "long_name": "CCompiler_show_customization( self )", + "filename": "ccompiler.py", + "nloc": 16, + "complexity": 6, + "token_count": 90, + "parameters": [ + "self" + ], + "start_line": 168, + "end_line": 183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_customize", + "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", + "filename": "ccompiler.py", + "nloc": 15, + "complexity": 6, + "token_count": 144, + "parameters": [ + "self", + "dist", + "need_cxx" + ], + "start_line": 189, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "simple_version_match.matcher", + "long_name": "simple_version_match.matcher( self , version_string )", + "filename": "ccompiler.py", + "nloc": 16, + "complexity": 7, + "token_count": 92, + "parameters": [ + "self", + "version_string" + ], + "start_line": 210, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "simple_version_match", + "long_name": "simple_version_match( pat = r '[-.\\d]+' , ignore = None , start = '' )", + "filename": "ccompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "pat", + "ignore", + "start" + ], + "start_line": 209, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_get_version.matcher", + "long_name": "CCompiler_get_version.matcher( version_string )", + "filename": "ccompiler.py", + "nloc": 6, + "complexity": 2, + "token_count": 31, + "parameters": [ + "version_string" + ], + "start_line": 244, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 2 + }, + { + "name": "CCompiler_get_version", + "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", + "filename": "ccompiler.py", + "nloc": 25, + "complexity": 8, + "token_count": 126, + "parameters": [ + "self", + "force", + "ok_status" + ], + "start_line": 228, + "end_line": 259, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "new_compiler", + "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", + "filename": "ccompiler.py", + "nloc": 38, + "complexity": 8, + "token_count": 188, + "parameters": [ + "plat", + "compiler", + "verbose", + "dry_run", + "force" + ], + "start_line": 284, + "end_line": 322, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "gen_lib_options", + "long_name": "gen_lib_options( compiler , library_dirs , runtime_library_dirs , libraries )", + "filename": "ccompiler.py", + "nloc": 10, + "complexity": 3, + "token_count": 57, + "parameters": [ + "compiler", + "library_dirs", + "runtime_library_dirs", + "libraries" + ], + "start_line": 328, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "split_quoted", + "long_name": "split_quoted( s )", + "filename": "ccompiler.py", + "nloc": 38, + "complexity": 10, + "token_count": 274, + "parameters": [ + "s" + ], + "start_line": 347, + "end_line": 395, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 49, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "_new_init_posix", + "long_name": "_new_init_posix( )", + "filename": "ccompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 17, + "parameters": [], + "start_line": 19, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_spawn", + "long_name": "CCompiler_spawn( self , cmd , display = None )", + "filename": "ccompiler.py", + "nloc": 15, + "complexity": 7, + "token_count": 104, + "parameters": [ + "self", + "cmd", + "display" + ], + "start_line": 25, + "end_line": 39, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_object_filenames", + "long_name": "CCompiler_object_filenames( self , source_filenames , strip_dir = 0 , output_dir = '' )", + "filename": "ccompiler.py", + "nloc": 21, + "complexity": 6, + "token_count": 185, + "parameters": [ + "self", + "source_filenames", + "strip_dir", + "output_dir" + ], + "start_line": 42, + "end_line": 64, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_compile", + "long_name": "CCompiler_compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", + "filename": "ccompiler.py", + "nloc": 42, + "complexity": 11, + "token_count": 342, + "parameters": [ + "self", + "sources", + "output_dir", + "macros", + "include_dirs", + "debug", + "extra_preargs", + "extra_postargs", + "depends" + ], + "start_line": 69, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_customize_cmd", + "long_name": "CCompiler_customize_cmd( self , cmd )", + "filename": "ccompiler.py", + "nloc": 20, + "complexity": 10, + "token_count": 200, + "parameters": [ + "self", + "cmd" + ], + "start_line": 122, + "end_line": 143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "_compiler_to_string", + "long_name": "_compiler_to_string( compiler )", + "filename": "ccompiler.py", + "nloc": 19, + "complexity": 6, + "token_count": 139, + "parameters": [ + "compiler" + ], + "start_line": 148, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_show_customization", + "long_name": "CCompiler_show_customization( self )", + "filename": "ccompiler.py", + "nloc": 16, + "complexity": 6, + "token_count": 90, + "parameters": [ + "self" + ], + "start_line": 168, + "end_line": 183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_customize", + "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", + "filename": "ccompiler.py", + "nloc": 15, + "complexity": 6, + "token_count": 144, + "parameters": [ + "self", + "dist", + "need_cxx" + ], + "start_line": 189, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_get_version", + "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", + "filename": "ccompiler.py", + "nloc": 18, + "complexity": 8, + "token_count": 130, + "parameters": [ + "self", + "force", + "ok_status" + ], + "start_line": 209, + "end_line": 230, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "new_compiler", + "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", + "filename": "ccompiler.py", + "nloc": 38, + "complexity": 8, + "token_count": 188, + "parameters": [ + "plat", + "compiler", + "verbose", + "dry_run", + "force" + ], + "start_line": 255, + "end_line": 293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "gen_lib_options", + "long_name": "gen_lib_options( compiler , library_dirs , runtime_library_dirs , libraries )", + "filename": "ccompiler.py", + "nloc": 10, + "complexity": 3, + "token_count": 57, + "parameters": [ + "compiler", + "library_dirs", + "runtime_library_dirs", + "libraries" + ], + "start_line": 299, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "split_quoted", + "long_name": "split_quoted( s )", + "filename": "ccompiler.py", + "nloc": 38, + "complexity": 10, + "token_count": 274, + "parameters": [ + "s" + ], + "start_line": 318, + "end_line": 366, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 49, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "simple_version_match", + "long_name": "simple_version_match( pat = r '[-.\\d]+' , ignore = None , start = '' )", + "filename": "ccompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "pat", + "ignore", + "start" + ], + "start_line": 209, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_get_version.matcher", + "long_name": "CCompiler_get_version.matcher( version_string )", + "filename": "ccompiler.py", + "nloc": 6, + "complexity": 2, + "token_count": 31, + "parameters": [ + "version_string" + ], + "start_line": 244, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 2 + }, + { + "name": "simple_version_match.matcher", + "long_name": "simple_version_match.matcher( self , version_string )", + "filename": "ccompiler.py", + "nloc": 16, + "complexity": 7, + "token_count": 92, + "parameters": [ + "self", + "version_string" + ], + "start_line": 210, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "CCompiler_get_version", + "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", + "filename": "ccompiler.py", + "nloc": 25, + "complexity": 8, + "token_count": 126, + "parameters": [ + "self", + "force", + "ok_status" + ], + "start_line": 228, + "end_line": 259, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + } + ], + "nloc": 335, + "complexity": 92, + "token_count": 2343, + "diff_parsed": { + "added": [ + "def simple_version_match(pat=r'[-.\\d]+', ignore=None, start=''):", + " def matcher(self, version_string):", + " pos = 0", + " if start:", + " m = re.match(start, version_string)", + " if not m:", + " return None", + " pos = m.end()", + " while 1:", + " m = re.search(pat, version_string[pos:])", + " if not m:", + " return None", + " if ignore and re.match(ignore, m.group(0)):", + " pos = m.end()", + " continue", + " break", + " return m.group(0)", + " return matcher", + "", + " try:", + " version_cmd = self.version_cmd", + " except AttributeError:", + " cmd = ' '.join(version_cmd)", + " try:", + " matcher = self.version_match", + " except AttributeError:", + " try:", + " pat = self.version_pattern", + " except AttributeError:", + " return", + " def matcher(version_string):", + " m = re.match(pat, version_string)", + " if not m:", + " return None", + " version = m.group('version')", + " return version", + " version = matcher(output)", + " if not version:", + " raise ValueError(\"compiler version not matched (%r)\" % (version,))", + " version = LooseVersion(version)" + ], + "deleted": [ + " if not (hasattr(self,'version_cmd') and", + " hasattr(self,'version_pattern')):", + " #log.warn('%s does not provide version_cmd and version_pattern attributes' \\", + " # % (self.__class__))", + " cmd = ' '.join(self.version_cmd)", + " m = re.match(self.version_pattern,output)", + " if m:", + " version = m.group('version')", + " if not m:", + " raise ValueError(\"compiler version not matched (%r)\" % (version,))", + " version = LooseVersion(version)" + ] + } + }, + { + "old_path": "numpy/distutils/fcompiler/gnu.py", + "new_path": "numpy/distutils/fcompiler/gnu.py", + "filename": "gnu.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -5,6 +5,7 @@\n import warnings\n \n from numpy.distutils.cpuinfo import cpu\n+from numpy.distutils.ccompiler import simple_version_match\n from numpy.distutils.fcompiler import FCompiler\n from numpy.distutils.exec_command import exec_command, find_executable\n from numpy.distutils.misc_util import mingw32\n@@ -12,8 +13,7 @@\n class GnuFCompiler(FCompiler):\n \n compiler_type = 'gnu'\n- version_pattern = r'GNU Fortran ((\\(GCC[^\\)]*(\\)\\)|\\)))|)\\s*'\\\n- '(?P[^\\s*\\)]+)'\n+ version_match = simple_version_match(start=r'GNU Fortran (?!95)')\n \n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n@@ -111,8 +111,8 @@ def get_libraries(self):\n opt.append('gcc')\n if g2c is not None:\n opt.append(g2c)\n- if sys.platform == 'darwin':\n- opt.append('cc_dynamic')\n+# if sys.platform == 'darwin':\n+# opt.append('cc_dynamic')\n return opt\n \n def get_flags_debug(self):\n@@ -222,10 +222,12 @@ def get_flags_arch(self):\n class Gnu95FCompiler(GnuFCompiler):\n \n compiler_type = 'gnu95'\n- version_pattern = r'GNU Fortran 95 \\(GCC (?P[^\\s*\\)]+)'\n+ version_match = simple_version_match(start='GNU Fortran 95')\n \n # 'gfortran --version' results:\n # Debian: GNU Fortran 95 (GCC 4.0.3 20051023 (prerelease) (Debian 4.0.2-3))\n+ # OS X: GNU Fortran 95 (GCC) 4.1.0\n+ # GNU Fortran 95 (GCC) 4.2.0 20060218 (experimental)\n \n for fc_exe in map(find_executable,['gfortran','f95']):\n if os.path.isfile(fc_exe):\n", + "added_lines": 7, + "deleted_lines": 5, + "source_code": "\nimport re\nimport os\nimport sys\nimport warnings\n\nfrom numpy.distutils.cpuinfo import cpu\nfrom numpy.distutils.ccompiler import simple_version_match\nfrom numpy.distutils.fcompiler import FCompiler\nfrom numpy.distutils.exec_command import exec_command, find_executable\nfrom numpy.distutils.misc_util import mingw32\n\nclass GnuFCompiler(FCompiler):\n\n compiler_type = 'gnu'\n version_match = simple_version_match(start=r'GNU Fortran (?!95)')\n\n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)\n # GNU Fortran (GCC) 3.3.3 (Debian 20040401)\n # GNU Fortran 0.5.25 20010319 (prerelease)\n # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)\n\n for fc_exe in map(find_executable,['g77','f77']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_f90' : None,\n 'compiler_fix' : None,\n 'linker_so' : [fc_exe,\"-Wall\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n 'linker_exe' : [fc_exe,\"-Wall\"]\n }\n module_dir_switch = None\n module_include_switch = None\n\n # Cygwin: f771: warning: -fPIC ignored for target (all code is position independent)\n if os.name != 'nt' and sys.platform!='cygwin':\n pic_flags = ['-fPIC']\n\n g2c = 'g2c'\n\n #def get_linker_so(self):\n # # win32 linking should be handled by standard linker\n # # Darwin g77 cannot be used as a linker.\n # #if re.match(r'(darwin)', sys.platform):\n # # return\n # return FCompiler.get_linker_so(self)\n\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', None)\n if target is None:\n target = '10.3'\n major, minor = target.split('.')\n if int(minor) < 3:\n minor = '3'\n warnings.warn('Environment variable '\n 'MACOSX_DEPLOYMENT_TARGET reset to 10.3')\n os.environ['MACOSX_DEPLOYMENT_TARGET'] = '%s.%s' % (major,\n minor)\n\n opt.extend(['-undefined', 'dynamic_lookup', '-bundle'])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work. 'man gcc' says:\n # \".. Instead of using -mimpure-text, you should compile all\n # source code with -fpic or -fPIC.\"\n opt.append('-mimpure-text')\n return opt\n\n def get_libgcc_dir(self):\n status, output = exec_command('%s -print-libgcc-file-name' \\\n % (self.compiler_f77[0]),use_tee=0)\n if not status:\n return os.path.dirname(output)\n return\n\n def get_library_dirs(self):\n opt = []\n if sys.platform[:5] != 'linux':\n d = self.get_libgcc_dir()\n if d:\n opt.append(d)\n return opt\n\n def get_libraries(self):\n opt = []\n d = self.get_libgcc_dir()\n if d is not None:\n g2c = self.g2c + '-pic'\n f = self.static_lib_format % (g2c, self.static_lib_extension)\n if not os.path.isfile(os.path.join(d,f)):\n g2c = self.g2c\n else:\n g2c = self.g2c\n\n if sys.platform=='win32':\n # To avoid undefined reference __EH_FRAME_BEGIN__ linker error,\n # don't use -lgcc option for mingw32 g77 linker.\n if not mingw32():\n opt.append('gcc')\n if g2c is not None:\n opt.append(g2c)\n# if sys.platform == 'darwin':\n# opt.append('cc_dynamic')\n return opt\n\n def get_flags_debug(self):\n return ['-g']\n\n def get_flags_opt(self):\n if self.get_version()<='3.3.3':\n # With this compiler version building Fortran BLAS/LAPACK\n # with -O3 caused failures in lib.lapack heevr,syevr tests.\n opt = ['-O2']\n else:\n opt = ['-O3']\n opt.append('-funroll-loops')\n return opt\n\n def get_flags_arch(self):\n opt = []\n if sys.platform=='darwin':\n if os.name != 'posix':\n # this should presumably correspond to Apple\n if cpu.is_ppc():\n opt.append('-arch ppc')\n elif cpu.is_i386():\n opt.append('-arch i386')\n for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\\\n '403 505 801 821 823 860'.split():\n if getattr(cpu,'is_ppc%s'%a)():\n opt.append('-mcpu='+a)\n opt.append('-mtune='+a)\n break\n return opt\n\n # default march options in case we find nothing better\n if cpu.is_i686():\n march_opt = '-march=i686'\n elif cpu.is_i586():\n march_opt = '-march=i586'\n elif cpu.is_i486():\n march_opt = '-march=i486'\n elif cpu.is_i386():\n march_opt = '-march=i386'\n else:\n march_opt = ''\n\n gnu_ver = self.get_version()\n\n if gnu_ver >= '0.5.26': # gcc 3.0\n if cpu.is_AthlonK6():\n march_opt = '-march=k6'\n elif cpu.is_AthlonK7():\n march_opt = '-march=athlon'\n\n if gnu_ver >= '3.1.1':\n if cpu.is_AthlonK6_2():\n march_opt = '-march=k6-2'\n elif cpu.is_AthlonK6_3():\n march_opt = '-march=k6-3'\n elif cpu.is_AthlonMP():\n march_opt = '-march=athlon-mp'\n # there's also: athlon-tbird, athlon-4, athlon-xp\n elif cpu.is_Nocona():\n march_opt = '-march=nocona'\n elif cpu.is_Prescott():\n march_opt = '-march=prescott'\n elif cpu.is_PentiumIV():\n march_opt = '-march=pentium4'\n elif cpu.is_PentiumIII():\n march_opt = '-march=pentium3'\n elif cpu.is_PentiumM():\n march_opt = '-march=pentium3'\n elif cpu.is_PentiumII():\n march_opt = '-march=pentium2'\n\n if gnu_ver >= '3.4':\n if cpu.is_Opteron():\n march_opt = '-march=opteron'\n elif cpu.is_Athlon64():\n march_opt = '-march=athlon64'\n\n if gnu_ver >= '3.4.4':\n if cpu.is_PentiumM():\n march_opt = '-march=pentium-m'\n\n # Note: gcc 3.2 on win32 has breakage with -march specified\n if '3.1.1' <= gnu_ver <= '3.4' and sys.platform=='win32':\n march_opt = ''\n\n if march_opt:\n opt.append(march_opt)\n\n # other CPU flags\n if gnu_ver >= '3.1.1':\n if cpu.has_mmx(): opt.append('-mmmx')\n if cpu.has_3dnow(): opt.append('-m3dnow')\n\n if gnu_ver > '3.2.2':\n if cpu.has_sse2(): opt.append('-msse2')\n if cpu.has_sse(): opt.append('-msse')\n if gnu_ver >= '3.4':\n if cpu.has_sse3(): opt.append('-msse3')\n if cpu.is_Intel():\n opt.append('-fomit-frame-pointer')\n if cpu.is_32bit():\n opt.append('-malign-double')\n return opt\n\nclass Gnu95FCompiler(GnuFCompiler):\n\n compiler_type = 'gnu95'\n version_match = simple_version_match(start='GNU Fortran 95')\n\n # 'gfortran --version' results:\n # Debian: GNU Fortran 95 (GCC 4.0.3 20051023 (prerelease) (Debian 4.0.2-3))\n # OS X: GNU Fortran 95 (GCC) 4.1.0\n # GNU Fortran 95 (GCC) 4.2.0 20060218 (experimental)\n\n for fc_exe in map(find_executable,['gfortran','f95']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-ffixed-form\",\"-fno-second-underscore\"],\n 'compiler_f90' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_fix' : [fc_exe,\"-Wall\",\"-ffixed-form\",\"-fno-second-underscore\"],\n 'linker_so' : [fc_exe,\"-Wall\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n 'linker_exe' : [fc_exe,\"-Wall\"]\n }\n module_dir_switch = '-J'\n module_include_switch = '-I'\n\n g2c = 'gfortran'\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from numpy.distutils.fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n compiler = GnuFCompiler()\n compiler.customize()\n print compiler.get_version()\n", + "source_code_before": "\nimport re\nimport os\nimport sys\nimport warnings\n\nfrom numpy.distutils.cpuinfo import cpu\nfrom numpy.distutils.fcompiler import FCompiler\nfrom numpy.distutils.exec_command import exec_command, find_executable\nfrom numpy.distutils.misc_util import mingw32\n\nclass GnuFCompiler(FCompiler):\n\n compiler_type = 'gnu'\n version_pattern = r'GNU Fortran ((\\(GCC[^\\)]*(\\)\\)|\\)))|)\\s*'\\\n '(?P[^\\s*\\)]+)'\n\n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)\n # GNU Fortran (GCC) 3.3.3 (Debian 20040401)\n # GNU Fortran 0.5.25 20010319 (prerelease)\n # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)\n\n for fc_exe in map(find_executable,['g77','f77']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_f90' : None,\n 'compiler_fix' : None,\n 'linker_so' : [fc_exe,\"-Wall\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n 'linker_exe' : [fc_exe,\"-Wall\"]\n }\n module_dir_switch = None\n module_include_switch = None\n\n # Cygwin: f771: warning: -fPIC ignored for target (all code is position independent)\n if os.name != 'nt' and sys.platform!='cygwin':\n pic_flags = ['-fPIC']\n\n g2c = 'g2c'\n\n #def get_linker_so(self):\n # # win32 linking should be handled by standard linker\n # # Darwin g77 cannot be used as a linker.\n # #if re.match(r'(darwin)', sys.platform):\n # # return\n # return FCompiler.get_linker_so(self)\n\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', None)\n if target is None:\n target = '10.3'\n major, minor = target.split('.')\n if int(minor) < 3:\n minor = '3'\n warnings.warn('Environment variable '\n 'MACOSX_DEPLOYMENT_TARGET reset to 10.3')\n os.environ['MACOSX_DEPLOYMENT_TARGET'] = '%s.%s' % (major,\n minor)\n\n opt.extend(['-undefined', 'dynamic_lookup', '-bundle'])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work. 'man gcc' says:\n # \".. Instead of using -mimpure-text, you should compile all\n # source code with -fpic or -fPIC.\"\n opt.append('-mimpure-text')\n return opt\n\n def get_libgcc_dir(self):\n status, output = exec_command('%s -print-libgcc-file-name' \\\n % (self.compiler_f77[0]),use_tee=0)\n if not status:\n return os.path.dirname(output)\n return\n\n def get_library_dirs(self):\n opt = []\n if sys.platform[:5] != 'linux':\n d = self.get_libgcc_dir()\n if d:\n opt.append(d)\n return opt\n\n def get_libraries(self):\n opt = []\n d = self.get_libgcc_dir()\n if d is not None:\n g2c = self.g2c + '-pic'\n f = self.static_lib_format % (g2c, self.static_lib_extension)\n if not os.path.isfile(os.path.join(d,f)):\n g2c = self.g2c\n else:\n g2c = self.g2c\n\n if sys.platform=='win32':\n # To avoid undefined reference __EH_FRAME_BEGIN__ linker error,\n # don't use -lgcc option for mingw32 g77 linker.\n if not mingw32():\n opt.append('gcc')\n if g2c is not None:\n opt.append(g2c)\n if sys.platform == 'darwin':\n opt.append('cc_dynamic')\n return opt\n\n def get_flags_debug(self):\n return ['-g']\n\n def get_flags_opt(self):\n if self.get_version()<='3.3.3':\n # With this compiler version building Fortran BLAS/LAPACK\n # with -O3 caused failures in lib.lapack heevr,syevr tests.\n opt = ['-O2']\n else:\n opt = ['-O3']\n opt.append('-funroll-loops')\n return opt\n\n def get_flags_arch(self):\n opt = []\n if sys.platform=='darwin':\n if os.name != 'posix':\n # this should presumably correspond to Apple\n if cpu.is_ppc():\n opt.append('-arch ppc')\n elif cpu.is_i386():\n opt.append('-arch i386')\n for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\\\n '403 505 801 821 823 860'.split():\n if getattr(cpu,'is_ppc%s'%a)():\n opt.append('-mcpu='+a)\n opt.append('-mtune='+a)\n break\n return opt\n\n # default march options in case we find nothing better\n if cpu.is_i686():\n march_opt = '-march=i686'\n elif cpu.is_i586():\n march_opt = '-march=i586'\n elif cpu.is_i486():\n march_opt = '-march=i486'\n elif cpu.is_i386():\n march_opt = '-march=i386'\n else:\n march_opt = ''\n\n gnu_ver = self.get_version()\n\n if gnu_ver >= '0.5.26': # gcc 3.0\n if cpu.is_AthlonK6():\n march_opt = '-march=k6'\n elif cpu.is_AthlonK7():\n march_opt = '-march=athlon'\n\n if gnu_ver >= '3.1.1':\n if cpu.is_AthlonK6_2():\n march_opt = '-march=k6-2'\n elif cpu.is_AthlonK6_3():\n march_opt = '-march=k6-3'\n elif cpu.is_AthlonMP():\n march_opt = '-march=athlon-mp'\n # there's also: athlon-tbird, athlon-4, athlon-xp\n elif cpu.is_Nocona():\n march_opt = '-march=nocona'\n elif cpu.is_Prescott():\n march_opt = '-march=prescott'\n elif cpu.is_PentiumIV():\n march_opt = '-march=pentium4'\n elif cpu.is_PentiumIII():\n march_opt = '-march=pentium3'\n elif cpu.is_PentiumM():\n march_opt = '-march=pentium3'\n elif cpu.is_PentiumII():\n march_opt = '-march=pentium2'\n\n if gnu_ver >= '3.4':\n if cpu.is_Opteron():\n march_opt = '-march=opteron'\n elif cpu.is_Athlon64():\n march_opt = '-march=athlon64'\n\n if gnu_ver >= '3.4.4':\n if cpu.is_PentiumM():\n march_opt = '-march=pentium-m'\n\n # Note: gcc 3.2 on win32 has breakage with -march specified\n if '3.1.1' <= gnu_ver <= '3.4' and sys.platform=='win32':\n march_opt = ''\n\n if march_opt:\n opt.append(march_opt)\n\n # other CPU flags\n if gnu_ver >= '3.1.1':\n if cpu.has_mmx(): opt.append('-mmmx')\n if cpu.has_3dnow(): opt.append('-m3dnow')\n\n if gnu_ver > '3.2.2':\n if cpu.has_sse2(): opt.append('-msse2')\n if cpu.has_sse(): opt.append('-msse')\n if gnu_ver >= '3.4':\n if cpu.has_sse3(): opt.append('-msse3')\n if cpu.is_Intel():\n opt.append('-fomit-frame-pointer')\n if cpu.is_32bit():\n opt.append('-malign-double')\n return opt\n\nclass Gnu95FCompiler(GnuFCompiler):\n\n compiler_type = 'gnu95'\n version_pattern = r'GNU Fortran 95 \\(GCC (?P[^\\s*\\)]+)'\n\n # 'gfortran --version' results:\n # Debian: GNU Fortran 95 (GCC 4.0.3 20051023 (prerelease) (Debian 4.0.2-3))\n\n for fc_exe in map(find_executable,['gfortran','f95']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-ffixed-form\",\"-fno-second-underscore\"],\n 'compiler_f90' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_fix' : [fc_exe,\"-Wall\",\"-ffixed-form\",\"-fno-second-underscore\"],\n 'linker_so' : [fc_exe,\"-Wall\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n 'linker_exe' : [fc_exe,\"-Wall\"]\n }\n module_dir_switch = '-J'\n module_include_switch = '-I'\n\n g2c = 'gfortran'\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from numpy.distutils.fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n compiler = GnuFCompiler()\n compiler.customize()\n print compiler.get_version()\n", + "methods": [ + { + "name": "get_flags_linker_so", + "long_name": "get_flags_linker_so( self )", + "filename": "gnu.py", + "nloc": 19, + "complexity": 5, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 54, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "get_libgcc_dir", + "long_name": "get_libgcc_dir( self )", + "filename": "gnu.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 81, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self )", + "filename": "gnu.py", + "nloc": 7, + "complexity": 3, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 88, + "end_line": 94, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "gnu.py", + "nloc": 16, + "complexity": 6, + "token_count": 107, + "parameters": [ + "self" + ], + "start_line": 96, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "get_flags_debug", + "long_name": "get_flags_debug( self )", + "filename": "gnu.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 118, + "end_line": 119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_flags_opt", + "long_name": "get_flags_opt( self )", + "filename": "gnu.py", + "nloc": 7, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 121, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_flags_arch", + "long_name": "get_flags_arch( self )", + "filename": "gnu.py", + "nloc": 75, + "complexity": 42, + "token_count": 436, + "parameters": [ + "self" + ], + "start_line": 131, + "end_line": 220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 90, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "get_flags_linker_so", + "long_name": "get_flags_linker_so( self )", + "filename": "gnu.py", + "nloc": 19, + "complexity": 5, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 54, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "get_libgcc_dir", + "long_name": "get_libgcc_dir( self )", + "filename": "gnu.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 81, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self )", + "filename": "gnu.py", + "nloc": 7, + "complexity": 3, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 88, + "end_line": 94, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "gnu.py", + "nloc": 18, + "complexity": 7, + "token_count": 120, + "parameters": [ + "self" + ], + "start_line": 96, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "get_flags_debug", + "long_name": "get_flags_debug( self )", + "filename": "gnu.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 118, + "end_line": 119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_flags_opt", + "long_name": "get_flags_opt( self )", + "filename": "gnu.py", + "nloc": 7, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 121, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_flags_arch", + "long_name": "get_flags_arch( self )", + "filename": "gnu.py", + "nloc": 75, + "complexity": 42, + "token_count": 436, + "parameters": [ + "self" + ], + "start_line": 131, + "end_line": 220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 90, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "gnu.py", + "nloc": 16, + "complexity": 6, + "token_count": 107, + "parameters": [ + "self" + ], + "start_line": 96, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + } + ], + "nloc": 188, + "complexity": 61, + "token_count": 1133, + "diff_parsed": { + "added": [ + "from numpy.distutils.ccompiler import simple_version_match", + " version_match = simple_version_match(start=r'GNU Fortran (?!95)')", + "# if sys.platform == 'darwin':", + "# opt.append('cc_dynamic')", + " version_match = simple_version_match(start='GNU Fortran 95')", + " # OS X: GNU Fortran 95 (GCC) 4.1.0", + " # GNU Fortran 95 (GCC) 4.2.0 20060218 (experimental)" + ], + "deleted": [ + " version_pattern = r'GNU Fortran ((\\(GCC[^\\)]*(\\)\\)|\\)))|)\\s*'\\", + " '(?P[^\\s*\\)]+)'", + " if sys.platform == 'darwin':", + " opt.append('cc_dynamic')", + " version_pattern = r'GNU Fortran 95 \\(GCC (?P[^\\s*\\)]+)'" + ] + } + } + ] + }, + { + "hash": "0838fa5177a802345d1bab2bc6cbdf36bc57d7bd", + "msg": "remove 'from numerictypes import *'", + "author": { + "name": "Tim Leslie", + "email": "tim.leslie@gmail.com" + }, + "committer": { + "name": "Tim Leslie", + "email": "tim.leslie@gmail.com" + }, + "author_date": "2006-03-19T01:25:20+00:00", + "author_timezone": 0, + "committer_date": "2006-03-19T01:25:20+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "06f4407a27139efcc9adfc5b3b504fe38a712bd4" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 1, + "insertions": 2, + "lines": 3, + "files": 2, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/ma.py", + "new_path": "numpy/core/ma.py", + "filename": "ma.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -13,7 +13,7 @@\n import oldnumeric\n from numeric import newaxis, ndarray, inf\n from oldnumeric import typecodes, amax, amin\n-from numerictypes import *\n+from numerictypes import bool_\n import numeric\n import warnings\n \n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "\"\"\"MA: a facility for dealing with missing observations\nMA is generally used as a numpy.array look-alike.\nby Paul F. Dubois.\n\nCopyright 1999, 2000, 2001 Regents of the University of California.\nReleased for unlimited redistribution.\nAdapted for numpy_core 2005 by Travis Oliphant and\n(mainly) Paul Dubois.\n\"\"\"\nimport types, sys\n\nimport umath\nimport oldnumeric\nfrom numeric import newaxis, ndarray, inf\nfrom oldnumeric import typecodes, amax, amin\nfrom numerictypes import bool_\nimport numeric\nimport warnings\n\n# Ufunc domain lookup for __array_wrap__\nufunc_domain = {}\n# Ufunc fills lookup for __array__\nufunc_fills = {}\n\nMaskType = bool_\nnomask = MaskType(0)\ndivide_tolerance = 1.e-35\n\nclass MAError (Exception):\n def __init__ (self, args=None):\n \"Create an exception\"\n self.args = args\n def __str__(self):\n \"Calculate the string representation\"\n return str(self.args)\n __repr__ = __str__\n\nclass _MaskedPrintOption:\n \"One instance of this class, masked_print_option, is created.\"\n def __init__ (self, display):\n \"Create the masked print option object.\"\n self.set_display(display)\n self._enabled = 1\n\n def display (self):\n \"Show what prints for masked values.\"\n return self._display\n\n def set_display (self, s):\n \"set_display(s) sets what prints for masked values.\"\n self._display = s\n\n def enabled (self):\n \"Is the use of the display value enabled?\"\n return self._enabled\n\n def enable(self, flag=1):\n \"Set the enabling flag to flag.\"\n self._enabled = flag\n\n def __str__ (self):\n return str(self._display)\n\n __repr__ = __str__\n\n#if you single index into a masked location you get this object.\nmasked_print_option = _MaskedPrintOption('--')\n\n# Use single element arrays or scalars.\ndefault_real_fill_value = 1.e20\ndefault_complex_fill_value = 1.e20 + 0.0j\ndefault_character_fill_value = '-'\ndefault_integer_fill_value = 999999\ndefault_object_fill_value = '?'\n\ndef default_fill_value (obj):\n \"Function to calculate default fill value for an object.\"\n if isinstance(obj, types.FloatType):\n return default_real_fill_value\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return default_integer_fill_value\n elif isinstance(obj, types.StringType):\n return default_character_fill_value\n elif isinstance(obj, types.ComplexType):\n return default_complex_fill_value\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtype.char\n if x in typecodes['Float']:\n return default_real_fill_value\n if x in typecodes['Integer']:\n return default_integer_fill_value\n if x in typecodes['Complex']:\n return default_complex_fill_value\n if x in typecodes['Character']:\n return default_character_fill_value\n if x in typecodes['UnsignedInteger']:\n return umath.absolute(default_integer_fill_value)\n return default_object_fill_value\n else:\n return default_object_fill_value\n\ndef minimum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking minima.\"\n if isinstance(obj, types.FloatType):\n return numeric.inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtype.char\n if x in typecodes['Float']:\n return numeric.inf\n if x in typecodes['Integer']:\n return sys.maxint\n if x in typecodes['UnsignedInteger']:\n return sys.maxint\n else:\n raise TypeError, 'Unsuitable type for calculating minimum.'\n\ndef maximum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking maxima.\"\n if isinstance(obj, types.FloatType):\n return -inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return -sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtype.char\n if x in typecodes['Float']:\n return -inf\n if x in typecodes['Integer']:\n return -sys.maxint\n if x in typecodes['UnsignedInteger']:\n return 0\n else:\n raise TypeError, 'Unsuitable type for calculating maximum.'\n\ndef set_fill_value (a, fill_value):\n \"Set fill value of a if it is a masked array.\"\n if isMaskedArray(a):\n a.set_fill_value (fill_value)\n\ndef getmask (a):\n \"\"\"Mask of values in a; could be nomask.\n Returns nomask if a is not a masked array.\n To get an array for sure use getmaskarray.\"\"\"\n if isinstance(a, MaskedArray):\n return a.raw_mask()\n else:\n return nomask\n\ndef getmaskarray (a):\n \"\"\"Mask of values in a; an array of zeros if mask is nomask\n or not a masked array, and is a byte-sized integer.\n Do not try to add up entries, for example.\n \"\"\"\n m = getmask(a)\n if m is nomask:\n return make_mask_none(shape(a))\n else:\n return m\n\ndef is_mask (m):\n \"\"\"Is m a legal mask? Does not check contents, only type.\n \"\"\"\n try:\n return m.dtype.type is MaskType\n except AttributeError:\n return False\n\ndef make_mask (m, copy=0, flag=0):\n \"\"\"make_mask(m, copy=0, flag=0)\n return m as a mask, creating a copy if necessary or requested.\n Can accept any sequence of integers or nomask. Does not check\n that contents must be 0s and 1s.\n if flag, return nomask if m contains no true elements.\n \"\"\"\n if m is nomask:\n return nomask\n elif isinstance(m, ndarray):\n if m.dtype.type is MaskType:\n if copy:\n result = numeric.array(m, dtype=MaskType, copy=copy)\n else:\n result = m\n else:\n result = m.astype(MaskType)\n else:\n result = filled(m, True).astype(MaskType)\n\n if flag and not oldnumeric.sometrue(oldnumeric.ravel(result)):\n return nomask\n else:\n return result\n\ndef make_mask_none (s):\n \"Return a mask of all zeros of shape s.\"\n result = numeric.zeros(s, dtype=MaskType)\n result.shape = s\n return result\n\ndef mask_or (m1, m2):\n \"\"\"Logical or of the mask candidates m1 and m2, treating nomask as false.\n Result may equal m1 or m2 if the other is nomask.\n \"\"\"\n if m1 is nomask: return make_mask(m2)\n if m2 is nomask: return make_mask(m1)\n if m1 is m2 and is_mask(m1): return m1\n return make_mask(umath.logical_or(m1, m2))\n\ndef filled (a, value = None):\n \"\"\"a as a contiguous numeric array with any masked areas replaced by value\n if value is None or the special element \"masked\", get_fill_value(a)\n is used instead.\n\n If a is already a contiguous numeric array, a itself is returned.\n\n filled(a) can be used to be sure that the result is numeric when\n passing an object a to other software ignorant of MA, in particular to\n numeric itself.\n \"\"\"\n if isinstance(a, MaskedArray):\n return a.filled(value)\n elif isinstance(a, ndarray) and a.flags['CONTIGUOUS']:\n return a\n elif isinstance(a, types.DictType):\n return numeric.array(a, 'O')\n else:\n return numeric.array(a)\n\ndef get_fill_value (a):\n \"\"\"\n The fill value of a, if it has one; otherwise, the default fill value\n for that type.\n \"\"\"\n if isMaskedArray(a):\n result = a.fill_value()\n else:\n result = default_fill_value(a)\n return result\n\ndef common_fill_value (a, b):\n \"The common fill_value of a and b, if there is one, or None\"\n t1 = get_fill_value(a)\n t2 = get_fill_value(b)\n if t1 == t2: return t1\n return None\n\n# Domain functions return 1 where the argument(s) are not in the domain.\nclass domain_check_interval:\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n def __init__(self, y1, y2):\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n self.y1 = y1\n self.y2 = y2\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.logical_or(umath.greater (x, self.y2),\n umath.less(x, self.y1)\n )\n\nclass domain_tan:\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n def __init__(self, eps):\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n self.eps = eps\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less(umath.absolute(umath.cos(x)), self.eps)\n\nclass domain_greater:\n \"domain_greater(v)(x) = true where x <= v\"\n def __init__(self, critical_value):\n \"domain_greater(v)(x) = true where x <= v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less_equal (x, self.critical_value)\n\nclass domain_greater_equal:\n \"domain_greater_equal(v)(x) = true where x < v\"\n def __init__(self, critical_value):\n \"domain_greater_equal(v)(x) = true where x < v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less (x, self.critical_value)\n\nclass masked_unary_operation:\n def __init__ (self, aufunc, fill=0, domain=None):\n \"\"\" masked_unary_operation(aufunc, fill=0, domain=None)\n aufunc(fill) must be defined\n self(x) returns aufunc(x)\n with masked values where domain(x) is true or getmask(x) is true.\n \"\"\"\n self.f = aufunc\n self.fill = fill\n self.domain = domain\n self.__doc__ = getattr(aufunc, \"__doc__\", str(aufunc))\n self.__name__ = getattr(aufunc, \"__name__\", str(aufunc))\n ufunc_domain[aufunc] = domain\n ufunc_fills[aufunc] = fill,\n\n def __call__ (self, a, *args, **kwargs):\n \"Execute the call behavior.\"\n# numeric tries to return scalars rather than arrays when given scalars.\n m = getmask(a)\n d1 = filled(a, self.fill)\n if self.domain is not None:\n m = mask_or(m, self.domain(d1))\n result = self.f(d1, *args, **kwargs)\n return masked_array(result, m)\n\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\n\nclass domain_safe_divide:\n def __init__ (self, tolerance=divide_tolerance):\n self.tolerance = tolerance\n def __call__ (self, a, b):\n return umath.absolute(a) * self.tolerance >= umath.absolute(b)\n\nclass domained_binary_operation:\n \"\"\"Binary operations that have a domain, like divide. These are complicated\n so they are a separate class. They have no reduce, outer or accumulate.\n \"\"\"\n def __init__ (self, abfunc, domain, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.domain = domain\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n self.__name__ = getattr(abfunc, \"__name__\", str(abfunc))\n ufunc_domain[abfunc] = domain\n ufunc_fills[abfunc] = fillx, filly\n\n def __call__(self, a, b):\n \"Execute the call behavior.\"\n ma = getmask(a)\n mb = getmask(b)\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n t = self.domain(d1, d2)\n\n if oldnumeric.sometrue(t, None):\n d2 = where(t, self.filly, d2)\n mb = mask_or(mb, t)\n m = mask_or(ma, mb)\n result = self.f(d1, d2)\n return masked_array(result, m)\n\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nclass masked_binary_operation:\n def __init__ (self, abfunc, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n ufunc_domain[abfunc] = None\n ufunc_fills[abfunc] = fillx, filly\n\n def __call__ (self, a, b, *args, **kwargs):\n \"Execute the call behavior.\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n result = self.f(d1, d2, *args, **kwargs)\n return masked_array(result, m)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis with this function.\"\"\"\n m = getmask(target)\n t = filled(target, self.filly)\n if t.shape == ():\n t = t.reshape(1)\n if m is not nomask:\n m = make_mask(m, copy=1)\n m.shape = (1,)\n if m is nomask:\n return masked_array (self.f.reduce (t, axis))\n else:\n t = masked_array (t, m)\n t = self.f.reduce(filled(t, self.filly), axis)\n m = umath.logical_and.reduce(m, axis)\n if isinstance(t, ndarray):\n return masked_array(t, m, get_fill_value(target))\n elif m:\n return masked\n else:\n return t\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = self.f.outer(filled(a, self.fillx), filled(b, self.filly))\n return masked_array(d, m)\n\n def accumulate (self, target, axis=0):\n \"\"\"Accumulate target along axis after filling with y fill value.\"\"\"\n t = filled(target, self.filly)\n return masked_array (self.f.accumulate (t, axis))\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nsqrt = masked_unary_operation(umath.sqrt, 0.0, domain_greater_equal(0.0))\nlog = masked_unary_operation(umath.log, 1.0, domain_greater(0.0))\nlog10 = masked_unary_operation(umath.log10, 1.0, domain_greater(0.0))\nexp = masked_unary_operation(umath.exp)\nconjugate = masked_unary_operation(umath.conjugate)\nsin = masked_unary_operation(umath.sin)\ncos = masked_unary_operation(umath.cos)\ntan = masked_unary_operation(umath.tan, 0.0, domain_tan(1.e-35))\narcsin = masked_unary_operation(umath.arcsin, 0.0, domain_check_interval(-1.0, 1.0))\narccos = masked_unary_operation(umath.arccos, 0.0, domain_check_interval(-1.0, 1.0))\narctan = masked_unary_operation(umath.arctan)\n# Missing from numeric\narcsinh = masked_unary_operation(umath.arcsinh)\narccosh = masked_unary_operation(umath.arccosh, 1.0, domain_greater_equal(1.0))\narctanh = masked_unary_operation(umath.arctanh, 0.0, domain_check_interval(-1.0+1e-15, 1.0-1e-15))\nsinh = masked_unary_operation(umath.sinh)\ncosh = masked_unary_operation(umath.cosh)\ntanh = masked_unary_operation(umath.tanh)\nabsolute = masked_unary_operation(umath.absolute)\nfabs = masked_unary_operation(umath.fabs)\nnegative = masked_unary_operation(umath.negative)\n\ndef nonzero(a):\n \"\"\"returns the indices of the elements of a which are not zero and not masked\n\n a must be 1d\n \"\"\"\n return asarray(filled(a, 0).nonzero())\n\naround = masked_unary_operation(oldnumeric.round_)\nfloor = masked_unary_operation(umath.floor)\nceil = masked_unary_operation(umath.ceil)\nlogical_not = masked_unary_operation(umath.logical_not)\n\nadd = masked_binary_operation(umath.add)\nsubtract = masked_binary_operation(umath.subtract)\nsubtract.reduce = None\nmultiply = masked_binary_operation(umath.multiply, 1, 1)\ndivide = domained_binary_operation(umath.divide, domain_safe_divide(), 0, 1)\ntrue_divide = domained_binary_operation(umath.true_divide, domain_safe_divide(), 0, 1)\nfloor_divide = domained_binary_operation(umath.floor_divide, domain_safe_divide(), 0, 1)\nremainder = domained_binary_operation(umath.remainder, domain_safe_divide(), 0, 1)\nfmod = domained_binary_operation(umath.fmod, domain_safe_divide(), 0, 1)\nhypot = masked_binary_operation(umath.hypot)\narctan2 = masked_binary_operation(umath.arctan2, 0.0, 1.0)\narctan2.reduce = None\nequal = masked_binary_operation(umath.equal)\nequal.reduce = None\nnot_equal = masked_binary_operation(umath.not_equal)\nnot_equal.reduce = None\nless_equal = masked_binary_operation(umath.less_equal)\nless_equal.reduce = None\ngreater_equal = masked_binary_operation(umath.greater_equal)\ngreater_equal.reduce = None\nless = masked_binary_operation(umath.less)\nless.reduce = None\ngreater = masked_binary_operation(umath.greater)\ngreater.reduce = None\nlogical_and = masked_binary_operation(umath.logical_and)\nalltrue = masked_binary_operation(umath.logical_and, 1, 1).reduce\nlogical_or = masked_binary_operation(umath.logical_or)\nsometrue = logical_or.reduce\nlogical_xor = masked_binary_operation(umath.logical_xor)\nbitwise_and = masked_binary_operation(umath.bitwise_and)\nbitwise_or = masked_binary_operation(umath.bitwise_or)\nbitwise_xor = masked_binary_operation(umath.bitwise_xor)\n\ndef rank (object):\n return oldnumeric.rank(filled(object))\n\ndef shape (object):\n return oldnumeric.shape(filled(object))\n\ndef size (object, axis=None):\n return oldnumeric.size(filled(object), axis)\n\nclass MaskedArray (object):\n \"\"\"Arrays with possibly masked values.\n Masked values of 1 exclude the corresponding element from\n any computation.\n\n Construction:\n x = array(data, dtype=None, copy=True, fortran=False,\n mask = nomask, fill_value=None)\n\n If copy=False, every effort is made not to copy the data:\n If data is a MaskedArray, and argument mask=nomask,\n then the candidate data is data.data and the\n mask used is data.mask. If data is a numeric array,\n it is used as the candidate raw data.\n If dtype.char is not None and\n is != data.dtype.char then a data copy is required.\n Otherwise, the candidate is used.\n\n If a data copy is required, raw data stored is the result of:\n numeric.array(data, dtype=dtype.char, copy=copy)\n\n If mask is nomask there are no masked values. Otherwise mask must\n be convertible to an array of booleans with the same shape as x.\n\n fill_value is used to fill in masked values when necessary,\n such as when printing and in method/function filled().\n The fill_value is not used for computation within this module.\n \"\"\"\n __array_priority__ = 10.1\n def __init__(self, data, dtype=None, copy=True, fortran=False,\n mask=nomask, fill_value=None):\n \"\"\"array(data, dtype=None, copy=True, fortran=False, mask=nomask, fill_value=None)\n If data already a numeric array, its dtype becomes the default value of dtype.\n \"\"\"\n if dtype is None:\n tc = None\n else:\n tc = numeric.dtype(dtype)\n need_data_copied = copy\n if isinstance(data, MaskedArray):\n c = data.data\n if tc is None:\n tc = c.dtype\n elif tc != c.dtype:\n need_data_copied = True\n if mask is nomask:\n mask = data.mask\n elif mask is not nomask: #attempting to change the mask\n need_data_copied = True\n\n elif isinstance(data, ndarray):\n c = data\n if tc is None:\n tc = c.dtype\n elif tc != c.dtype:\n need_data_copied = True\n else:\n need_data_copied = False #because I'll do it now\n c = numeric.array(data, dtype=tc, copy=True, fortran=fortran)\n tc = c.dtype\n\n if need_data_copied:\n if tc == c.dtype:\n self._data = numeric.array(c, dtype=tc, copy=True, fortran=fortran)\n else:\n self._data = c.astype(tc)\n else:\n self._data = c\n\n if mask is nomask:\n self._mask = nomask\n self._shared_mask = 0\n else:\n self._mask = make_mask (mask)\n if self._mask is nomask:\n self._shared_mask = 0\n else:\n self._shared_mask = (self._mask is mask)\n nm = size(self._mask)\n nd = size(self._data)\n if nm != nd:\n if nm == 1:\n self._mask = oldnumeric.resize(self._mask, self._data.shape)\n self._shared_mask = 0\n elif nd == 1:\n self._data = oldnumeric.resize(self._data, self._mask.shape)\n self._data.shape = self._mask.shape\n else:\n raise MAError, \"Mask and data not compatible.\"\n elif nm == 1 and shape(self._mask) != shape(self._data):\n self.unshare_mask()\n self._mask.shape = self._data.shape\n\n self.set_fill_value(fill_value)\n\n def __array__ (self, t=None, context=None):\n \"Special hook for numeric. Converts to numeric if possible.\"\n if self._mask is not nomask:\n if oldnumeric.ravel(self._mask).any():\n if context is None:\n warnings.warn(\"Cannot automatically convert masked array to \"\\\n \"numeric because data\\n is masked in one or \"\\\n \"more locations.\");\n return self._data\n #raise MAError, \\\n # \"\"\"Cannot automatically convert masked array to numeric because data\n # is masked in one or more locations.\n # \"\"\"\n else:\n func, args, i = context\n fills = ufunc_fills.get(func)\n if fills is None:\n raise MAError, \"%s not known to ma\" % func\n return self.filled(fills[i])\n else: # Mask is all false\n # Optimize to avoid future invocations of this section.\n self._mask = nomask\n self._shared_mask = 0\n if t:\n return self._data.astype(t)\n else:\n return self._data\n\n def __array_wrap__ (self, array, context):\n \"\"\"Special hook for ufuncs.\n\n Wraps the numpy array and sets the mask according to\n context.\n \"\"\"\n func, args = context[:2]\n domain = ufunc_domain[func]\n m = reduce(mask_or, [getmask(a) for a in args])\n if domain is not None:\n m = mask_or(m, domain(*[getattr(a, '_data', a)\n for a in args]))\n if m is not nomask:\n try:\n shape = array.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = reduce(mask_or, [getmaskarray(a) for a in args])\n\n return MaskedArray(array, copy=False, mask=m)\n\n def _get_shape(self):\n \"Return the current shape.\"\n return self._data.shape\n\n def _set_shape (self, newshape):\n \"Set the array's shape.\"\n self._data.shape = newshape\n if self._mask is not nomask:\n self._mask = self._mask.copy()\n self._mask.shape = newshape\n\n def _get_flat(self):\n \"\"\"Calculate the flat value.\n \"\"\"\n if self._mask is nomask:\n return masked_array(self._data.ravel(), mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.ravel(),\n mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_flat (self, value):\n \"x.flat = value\"\n y = self.ravel()\n y[:] = value\n\n def _get_real(self):\n \"Get the real part of a complex array.\"\n if self._mask is nomask:\n return masked_array(self._data.real, mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.real, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_real (self, value):\n \"x.real = value\"\n y = self.real\n y[...] = value\n\n def _get_imaginary(self):\n \"Get the imaginary part of a complex array.\"\n if self._mask is nomask:\n return masked_array(self._data.imag, mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.imag, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_imaginary (self, value):\n \"x.imaginary = value\"\n y = self.imaginary\n y[...] = value\n\n def __str__(self):\n \"\"\"Calculate the str representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n if masked_print_option.enabled():\n f = masked_print_option\n # XXX: Without the following special case masked\n # XXX: would print as \"[--]\", not \"--\". Can we avoid\n # XXX: checks for masked by choosing a different value\n # XXX: for the masked singleton? 2005-01-05 -- sasha\n if self is masked:\n return str(f)\n m = self._mask\n if m is not nomask and m.shape == () and m:\n return str(f)\n # convert to object array to make filled work\n self = self.astype(object)\n else:\n f = self.fill_value()\n res = self.filled(f)\n return str(res)\n\n def __repr__(self):\n \"\"\"Calculate the repr representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n with_mask = \"\"\"\\\narray(data =\n %(data)s,\n mask =\n %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n with_mask1 = \"\"\"\\\narray(data = %(data)s,\n mask = %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n without_mask = \"\"\"array(\n %(data)s)\"\"\"\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n\n n = len(self.shape)\n if self._mask is nomask:\n if n <= 1:\n return without_mask1 % {'data':str(self.filled())}\n return without_mask % {'data':str(self.filled())}\n else:\n if n <= 1:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n if self._mask is nomask:\n return without_mask % {'data':str(self.filled())}\n else:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n\n def __float__(self):\n \"Convert self to float.\"\n self.unmask()\n if self._mask is not nomask:\n raise MAError, 'Cannot convert masked element to a Python float.'\n return float(self.data.item())\n\n def __int__(self):\n \"Convert self to int.\"\n self.unmask()\n if self._mask is not nomask:\n raise MAError, 'Cannot convert masked element to a Python int.'\n return int(self.data.item())\n\n def __getitem__(self, i):\n \"Get item described by i. Not a copy as in previous versions.\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i]\n if m is nomask:\n return dout\n mi = m[i]\n if mi.size == 1:\n if mi:\n return masked\n else:\n return dout\n else:\n return masked_array(dout, mi, fill_value=self._fill_value)\n\n def __getslice__(self, i, j):\n \"Get slice described by i, j\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i:j]\n if m is nomask:\n return masked_array(dout, fill_value=self._fill_value)\n else:\n return masked_array(dout, mask = m[i:j], fill_value=self._fill_value)\n\n# --------\n# setitem and setslice notes\n# note that if value is masked, it means to mask those locations.\n# setting a value changes the mask to match the value in those locations.\n\n def __setitem__(self, index, value):\n \"Set item described by index. If value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, 'Cannot alter the masked element.'\n if value is masked:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n else:\n self.unshare_mask()\n self._mask[index] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[index] = value\n if m is nomask:\n if self._mask is not nomask:\n self.unshare_mask()\n self._mask[index] = False\n else:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = True\n else:\n self.unshare_mask()\n self._mask[index] = m\n\n def __setslice__(self, i, j, value):\n \"Set slice i:j; if value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, \"Cannot alter the 'masked' object.\"\n if value is masked:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n self._mask[i:j] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[i:j] = value\n if m is nomask:\n if self._mask is not nomask:\n self.unshare_mask()\n self._mask[i:j] = False\n else:\n if self._mask is nomask:\n self._mask = make_mask_none(self._data.shape)\n self._shared_mask = False\n self._mask[i:j] = m\n\n def __nonzero__(self):\n \"\"\"returns true if any element is non-zero or masked\n\n \"\"\"\n # XXX: This changes bool conversion logic from MA.\n # XXX: In MA bool(a) == len(a) != 0, but in numpy\n # XXX: scalars do not have len\n m = self._mask\n d = self._data\n return bool(m is not nomask and m.any()\n or d is not nomask and d.any())\n\n def __len__ (self):\n \"\"\"Return length of first dimension. This is weird but Python's\n slicing behavior depends on it.\"\"\"\n return len(self._data)\n\n def __and__(self, other):\n \"Return bitwise_and\"\n return bitwise_and(self, other)\n\n def __or__(self, other):\n \"Return bitwise_or\"\n return bitwise_or(self, other)\n\n def __xor__(self, other):\n \"Return bitwise_xor\"\n return bitwise_xor(self, other)\n\n __rand__ = __and__\n __ror__ = __or__\n __rxor__ = __xor__\n\n def __abs__(self):\n \"Return absolute(self)\"\n return absolute(self)\n\n def __neg__(self):\n \"Return negative(self)\"\n return negative(self)\n\n def __pos__(self):\n \"Return array(self)\"\n return array(self)\n\n def __add__(self, other):\n \"Return add(self, other)\"\n return add(self, other)\n\n __radd__ = __add__\n\n def __mod__ (self, other):\n \"Return remainder(self, other)\"\n return remainder(self, other)\n\n def __rmod__ (self, other):\n \"Return remainder(other, self)\"\n return remainder(other, self)\n\n def __lshift__ (self, n):\n return left_shift(self, n)\n\n def __rshift__ (self, n):\n return right_shift(self, n)\n\n def __sub__(self, other):\n \"Return subtract(self, other)\"\n return subtract(self, other)\n\n def __rsub__(self, other):\n \"Return subtract(other, self)\"\n return subtract(other, self)\n\n def __mul__(self, other):\n \"Return multiply(self, other)\"\n return multiply(self, other)\n\n __rmul__ = __mul__\n\n def __div__(self, other):\n \"Return divide(self, other)\"\n return divide(self, other)\n\n def __rdiv__(self, other):\n \"Return divide(other, self)\"\n return divide(other, self)\n\n def __truediv__(self, other):\n \"Return divide(self, other)\"\n return true_divide(self, other)\n\n def __rtruediv__(self, other):\n \"Return divide(other, self)\"\n return true_divide(other, self)\n\n def __floordiv__(self, other):\n \"Return divide(self, other)\"\n return floor_divide(self, other)\n\n def __rfloordiv__(self, other):\n \"Return divide(other, self)\"\n return floor_divide(other, self)\n\n def __pow__(self, other, third=None):\n \"Return power(self, other, third)\"\n return power(self, other, third)\n\n def __sqrt__(self):\n \"Return sqrt(self)\"\n return sqrt(self)\n\n def __iadd__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtype.char\n f = filled(other, 0)\n t1 = f.dtype.char\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data += f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = add(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __imul__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtype.char\n f = filled(other, 0)\n t1 = f.dtype.char\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data *= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = multiply(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __isub__(self, other):\n \"Subtract other from self in place.\"\n t = self._data.dtype.char\n f = filled(other, 0)\n t1 = f.dtype.char\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data -= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = subtract(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n\n\n def __idiv__(self, other):\n \"Divide self by other in place.\"\n t = self._data.dtype.char\n f = filled(other, 0)\n t1 = f.dtype.char\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n mo = getmask(other)\n result = divide(self, masked_array(f, mask=mo))\n self._data = result.data\n dm = result.raw_mask()\n if dm is not self._mask:\n self._mask = dm\n self._shared_mask = 1\n return self\n\n def __eq__(self, other):\n return equal(self,other)\n\n def __ne__(self, other):\n return not_equal(self,other)\n\n def __lt__(self, other):\n return less(self,other)\n\n def __le__(self, other):\n return less_equal(self,other)\n\n def __gt__(self, other):\n return greater(self,other)\n\n def __ge__(self, other):\n return greater_equal(self,other)\n\n def astype (self, tc):\n \"return self as array of given type.\"\n d = self._data.astype(tc)\n return array(d, mask=self._mask)\n\n def byte_swapped(self):\n \"\"\"Returns the raw data field, byte_swapped. Included for consistency\n with numeric but doesn't make sense in this context.\n \"\"\"\n return self._data.byte_swapped()\n\n def compressed (self):\n \"A 1-D array of all the non-masked data.\"\n d = oldnumeric.ravel(self._data)\n if self._mask is nomask:\n return array(d)\n else:\n m = 1 - oldnumeric.ravel(self._mask)\n c = oldnumeric.compress(m, d)\n return array(c, copy=0)\n\n def count (self, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n m = self._mask\n s = self._data.shape\n ls = len(s)\n if m is nomask:\n if ls == 0:\n return 1\n if ls == 1:\n return s[0]\n if axis is None:\n return reduce(lambda x, y:x*y, s)\n else:\n n = s[axis]\n t = list(s)\n del t[axis]\n return ones(t) * n\n if axis is None:\n w = oldnumeric.ravel(m).astype(int)\n n1 = size(w)\n if n1 == 1:\n n2 = w[0]\n else:\n n2 = umath.add.reduce(w)\n return n1 - n2\n else:\n n1 = size(m, axis)\n n2 = sum(m.astype(int), axis)\n return n1 - n2\n\n def dot (self, other):\n \"s.dot(other) = innerproduct(s, other)\"\n return innerproduct(self, other)\n\n def fill_value(self):\n \"Get the current fill value.\"\n return self._fill_value\n\n def filled (self, fill_value=None):\n \"\"\"A numeric array with masked values filled. If fill_value is None,\n use self.fill_value().\n\n If mask is nomask, copy data only if not contiguous.\n Result is always a contiguous, numeric array.\n# Is contiguous really necessary now?\n \"\"\"\n d = self._data\n m = self._mask\n if m is nomask:\n if d.flags['CONTIGUOUS']:\n return d\n else:\n return d.copy()\n else:\n if fill_value is None:\n value = self._fill_value\n else:\n value = fill_value\n\n if self is masked:\n result = numeric.array(value)\n else:\n try:\n result = numeric.array(d, dtype=d.dtype, copy=1)\n result[m] = value\n except (TypeError, AttributeError):\n #ok, can't put that value in here\n value = numeric.array(value, dtype=object)\n d = d.astype(object)\n result = oldnumeric.choose(m, (d, value))\n except IndexError:\n #ok, if scalar\n if d.shape:\n raise\n elif m:\n result = numeric.array(value, dtype=d.dtype)\n else:\n result = d\n return result\n\n def ids (self):\n \"\"\"Return the ids of the data and mask areas\"\"\"\n return (id(self._data), id(self._mask))\n\n def iscontiguous (self):\n \"Is the data contiguous?\"\n return self._data.flags['CONTIGUOUS']\n\n def itemsize(self):\n \"Item size of each data item.\"\n return self._data.itemsize\n\n\n def outer(self, other):\n \"s.outer(other) = outerproduct(s, other)\"\n return outerproduct(self, other)\n\n def put (self, values):\n \"\"\"Set the non-masked entries of self to filled(values).\n No change to mask\n \"\"\"\n iota = numeric.arange(self.size)\n d = self._data\n if self._mask is nomask:\n ind = iota\n else:\n ind = oldnumeric.compress(1 - self._mask, iota)\n d[ind] = filled(values).astype(d.dtype)\n\n def putmask (self, values):\n \"\"\"Set the masked entries of self to filled(values).\n Mask changed to nomask.\n \"\"\"\n d = self._data\n if self._mask is not nomask:\n d[self._mask] = filled(values).astype(d.dtype)\n self._shared_mask = 0\n self._mask = nomask\n\n def ravel (self):\n \"\"\"Return a 1-D view of self.\"\"\"\n if self._mask is nomask:\n return masked_array(self._data.ravel())\n else:\n return masked_array(self._data.ravel(), self._mask.ravel())\n\n def raw_data (self):\n \"\"\" Obsolete; use data property instead.\n The raw data; portions may be meaningless.\n May be noncontiguous. Expert use only.\"\"\"\n return self._data\n data = property(fget=raw_data,\n doc=\"The data, but values at masked locations are meaningless.\")\n\n def raw_mask (self):\n \"\"\" Obsolete; use mask property instead.\n May be noncontiguous. Expert use only.\n \"\"\"\n return self._mask\n mask = property(fget=raw_mask,\n doc=\"The mask, may be nomask. Values where mask true are meaningless.\")\n\n def reshape (self, *s):\n \"\"\"This array reshaped to shape s\"\"\"\n d = self._data.reshape(*s)\n if self._mask is nomask:\n return masked_array(d)\n else:\n m = self._mask.reshape(*s)\n return masked_array(d, m)\n\n def set_fill_value (self, v=None):\n \"Set the fill value to v. Omit v to restore default.\"\n if v is None:\n v = default_fill_value (self.raw_data())\n self._fill_value = v\n\n def _get_ndim(self):\n return self._data.ndim\n ndim = property(_get_ndim, doc=numeric.ndarray.ndim.__doc__)\n\n def _get_size (self):\n return self._data.size\n size = property(fget=_get_size, doc=\"Number of elements in the array.\")\n## CHECK THIS: signature of numeric.array.size?\n\n def _get_dtype(self):\n return self._data.dtype\n dtype = property(fget=_get_dtype, doc=\"type of the array elements.\")\n\n def item(self):\n \"Return Python scalar if possible.\"\n if self._mask is not nomask:\n m = oldnumeric.ravel(self._mask)\n try:\n if m[0]:\n return masked\n except IndexError:\n return masked\n return self._data.item()\n\n def tolist(self, fill_value=None):\n \"Convert to list\"\n return self.filled(fill_value).tolist()\n\n def tostring(self, fill_value=None):\n \"Convert to string\"\n return self.filled(fill_value).tostring()\n\n def unmask (self):\n \"Replace the mask by nomask if possible.\"\n if self._mask is nomask: return\n m = make_mask(self._mask, flag=1)\n if m is nomask:\n self._mask = nomask\n self._shared_mask = 0\n\n def unshare_mask (self):\n \"If currently sharing mask, make a copy.\"\n if self._shared_mask:\n self._mask = make_mask (self._mask, copy=1, flag=0)\n self._shared_mask = 0\n\n shape = property(_get_shape, _set_shape,\n doc = 'tuple giving the shape of the array')\n\n flat = property(_get_flat, _set_flat,\n doc = 'Access array in flat form.')\n\n real = property(_get_real, _set_real,\n doc = 'Access the real part of the array')\n\n imaginary = property(_get_imaginary, _set_imaginary,\n doc = 'Access the imaginary part of the array')\n\n imag = imaginary\n\n#end class MaskedArray\n\narray = MaskedArray\n\ndef isMaskedArray (x):\n \"Is x a masked array, that is, an instance of MaskedArray?\"\n return isinstance(x, MaskedArray)\n\nisarray = isMaskedArray\nisMA = isMaskedArray #backward compatibility\n\ndef allclose (a, b, fill_value=1, rtol=1.e-5, atol=1.e-8):\n \"\"\" Returns true if all components of a and b are equal\n subject to given tolerances.\n If fill_value is 1, masked values considered equal.\n If fill_value is 0, masked values considered unequal.\n The relative error rtol should be positive and << 1.0\n The absolute error atol comes into play for those elements\n of b that are very small or zero; it says how small a must be also.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a)\n d2 = filled(b)\n x = filled(array(d1, copy=0, mask=m), fill_value).astype(float)\n y = filled(array(d2, copy=0, mask=m), 1).astype(float)\n d = umath.less_equal(umath.absolute(x-y), atol + rtol * umath.absolute(y))\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n\ndef allequal (a, b, fill_value=1):\n \"\"\"\n True if all entries of a and b are equal, using\n fill_value as a truth value where either or both are masked.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n if m is nomask:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n elif fill_value:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n dm = array(d, mask=m, copy=0)\n return oldnumeric.alltrue(oldnumeric.ravel(filled(dm, 1)))\n else:\n return 0\n\ndef masked_values (data, value, rtol=1.e-5, atol=1.e-8, copy=1):\n \"\"\"\n masked_values(data, value, rtol=1.e-5, atol=1.e-8)\n Create a masked array; mask is nomask if possible.\n If copy==0, and otherwise possible, result\n may share data values with original array.\n Let d = filled(data, value). Returns d\n masked where abs(data-value)<= atol + rtol * abs(value)\n if d is of a floating point type. Otherwise returns\n masked_object(d, value, copy)\n \"\"\"\n abs = umath.absolute\n d = filled(data, value)\n if issubclass(d.dtype.type, numeric.floating):\n m = umath.less_equal(abs(d-value), atol+rtol*abs(value))\n m = make_mask(m, flag=1)\n return array(d, mask = m, copy=copy,\n fill_value=value)\n else:\n return masked_object(d, value, copy=copy)\n\ndef masked_object (data, value, copy=1):\n \"Create array masked where exactly data equal to value\"\n d = filled(data, value)\n dm = make_mask(umath.equal(d, value), flag=1)\n return array(d, mask=dm, copy=copy, fill_value=value)\n\ndef arrayrange(start, stop=None, step=1, dtype=None):\n \"\"\"Just like range() except it returns a array whose type can be specified\n by the keyword argument dtype.\n \"\"\"\n return array(numeric.arrayrange(start, stop, step, dtype))\n\narange = arrayrange\n\ndef fromstring (s, t):\n \"Construct a masked array from a string. Result will have no mask.\"\n return masked_array(numeric.fromstring(s, t))\n\ndef left_shift (a, n):\n \"Left shift n bits\"\n m = getmask(a)\n if m is nomask:\n d = umath.left_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.left_shift(filled(a, 0), n)\n return masked_array(d, m)\n\ndef right_shift (a, n):\n \"Right shift n bits\"\n m = getmask(a)\n if m is nomask:\n d = umath.right_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.right_shift(filled(a, 0), n)\n return masked_array(d, m)\n\ndef resize (a, new_shape):\n \"\"\"resize(a, new_shape) returns a new array with the specified shape.\n The original array's total size can be any size.\"\"\"\n m = getmask(a)\n if m is not nomask:\n m = oldnumeric.resize(m, new_shape)\n result = array(oldnumeric.resize(filled(a), new_shape), mask=m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n \"\"\"\n af = filled(a)\n if isinstance(repeats, types.IntType):\n repeats = tuple([repeats]*(shape(af)[axis]))\n\n m = getmask(a)\n if m is not nomask:\n m = oldnumeric.repeat(m, repeats, axis)\n d = oldnumeric.repeat(af, repeats, axis)\n result = masked_array(d, m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef identity(n):\n \"\"\"identity(n) returns the identity matrix of shape n x n.\n \"\"\"\n return array(numeric.identity(n))\n\ndef indices (dimensions, dtype=None):\n \"\"\"indices(dimensions,dtype=None) returns an array representing a grid\n of indices with row-only, and column-only variation.\n \"\"\"\n return array(numeric.indices(dimensions, dtype))\n\ndef zeros (shape, dtype=int):\n \"\"\"zeros(n, dtype=int) =\n an array of all zeros of the given length or shape.\"\"\"\n return array(numeric.zeros(shape, dtype))\n\ndef ones (shape, dtype=int):\n \"\"\"ones(n, dtype=int) =\n an array of all ones of the given length or shape.\"\"\"\n return array(numeric.ones(shape, dtype))\n\n\ndef count (a, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n a = masked_array(a)\n return a.count(axis)\n\ndef power (a, b, third=None):\n \"a**b\"\n if third is not None:\n raise MAError, \"3-argument power not supported.\"\n ma = getmask(a)\n mb = getmask(b)\n m = mask_or(ma, mb)\n fa = filled(a, 1)\n fb = filled(b, 1)\n if fb.dtype.char in typecodes[\"Integer\"]:\n return masked_array(umath.power(fa, fb), m)\n md = make_mask(umath.less_equal (fa, 0), flag=1)\n m = mask_or(m, md)\n if m is nomask:\n return masked_array(umath.power(fa, fb))\n else:\n fa = numeric.where(m, 1, fa)\n return masked_array(umath.power(fa, fb), m)\n\ndef masked_array (a, mask=nomask, fill_value=None):\n \"\"\"masked_array(a, mask=nomask) =\n array(a, mask=mask, copy=0, fill_value=fill_value)\n \"\"\"\n return array(a, mask=mask, copy=0, fill_value=fill_value)\n\nsum = add.reduce\nproduct = multiply.reduce\n\ndef average (a, axis=0, weights=None, returned = 0):\n \"\"\"average(a, axis=0, weights=None)\n Computes average along indicated axis.\n If axis is None, average over the entire array\n Inputs can be integer or floating types; result is of type float.\n\n If weights are given, result is sum(a*weights)/(sum(weights)*1.0)\n weights must have a's shape or be the 1-d with length the size\n of a in the given axis.\n\n If returned, return a tuple: the result and the sum of the weights\n or count of values. Results will have the same shape.\n\n masked values in the weights will be set to 0.0\n \"\"\"\n a = masked_array(a)\n mask = a.mask\n ash = a.shape\n if ash == ():\n ash = (1,)\n if axis is None:\n if mask is nomask:\n if weights is None:\n n = add.reduce(a.raw_data().ravel())\n d = reduce(lambda x, y: x * y, ash, 1.0)\n else:\n w = filled(weights, 0.0).ravel()\n n = umath.add.reduce(a.raw_data().ravel() * w)\n d = umath.add.reduce(w)\n del w\n else:\n if weights is None:\n n = add.reduce(a.ravel())\n w = oldnumeric.choose(mask, (1.0, 0.0)).ravel()\n d = umath.add.reduce(w)\n del w\n else:\n w = array(filled(weights, 0.0), float, mask=mask).ravel()\n n = add.reduce(a.ravel() * w)\n d = add.reduce(w)\n del w\n else:\n if mask is nomask:\n if weights is None:\n d = ash[axis] * 1.0\n n = umath.add.reduce(a.raw_data(), axis)\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = numeric.array(w, float, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None, None, 1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * ones(ash, float)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w, r\n else:\n raise ValueError, 'average: weights wrong shape.'\n else:\n if weights is None:\n n = add.reduce(a, axis)\n w = numeric.choose(mask, (1.0, 0.0))\n d = umath.add.reduce(w, axis)\n del w\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = array(w, float, mask=mask, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None, None, 1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * masked_array(ones(ash, float), mask)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n else:\n raise ValueError, 'average: weights wrong shape.'\n del w\n #print n, d, repr(mask), repr(weights)\n if n is masked or d is masked: return masked\n result = divide (n, d)\n del n\n\n if isinstance(result, MaskedArray):\n result.unmask()\n if returned:\n if not isinstance(d, MaskedArray):\n d = masked_array(d)\n if not d.shape == result.shape:\n d = ones(result.shape, float) * d\n d.unmask()\n if returned:\n return result, d\n else:\n return result\n\ndef where (condition, x, y):\n \"\"\"where(condition, x, y) is x where condition is nonzero, y otherwise.\n condition must be convertible to an integer array.\n Answer is always the shape of condition.\n The type depends on x and y. It is integer if both x and y are\n the value masked.\n \"\"\"\n fc = filled(not_equal(condition, 0), 0)\n xv = filled(x)\n xm = getmask(x)\n yv = filled(y)\n ym = getmask(y)\n d = numeric.choose(fc, (yv, xv))\n md = numeric.choose(fc, (ym, xm))\n m = getmask(condition)\n m = make_mask(mask_or(m, md), copy=0, flag=1)\n return masked_array(d, m)\n\ndef choose (indices, t):\n \"Returns array shaped like indices with elements chosen from t\"\n def fmask (x):\n if x is masked: return 1\n return filled(x)\n def nmask (x):\n if x is masked: return 1\n m = getmask(x)\n if m is nomask: return 0\n return m\n c = filled(indices, 0)\n masks = [nmask(x) for x in t]\n a = [fmask(x) for x in t]\n d = numeric.choose(c, a)\n m = numeric.choose(c, masks)\n m = make_mask(mask_or(m, getmask(indices)), copy=0, flag=1)\n return masked_array(d, m)\n\ndef masked_where(condition, x, copy=1):\n \"\"\"Return x as an array masked where condition is true.\n Also masked where x or condition masked.\n \"\"\"\n cm = filled(condition,1)\n m = mask_or(getmask(x), cm)\n return array(filled(x), copy=copy, mask=m)\n\ndef masked_greater(x, value, copy=1):\n \"masked_greater(x, value) = x masked where x > value\"\n return masked_where(greater(x, value), x, copy)\n\ndef masked_greater_equal(x, value, copy=1):\n \"masked_greater_equal(x, value) = x masked where x >= value\"\n return masked_where(greater_equal(x, value), x, copy)\n\ndef masked_less(x, value, copy=1):\n \"masked_less(x, value) = x masked where x < value\"\n return masked_where(less(x, value), x, copy)\n\ndef masked_less_equal(x, value, copy=1):\n \"masked_less_equal(x, value) = x masked where x <= value\"\n return masked_where(less_equal(x, value), x, copy)\n\ndef masked_not_equal(x, value, copy=1):\n \"masked_not_equal(x, value) = x masked where x != value\"\n d = filled(x, 0)\n c = umath.not_equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_equal(x, value, copy=1):\n \"\"\"masked_equal(x, value) = x masked where x == value\n For floating point consider masked_values(x, value) instead.\n \"\"\"\n d = filled(x, 0)\n c = umath.equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_inside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are inside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d = filled(x, 0)\n c = umath.logical_and(umath.less_equal(d, v2), umath.greater_equal(d, v1))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef masked_outside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are outside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d = filled(x, 0)\n c = umath.logical_or(umath.less(d, v1), umath.greater(d, v2))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef reshape (a, *newshape):\n \"Copy of a with a new shape.\"\n m = getmask(a)\n d = filled(a).reshape(*newshape)\n if m is nomask:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.reshape(m, *newshape))\n\ndef ravel (a):\n \"a as one-dimensional, may share data and mask\"\n m = getmask(a)\n d = oldnumeric.ravel(filled(a))\n if m is nomask:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.ravel(m))\n\ndef concatenate (arrays, axis=0):\n \"Concatenate the arrays along the given axis\"\n d = []\n for x in arrays:\n d.append(filled(x))\n d = numeric.concatenate(d, axis)\n for x in arrays:\n if getmask(x) is not nomask: break\n else:\n return masked_array(d)\n dm = []\n for x in arrays:\n dm.append(getmaskarray(x))\n dm = numeric.concatenate(dm, axis)\n return masked_array(d, mask=dm)\n\ndef take (a, indices, axis=0):\n \"take(a, indices, axis=0) returns selection of items from a.\"\n m = getmask(a)\n d = masked_array(a).raw_data()\n if m is nomask:\n return masked_array(numeric.take(d, indices, axis))\n else:\n return masked_array(numeric.take(d, indices, axis),\n mask = numeric.take(m, indices, axis))\n\ndef transpose(a, axes=None):\n \"transpose(a, axes=None) reorder dimensions per tuple axes\"\n m = getmask(a)\n d = filled(a)\n if m is nomask:\n return masked_array(numeric.transpose(d, axes))\n else:\n return masked_array(numeric.transpose(d, axes),\n mask = numeric.transpose(m, axes))\n\n\ndef put(a, indices, values):\n \"\"\"put(a, indices, values) sets storage-indexed locations to corresponding values.\n\n Values and indices are filled if necessary.\n\n \"\"\"\n d = a.raw_data()\n ind = filled(indices)\n v = filled(values)\n numeric.put (d, ind, v)\n m = getmask(a)\n if m is not nomask:\n a.unshare_mask()\n numeric.put(a.raw_mask(), ind, 0)\n\ndef putmask(a, mask, values):\n \"putmask(a, mask, values) sets a where mask is true.\"\n if mask is nomask:\n return\n numeric.putmask(a.raw_data(), mask, values)\n m = getmask(a)\n if m is nomask: return\n a.unshare_mask()\n numeric.putmask(a.raw_mask(), mask, 0)\n\ndef innerproduct(a, b):\n \"\"\"innerproduct(a,b) returns the dot product of two arrays, which has\n shape a.shape[:-1] + b.shape[:-1] with elements computed by summing the\n product of the elements from the last dimensions of a and b.\n Masked elements are replace by zeros.\n \"\"\"\n fa = filled(a, 0)\n fb = filled(b, 0)\n if len(fa.shape) == 0: fa.shape = (1,)\n if len(fb.shape) == 0: fb.shape = (1,)\n return masked_array(numeric.innerproduct(fa, fb))\n\ndef outerproduct(a, b):\n \"\"\"outerproduct(a,b) = {a[i]*b[j]}, has shape (len(a),len(b))\"\"\"\n fa = filled(a, 0).ravel()\n fb = filled(b, 0).ravel()\n d = numeric.outerproduct(fa, fb)\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n return masked_array(d)\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = make_mask(1-numeric.outerproduct(1-ma, 1-mb), copy=0)\n return masked_array(d, m)\n\ndef dot(a, b):\n \"\"\"dot(a,b) returns matrix-multiplication between a and b. The product-sum\n is over the last dimension of a and the second-to-last dimension of b.\n Masked values are replaced by zeros. See also innerproduct.\n \"\"\"\n return innerproduct(filled(a, 0), numeric.swapaxes(filled(b, 0), -1, -2))\n\ndef compress(condition, x, dimension=-1):\n \"\"\"Select those parts of x for which condition is true.\n Masked values in condition are considered false.\n \"\"\"\n c = filled(condition, 0)\n m = getmask(x)\n if m is not nomask:\n m = numeric.compress(c, m, dimension)\n d = numeric.compress(c, filled(x), dimension)\n return masked_array(d, m)\n\nclass _minimum_operation:\n \"Object to calculate minima\"\n def __init__ (self):\n \"\"\"minimum(a, b) or minimum(a)\n In one argument case returns the scalar minimum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is nomask:\n d = amin(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amin(ac.raw_data())\n else:\n return where(less(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is nomask:\n t = filled(target)\n return masked_array (umath.minimum.reduce (t, axis))\n else:\n t = umath.minimum.reduce(filled(target, minimum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.minimum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nminimum = _minimum_operation ()\n\nclass _maximum_operation:\n \"Object to calculate maxima\"\n def __init__ (self):\n \"\"\"maximum(a, b) or maximum(a)\n In one argument case returns the scalar maximum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is nomask:\n d = amax(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amax(ac.raw_data())\n else:\n return where(greater(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is nomask:\n t = filled(target)\n return masked_array (umath.maximum.reduce (t, axis))\n else:\n t = umath.maximum.reduce(filled(target, maximum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.maximum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nmaximum = _maximum_operation ()\n\ndef sort (x, axis = -1, fill_value=None):\n \"\"\"If x does not have a mask, return a masked array formed from the\n result of numeric.sort(x, axis).\n Otherwise, fill x with fill_value. Sort it.\n Set a mask where the result is equal to fill_value.\n Note that this may have unintended consequences if the data contains the\n fill value at a non-masked site.\n\n If fill_value is not given the default fill value for x's type will be\n used.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n d = filled(x, fill_value)\n s = oldnumeric.sort(d, axis)\n if getmask(x) is nomask:\n return masked_array(s)\n return masked_values(s, fill_value, copy=0)\n\ndef diagonal(a, k = 0, axis1=0, axis2=1):\n \"\"\"diagonal(a,k=0,axis1=0, axis2=1) = the k'th diagonal of a\"\"\"\n d = oldnumeric.diagonal(filled(a), k, axis1, axis2)\n m = getmask(a)\n if m is nomask:\n return masked_array(d, m)\n else:\n return masked_array(d, oldnumeric.diagonal(m, k, axis1, axis2))\n\ndef argsort (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for sorting along given axis.\n if fill_value is None, use get_fill_value(x)\n Returns a numpy array.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argsort(d, axis)\n\ndef argmin (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return indices for minimum values along given axis.\n if fill_value is None, use get_fill_value(x).\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argmin(d, axis)\n\ndef argmax (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for maximum along given axis.\n if fill_value is None, use -get_fill_value(x) if it exists.\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n try:\n fill_value = - fill_value\n except:\n pass\n d = filled(x, fill_value)\n return oldnumeric.argmax(d, axis)\n\ndef fromfunction (f, s):\n \"\"\"apply f to s to create array as in umath.\"\"\"\n return masked_array(numeric.fromfunction(f, s))\n\ndef asarray(data, dtype=None):\n \"\"\"asarray(data, dtype) = array(data, dtype, copy=0)\n \"\"\"\n if isinstance(data, MaskedArray) and \\\n (dtype is None or dtype == data.dtype):\n return data\n return array(data, dtype=dtype, copy=0)\n\n# Add methods to support ndarray interface\n# XXX: I is better to to change the masked_*_operation adaptors\n# XXX: to wrap ndarray methods directly to create ma.array methods.\nfrom types import MethodType\ndef _m(f):\n return MethodType(f, None, array)\ndef not_implemented(*args, **kwds):\n raise NotImplementedError, \"not yet implemented for numpy.ma arrays\"\narray.all = _m(alltrue)\narray.any = _m(sometrue)\narray.argmax = _m(argmax)\narray.argmin = _m(argmin)\narray.argsort = _m(argsort)\narray.base = property(_m(not_implemented))\narray.byteswap = _m(not_implemented)\n\ndef _choose(self, *args):\n return choose(self, args)\narray.choose = _m(_choose)\ndel _choose\n\narray.clip = _m(not_implemented)\n\ndef _compress(self, cond, axis=None):\n return compress(cond, self, axis)\narray.compress = _m(_compress)\ndel _compress\n\narray.conj = array.conjugate = _m(conjugate)\narray.copy = _m(not_implemented)\narray.cumprod = _m(not_implemented)\narray.cumsum = _m(not_implemented)\narray.diagonal = _m(diagonal)\narray.dump = _m(not_implemented)\narray.dumps = _m(not_implemented)\narray.fill = _m(not_implemented)\narray.flags = property(_m(not_implemented))\narray.flatten = _m(ravel)\narray.getfield = _m(not_implemented)\ndef _max(a, axis=None):\n if axis is None:\n return maximum(a)\n else:\n return maximum.reduce(a, axis)\narray.max = _m(_max)\ndel _max\ndef _min(a, axis=None):\n if axis is None:\n return minimum(a)\n else:\n return minimum.reduce(a, axis)\narray.min = _m(_min)\ndel _min\narray.mean = _m(average)\narray.nbytes = property(_m(not_implemented))\narray.newbyteorder = _m(not_implemented)\narray.nonzero = _m(nonzero)\narray.prod = _m(product)\narray.ptp = _m(not_implemented)\narray.repeat = _m(repeat)\narray.resize = _m(resize)\narray.searchsorted = _m(not_implemented)\narray.setfield = _m(not_implemented)\narray.setflags = _m(not_implemented)\narray.sort = _m(not_implemented) # NB: ndarray.sort is inplace\narray.squeeze = _m(not_implemented)\narray.std = _m(not_implemented)\narray.strides = property(_m(not_implemented))\narray.sum = _m(sum)\narray.swapaxes = _m(not_implemented)\narray.take = _m(take)\narray.tofile = _m(not_implemented)\narray.trace = _m(not_implemented)\narray.transpose = _m(transpose)\narray.var = _m(not_implemented)\narray.view = _m(not_implemented)\narray.round = _m(around)\ndel _m, MethodType, not_implemented\n\n\nmasked = MaskedArray(0, int, mask=1)\n", + "source_code_before": "\"\"\"MA: a facility for dealing with missing observations\nMA is generally used as a numpy.array look-alike.\nby Paul F. Dubois.\n\nCopyright 1999, 2000, 2001 Regents of the University of California.\nReleased for unlimited redistribution.\nAdapted for numpy_core 2005 by Travis Oliphant and\n(mainly) Paul Dubois.\n\"\"\"\nimport types, sys\n\nimport umath\nimport oldnumeric\nfrom numeric import newaxis, ndarray, inf\nfrom oldnumeric import typecodes, amax, amin\nfrom numerictypes import *\nimport numeric\nimport warnings\n\n# Ufunc domain lookup for __array_wrap__\nufunc_domain = {}\n# Ufunc fills lookup for __array__\nufunc_fills = {}\n\nMaskType = bool_\nnomask = MaskType(0)\ndivide_tolerance = 1.e-35\n\nclass MAError (Exception):\n def __init__ (self, args=None):\n \"Create an exception\"\n self.args = args\n def __str__(self):\n \"Calculate the string representation\"\n return str(self.args)\n __repr__ = __str__\n\nclass _MaskedPrintOption:\n \"One instance of this class, masked_print_option, is created.\"\n def __init__ (self, display):\n \"Create the masked print option object.\"\n self.set_display(display)\n self._enabled = 1\n\n def display (self):\n \"Show what prints for masked values.\"\n return self._display\n\n def set_display (self, s):\n \"set_display(s) sets what prints for masked values.\"\n self._display = s\n\n def enabled (self):\n \"Is the use of the display value enabled?\"\n return self._enabled\n\n def enable(self, flag=1):\n \"Set the enabling flag to flag.\"\n self._enabled = flag\n\n def __str__ (self):\n return str(self._display)\n\n __repr__ = __str__\n\n#if you single index into a masked location you get this object.\nmasked_print_option = _MaskedPrintOption('--')\n\n# Use single element arrays or scalars.\ndefault_real_fill_value = 1.e20\ndefault_complex_fill_value = 1.e20 + 0.0j\ndefault_character_fill_value = '-'\ndefault_integer_fill_value = 999999\ndefault_object_fill_value = '?'\n\ndef default_fill_value (obj):\n \"Function to calculate default fill value for an object.\"\n if isinstance(obj, types.FloatType):\n return default_real_fill_value\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return default_integer_fill_value\n elif isinstance(obj, types.StringType):\n return default_character_fill_value\n elif isinstance(obj, types.ComplexType):\n return default_complex_fill_value\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtype.char\n if x in typecodes['Float']:\n return default_real_fill_value\n if x in typecodes['Integer']:\n return default_integer_fill_value\n if x in typecodes['Complex']:\n return default_complex_fill_value\n if x in typecodes['Character']:\n return default_character_fill_value\n if x in typecodes['UnsignedInteger']:\n return umath.absolute(default_integer_fill_value)\n return default_object_fill_value\n else:\n return default_object_fill_value\n\ndef minimum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking minima.\"\n if isinstance(obj, types.FloatType):\n return numeric.inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtype.char\n if x in typecodes['Float']:\n return numeric.inf\n if x in typecodes['Integer']:\n return sys.maxint\n if x in typecodes['UnsignedInteger']:\n return sys.maxint\n else:\n raise TypeError, 'Unsuitable type for calculating minimum.'\n\ndef maximum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking maxima.\"\n if isinstance(obj, types.FloatType):\n return -inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return -sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtype.char\n if x in typecodes['Float']:\n return -inf\n if x in typecodes['Integer']:\n return -sys.maxint\n if x in typecodes['UnsignedInteger']:\n return 0\n else:\n raise TypeError, 'Unsuitable type for calculating maximum.'\n\ndef set_fill_value (a, fill_value):\n \"Set fill value of a if it is a masked array.\"\n if isMaskedArray(a):\n a.set_fill_value (fill_value)\n\ndef getmask (a):\n \"\"\"Mask of values in a; could be nomask.\n Returns nomask if a is not a masked array.\n To get an array for sure use getmaskarray.\"\"\"\n if isinstance(a, MaskedArray):\n return a.raw_mask()\n else:\n return nomask\n\ndef getmaskarray (a):\n \"\"\"Mask of values in a; an array of zeros if mask is nomask\n or not a masked array, and is a byte-sized integer.\n Do not try to add up entries, for example.\n \"\"\"\n m = getmask(a)\n if m is nomask:\n return make_mask_none(shape(a))\n else:\n return m\n\ndef is_mask (m):\n \"\"\"Is m a legal mask? Does not check contents, only type.\n \"\"\"\n try:\n return m.dtype.type is MaskType\n except AttributeError:\n return False\n\ndef make_mask (m, copy=0, flag=0):\n \"\"\"make_mask(m, copy=0, flag=0)\n return m as a mask, creating a copy if necessary or requested.\n Can accept any sequence of integers or nomask. Does not check\n that contents must be 0s and 1s.\n if flag, return nomask if m contains no true elements.\n \"\"\"\n if m is nomask:\n return nomask\n elif isinstance(m, ndarray):\n if m.dtype.type is MaskType:\n if copy:\n result = numeric.array(m, dtype=MaskType, copy=copy)\n else:\n result = m\n else:\n result = m.astype(MaskType)\n else:\n result = filled(m, True).astype(MaskType)\n\n if flag and not oldnumeric.sometrue(oldnumeric.ravel(result)):\n return nomask\n else:\n return result\n\ndef make_mask_none (s):\n \"Return a mask of all zeros of shape s.\"\n result = numeric.zeros(s, dtype=MaskType)\n result.shape = s\n return result\n\ndef mask_or (m1, m2):\n \"\"\"Logical or of the mask candidates m1 and m2, treating nomask as false.\n Result may equal m1 or m2 if the other is nomask.\n \"\"\"\n if m1 is nomask: return make_mask(m2)\n if m2 is nomask: return make_mask(m1)\n if m1 is m2 and is_mask(m1): return m1\n return make_mask(umath.logical_or(m1, m2))\n\ndef filled (a, value = None):\n \"\"\"a as a contiguous numeric array with any masked areas replaced by value\n if value is None or the special element \"masked\", get_fill_value(a)\n is used instead.\n\n If a is already a contiguous numeric array, a itself is returned.\n\n filled(a) can be used to be sure that the result is numeric when\n passing an object a to other software ignorant of MA, in particular to\n numeric itself.\n \"\"\"\n if isinstance(a, MaskedArray):\n return a.filled(value)\n elif isinstance(a, ndarray) and a.flags['CONTIGUOUS']:\n return a\n elif isinstance(a, types.DictType):\n return numeric.array(a, 'O')\n else:\n return numeric.array(a)\n\ndef get_fill_value (a):\n \"\"\"\n The fill value of a, if it has one; otherwise, the default fill value\n for that type.\n \"\"\"\n if isMaskedArray(a):\n result = a.fill_value()\n else:\n result = default_fill_value(a)\n return result\n\ndef common_fill_value (a, b):\n \"The common fill_value of a and b, if there is one, or None\"\n t1 = get_fill_value(a)\n t2 = get_fill_value(b)\n if t1 == t2: return t1\n return None\n\n# Domain functions return 1 where the argument(s) are not in the domain.\nclass domain_check_interval:\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n def __init__(self, y1, y2):\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n self.y1 = y1\n self.y2 = y2\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.logical_or(umath.greater (x, self.y2),\n umath.less(x, self.y1)\n )\n\nclass domain_tan:\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n def __init__(self, eps):\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n self.eps = eps\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less(umath.absolute(umath.cos(x)), self.eps)\n\nclass domain_greater:\n \"domain_greater(v)(x) = true where x <= v\"\n def __init__(self, critical_value):\n \"domain_greater(v)(x) = true where x <= v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less_equal (x, self.critical_value)\n\nclass domain_greater_equal:\n \"domain_greater_equal(v)(x) = true where x < v\"\n def __init__(self, critical_value):\n \"domain_greater_equal(v)(x) = true where x < v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less (x, self.critical_value)\n\nclass masked_unary_operation:\n def __init__ (self, aufunc, fill=0, domain=None):\n \"\"\" masked_unary_operation(aufunc, fill=0, domain=None)\n aufunc(fill) must be defined\n self(x) returns aufunc(x)\n with masked values where domain(x) is true or getmask(x) is true.\n \"\"\"\n self.f = aufunc\n self.fill = fill\n self.domain = domain\n self.__doc__ = getattr(aufunc, \"__doc__\", str(aufunc))\n self.__name__ = getattr(aufunc, \"__name__\", str(aufunc))\n ufunc_domain[aufunc] = domain\n ufunc_fills[aufunc] = fill,\n\n def __call__ (self, a, *args, **kwargs):\n \"Execute the call behavior.\"\n# numeric tries to return scalars rather than arrays when given scalars.\n m = getmask(a)\n d1 = filled(a, self.fill)\n if self.domain is not None:\n m = mask_or(m, self.domain(d1))\n result = self.f(d1, *args, **kwargs)\n return masked_array(result, m)\n\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\n\nclass domain_safe_divide:\n def __init__ (self, tolerance=divide_tolerance):\n self.tolerance = tolerance\n def __call__ (self, a, b):\n return umath.absolute(a) * self.tolerance >= umath.absolute(b)\n\nclass domained_binary_operation:\n \"\"\"Binary operations that have a domain, like divide. These are complicated\n so they are a separate class. They have no reduce, outer or accumulate.\n \"\"\"\n def __init__ (self, abfunc, domain, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.domain = domain\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n self.__name__ = getattr(abfunc, \"__name__\", str(abfunc))\n ufunc_domain[abfunc] = domain\n ufunc_fills[abfunc] = fillx, filly\n\n def __call__(self, a, b):\n \"Execute the call behavior.\"\n ma = getmask(a)\n mb = getmask(b)\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n t = self.domain(d1, d2)\n\n if oldnumeric.sometrue(t, None):\n d2 = where(t, self.filly, d2)\n mb = mask_or(mb, t)\n m = mask_or(ma, mb)\n result = self.f(d1, d2)\n return masked_array(result, m)\n\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nclass masked_binary_operation:\n def __init__ (self, abfunc, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n ufunc_domain[abfunc] = None\n ufunc_fills[abfunc] = fillx, filly\n\n def __call__ (self, a, b, *args, **kwargs):\n \"Execute the call behavior.\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n result = self.f(d1, d2, *args, **kwargs)\n return masked_array(result, m)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis with this function.\"\"\"\n m = getmask(target)\n t = filled(target, self.filly)\n if t.shape == ():\n t = t.reshape(1)\n if m is not nomask:\n m = make_mask(m, copy=1)\n m.shape = (1,)\n if m is nomask:\n return masked_array (self.f.reduce (t, axis))\n else:\n t = masked_array (t, m)\n t = self.f.reduce(filled(t, self.filly), axis)\n m = umath.logical_and.reduce(m, axis)\n if isinstance(t, ndarray):\n return masked_array(t, m, get_fill_value(target))\n elif m:\n return masked\n else:\n return t\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = self.f.outer(filled(a, self.fillx), filled(b, self.filly))\n return masked_array(d, m)\n\n def accumulate (self, target, axis=0):\n \"\"\"Accumulate target along axis after filling with y fill value.\"\"\"\n t = filled(target, self.filly)\n return masked_array (self.f.accumulate (t, axis))\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nsqrt = masked_unary_operation(umath.sqrt, 0.0, domain_greater_equal(0.0))\nlog = masked_unary_operation(umath.log, 1.0, domain_greater(0.0))\nlog10 = masked_unary_operation(umath.log10, 1.0, domain_greater(0.0))\nexp = masked_unary_operation(umath.exp)\nconjugate = masked_unary_operation(umath.conjugate)\nsin = masked_unary_operation(umath.sin)\ncos = masked_unary_operation(umath.cos)\ntan = masked_unary_operation(umath.tan, 0.0, domain_tan(1.e-35))\narcsin = masked_unary_operation(umath.arcsin, 0.0, domain_check_interval(-1.0, 1.0))\narccos = masked_unary_operation(umath.arccos, 0.0, domain_check_interval(-1.0, 1.0))\narctan = masked_unary_operation(umath.arctan)\n# Missing from numeric\narcsinh = masked_unary_operation(umath.arcsinh)\narccosh = masked_unary_operation(umath.arccosh, 1.0, domain_greater_equal(1.0))\narctanh = masked_unary_operation(umath.arctanh, 0.0, domain_check_interval(-1.0+1e-15, 1.0-1e-15))\nsinh = masked_unary_operation(umath.sinh)\ncosh = masked_unary_operation(umath.cosh)\ntanh = masked_unary_operation(umath.tanh)\nabsolute = masked_unary_operation(umath.absolute)\nfabs = masked_unary_operation(umath.fabs)\nnegative = masked_unary_operation(umath.negative)\n\ndef nonzero(a):\n \"\"\"returns the indices of the elements of a which are not zero and not masked\n\n a must be 1d\n \"\"\"\n return asarray(filled(a, 0).nonzero())\n\naround = masked_unary_operation(oldnumeric.round_)\nfloor = masked_unary_operation(umath.floor)\nceil = masked_unary_operation(umath.ceil)\nlogical_not = masked_unary_operation(umath.logical_not)\n\nadd = masked_binary_operation(umath.add)\nsubtract = masked_binary_operation(umath.subtract)\nsubtract.reduce = None\nmultiply = masked_binary_operation(umath.multiply, 1, 1)\ndivide = domained_binary_operation(umath.divide, domain_safe_divide(), 0, 1)\ntrue_divide = domained_binary_operation(umath.true_divide, domain_safe_divide(), 0, 1)\nfloor_divide = domained_binary_operation(umath.floor_divide, domain_safe_divide(), 0, 1)\nremainder = domained_binary_operation(umath.remainder, domain_safe_divide(), 0, 1)\nfmod = domained_binary_operation(umath.fmod, domain_safe_divide(), 0, 1)\nhypot = masked_binary_operation(umath.hypot)\narctan2 = masked_binary_operation(umath.arctan2, 0.0, 1.0)\narctan2.reduce = None\nequal = masked_binary_operation(umath.equal)\nequal.reduce = None\nnot_equal = masked_binary_operation(umath.not_equal)\nnot_equal.reduce = None\nless_equal = masked_binary_operation(umath.less_equal)\nless_equal.reduce = None\ngreater_equal = masked_binary_operation(umath.greater_equal)\ngreater_equal.reduce = None\nless = masked_binary_operation(umath.less)\nless.reduce = None\ngreater = masked_binary_operation(umath.greater)\ngreater.reduce = None\nlogical_and = masked_binary_operation(umath.logical_and)\nalltrue = masked_binary_operation(umath.logical_and, 1, 1).reduce\nlogical_or = masked_binary_operation(umath.logical_or)\nsometrue = logical_or.reduce\nlogical_xor = masked_binary_operation(umath.logical_xor)\nbitwise_and = masked_binary_operation(umath.bitwise_and)\nbitwise_or = masked_binary_operation(umath.bitwise_or)\nbitwise_xor = masked_binary_operation(umath.bitwise_xor)\n\ndef rank (object):\n return oldnumeric.rank(filled(object))\n\ndef shape (object):\n return oldnumeric.shape(filled(object))\n\ndef size (object, axis=None):\n return oldnumeric.size(filled(object), axis)\n\nclass MaskedArray (object):\n \"\"\"Arrays with possibly masked values.\n Masked values of 1 exclude the corresponding element from\n any computation.\n\n Construction:\n x = array(data, dtype=None, copy=True, fortran=False,\n mask = nomask, fill_value=None)\n\n If copy=False, every effort is made not to copy the data:\n If data is a MaskedArray, and argument mask=nomask,\n then the candidate data is data.data and the\n mask used is data.mask. If data is a numeric array,\n it is used as the candidate raw data.\n If dtype.char is not None and\n is != data.dtype.char then a data copy is required.\n Otherwise, the candidate is used.\n\n If a data copy is required, raw data stored is the result of:\n numeric.array(data, dtype=dtype.char, copy=copy)\n\n If mask is nomask there are no masked values. Otherwise mask must\n be convertible to an array of booleans with the same shape as x.\n\n fill_value is used to fill in masked values when necessary,\n such as when printing and in method/function filled().\n The fill_value is not used for computation within this module.\n \"\"\"\n __array_priority__ = 10.1\n def __init__(self, data, dtype=None, copy=True, fortran=False,\n mask=nomask, fill_value=None):\n \"\"\"array(data, dtype=None, copy=True, fortran=False, mask=nomask, fill_value=None)\n If data already a numeric array, its dtype becomes the default value of dtype.\n \"\"\"\n if dtype is None:\n tc = None\n else:\n tc = numeric.dtype(dtype)\n need_data_copied = copy\n if isinstance(data, MaskedArray):\n c = data.data\n if tc is None:\n tc = c.dtype\n elif tc != c.dtype:\n need_data_copied = True\n if mask is nomask:\n mask = data.mask\n elif mask is not nomask: #attempting to change the mask\n need_data_copied = True\n\n elif isinstance(data, ndarray):\n c = data\n if tc is None:\n tc = c.dtype\n elif tc != c.dtype:\n need_data_copied = True\n else:\n need_data_copied = False #because I'll do it now\n c = numeric.array(data, dtype=tc, copy=True, fortran=fortran)\n tc = c.dtype\n\n if need_data_copied:\n if tc == c.dtype:\n self._data = numeric.array(c, dtype=tc, copy=True, fortran=fortran)\n else:\n self._data = c.astype(tc)\n else:\n self._data = c\n\n if mask is nomask:\n self._mask = nomask\n self._shared_mask = 0\n else:\n self._mask = make_mask (mask)\n if self._mask is nomask:\n self._shared_mask = 0\n else:\n self._shared_mask = (self._mask is mask)\n nm = size(self._mask)\n nd = size(self._data)\n if nm != nd:\n if nm == 1:\n self._mask = oldnumeric.resize(self._mask, self._data.shape)\n self._shared_mask = 0\n elif nd == 1:\n self._data = oldnumeric.resize(self._data, self._mask.shape)\n self._data.shape = self._mask.shape\n else:\n raise MAError, \"Mask and data not compatible.\"\n elif nm == 1 and shape(self._mask) != shape(self._data):\n self.unshare_mask()\n self._mask.shape = self._data.shape\n\n self.set_fill_value(fill_value)\n\n def __array__ (self, t=None, context=None):\n \"Special hook for numeric. Converts to numeric if possible.\"\n if self._mask is not nomask:\n if oldnumeric.ravel(self._mask).any():\n if context is None:\n warnings.warn(\"Cannot automatically convert masked array to \"\\\n \"numeric because data\\n is masked in one or \"\\\n \"more locations.\");\n return self._data\n #raise MAError, \\\n # \"\"\"Cannot automatically convert masked array to numeric because data\n # is masked in one or more locations.\n # \"\"\"\n else:\n func, args, i = context\n fills = ufunc_fills.get(func)\n if fills is None:\n raise MAError, \"%s not known to ma\" % func\n return self.filled(fills[i])\n else: # Mask is all false\n # Optimize to avoid future invocations of this section.\n self._mask = nomask\n self._shared_mask = 0\n if t:\n return self._data.astype(t)\n else:\n return self._data\n\n def __array_wrap__ (self, array, context):\n \"\"\"Special hook for ufuncs.\n\n Wraps the numpy array and sets the mask according to\n context.\n \"\"\"\n func, args = context[:2]\n domain = ufunc_domain[func]\n m = reduce(mask_or, [getmask(a) for a in args])\n if domain is not None:\n m = mask_or(m, domain(*[getattr(a, '_data', a)\n for a in args]))\n if m is not nomask:\n try:\n shape = array.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = reduce(mask_or, [getmaskarray(a) for a in args])\n\n return MaskedArray(array, copy=False, mask=m)\n\n def _get_shape(self):\n \"Return the current shape.\"\n return self._data.shape\n\n def _set_shape (self, newshape):\n \"Set the array's shape.\"\n self._data.shape = newshape\n if self._mask is not nomask:\n self._mask = self._mask.copy()\n self._mask.shape = newshape\n\n def _get_flat(self):\n \"\"\"Calculate the flat value.\n \"\"\"\n if self._mask is nomask:\n return masked_array(self._data.ravel(), mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.ravel(),\n mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_flat (self, value):\n \"x.flat = value\"\n y = self.ravel()\n y[:] = value\n\n def _get_real(self):\n \"Get the real part of a complex array.\"\n if self._mask is nomask:\n return masked_array(self._data.real, mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.real, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_real (self, value):\n \"x.real = value\"\n y = self.real\n y[...] = value\n\n def _get_imaginary(self):\n \"Get the imaginary part of a complex array.\"\n if self._mask is nomask:\n return masked_array(self._data.imag, mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.imag, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_imaginary (self, value):\n \"x.imaginary = value\"\n y = self.imaginary\n y[...] = value\n\n def __str__(self):\n \"\"\"Calculate the str representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n if masked_print_option.enabled():\n f = masked_print_option\n # XXX: Without the following special case masked\n # XXX: would print as \"[--]\", not \"--\". Can we avoid\n # XXX: checks for masked by choosing a different value\n # XXX: for the masked singleton? 2005-01-05 -- sasha\n if self is masked:\n return str(f)\n m = self._mask\n if m is not nomask and m.shape == () and m:\n return str(f)\n # convert to object array to make filled work\n self = self.astype(object)\n else:\n f = self.fill_value()\n res = self.filled(f)\n return str(res)\n\n def __repr__(self):\n \"\"\"Calculate the repr representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n with_mask = \"\"\"\\\narray(data =\n %(data)s,\n mask =\n %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n with_mask1 = \"\"\"\\\narray(data = %(data)s,\n mask = %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n without_mask = \"\"\"array(\n %(data)s)\"\"\"\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n\n n = len(self.shape)\n if self._mask is nomask:\n if n <= 1:\n return without_mask1 % {'data':str(self.filled())}\n return without_mask % {'data':str(self.filled())}\n else:\n if n <= 1:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n if self._mask is nomask:\n return without_mask % {'data':str(self.filled())}\n else:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n\n def __float__(self):\n \"Convert self to float.\"\n self.unmask()\n if self._mask is not nomask:\n raise MAError, 'Cannot convert masked element to a Python float.'\n return float(self.data.item())\n\n def __int__(self):\n \"Convert self to int.\"\n self.unmask()\n if self._mask is not nomask:\n raise MAError, 'Cannot convert masked element to a Python int.'\n return int(self.data.item())\n\n def __getitem__(self, i):\n \"Get item described by i. Not a copy as in previous versions.\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i]\n if m is nomask:\n return dout\n mi = m[i]\n if mi.size == 1:\n if mi:\n return masked\n else:\n return dout\n else:\n return masked_array(dout, mi, fill_value=self._fill_value)\n\n def __getslice__(self, i, j):\n \"Get slice described by i, j\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i:j]\n if m is nomask:\n return masked_array(dout, fill_value=self._fill_value)\n else:\n return masked_array(dout, mask = m[i:j], fill_value=self._fill_value)\n\n# --------\n# setitem and setslice notes\n# note that if value is masked, it means to mask those locations.\n# setting a value changes the mask to match the value in those locations.\n\n def __setitem__(self, index, value):\n \"Set item described by index. If value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, 'Cannot alter the masked element.'\n if value is masked:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n else:\n self.unshare_mask()\n self._mask[index] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[index] = value\n if m is nomask:\n if self._mask is not nomask:\n self.unshare_mask()\n self._mask[index] = False\n else:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = True\n else:\n self.unshare_mask()\n self._mask[index] = m\n\n def __setslice__(self, i, j, value):\n \"Set slice i:j; if value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, \"Cannot alter the 'masked' object.\"\n if value is masked:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n self._mask[i:j] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[i:j] = value\n if m is nomask:\n if self._mask is not nomask:\n self.unshare_mask()\n self._mask[i:j] = False\n else:\n if self._mask is nomask:\n self._mask = make_mask_none(self._data.shape)\n self._shared_mask = False\n self._mask[i:j] = m\n\n def __nonzero__(self):\n \"\"\"returns true if any element is non-zero or masked\n\n \"\"\"\n # XXX: This changes bool conversion logic from MA.\n # XXX: In MA bool(a) == len(a) != 0, but in numpy\n # XXX: scalars do not have len\n m = self._mask\n d = self._data\n return bool(m is not nomask and m.any()\n or d is not nomask and d.any())\n\n def __len__ (self):\n \"\"\"Return length of first dimension. This is weird but Python's\n slicing behavior depends on it.\"\"\"\n return len(self._data)\n\n def __and__(self, other):\n \"Return bitwise_and\"\n return bitwise_and(self, other)\n\n def __or__(self, other):\n \"Return bitwise_or\"\n return bitwise_or(self, other)\n\n def __xor__(self, other):\n \"Return bitwise_xor\"\n return bitwise_xor(self, other)\n\n __rand__ = __and__\n __ror__ = __or__\n __rxor__ = __xor__\n\n def __abs__(self):\n \"Return absolute(self)\"\n return absolute(self)\n\n def __neg__(self):\n \"Return negative(self)\"\n return negative(self)\n\n def __pos__(self):\n \"Return array(self)\"\n return array(self)\n\n def __add__(self, other):\n \"Return add(self, other)\"\n return add(self, other)\n\n __radd__ = __add__\n\n def __mod__ (self, other):\n \"Return remainder(self, other)\"\n return remainder(self, other)\n\n def __rmod__ (self, other):\n \"Return remainder(other, self)\"\n return remainder(other, self)\n\n def __lshift__ (self, n):\n return left_shift(self, n)\n\n def __rshift__ (self, n):\n return right_shift(self, n)\n\n def __sub__(self, other):\n \"Return subtract(self, other)\"\n return subtract(self, other)\n\n def __rsub__(self, other):\n \"Return subtract(other, self)\"\n return subtract(other, self)\n\n def __mul__(self, other):\n \"Return multiply(self, other)\"\n return multiply(self, other)\n\n __rmul__ = __mul__\n\n def __div__(self, other):\n \"Return divide(self, other)\"\n return divide(self, other)\n\n def __rdiv__(self, other):\n \"Return divide(other, self)\"\n return divide(other, self)\n\n def __truediv__(self, other):\n \"Return divide(self, other)\"\n return true_divide(self, other)\n\n def __rtruediv__(self, other):\n \"Return divide(other, self)\"\n return true_divide(other, self)\n\n def __floordiv__(self, other):\n \"Return divide(self, other)\"\n return floor_divide(self, other)\n\n def __rfloordiv__(self, other):\n \"Return divide(other, self)\"\n return floor_divide(other, self)\n\n def __pow__(self, other, third=None):\n \"Return power(self, other, third)\"\n return power(self, other, third)\n\n def __sqrt__(self):\n \"Return sqrt(self)\"\n return sqrt(self)\n\n def __iadd__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtype.char\n f = filled(other, 0)\n t1 = f.dtype.char\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data += f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = add(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __imul__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtype.char\n f = filled(other, 0)\n t1 = f.dtype.char\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data *= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = multiply(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __isub__(self, other):\n \"Subtract other from self in place.\"\n t = self._data.dtype.char\n f = filled(other, 0)\n t1 = f.dtype.char\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data -= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = subtract(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n\n\n def __idiv__(self, other):\n \"Divide self by other in place.\"\n t = self._data.dtype.char\n f = filled(other, 0)\n t1 = f.dtype.char\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n mo = getmask(other)\n result = divide(self, masked_array(f, mask=mo))\n self._data = result.data\n dm = result.raw_mask()\n if dm is not self._mask:\n self._mask = dm\n self._shared_mask = 1\n return self\n\n def __eq__(self, other):\n return equal(self,other)\n\n def __ne__(self, other):\n return not_equal(self,other)\n\n def __lt__(self, other):\n return less(self,other)\n\n def __le__(self, other):\n return less_equal(self,other)\n\n def __gt__(self, other):\n return greater(self,other)\n\n def __ge__(self, other):\n return greater_equal(self,other)\n\n def astype (self, tc):\n \"return self as array of given type.\"\n d = self._data.astype(tc)\n return array(d, mask=self._mask)\n\n def byte_swapped(self):\n \"\"\"Returns the raw data field, byte_swapped. Included for consistency\n with numeric but doesn't make sense in this context.\n \"\"\"\n return self._data.byte_swapped()\n\n def compressed (self):\n \"A 1-D array of all the non-masked data.\"\n d = oldnumeric.ravel(self._data)\n if self._mask is nomask:\n return array(d)\n else:\n m = 1 - oldnumeric.ravel(self._mask)\n c = oldnumeric.compress(m, d)\n return array(c, copy=0)\n\n def count (self, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n m = self._mask\n s = self._data.shape\n ls = len(s)\n if m is nomask:\n if ls == 0:\n return 1\n if ls == 1:\n return s[0]\n if axis is None:\n return reduce(lambda x, y:x*y, s)\n else:\n n = s[axis]\n t = list(s)\n del t[axis]\n return ones(t) * n\n if axis is None:\n w = oldnumeric.ravel(m).astype(int)\n n1 = size(w)\n if n1 == 1:\n n2 = w[0]\n else:\n n2 = umath.add.reduce(w)\n return n1 - n2\n else:\n n1 = size(m, axis)\n n2 = sum(m.astype(int), axis)\n return n1 - n2\n\n def dot (self, other):\n \"s.dot(other) = innerproduct(s, other)\"\n return innerproduct(self, other)\n\n def fill_value(self):\n \"Get the current fill value.\"\n return self._fill_value\n\n def filled (self, fill_value=None):\n \"\"\"A numeric array with masked values filled. If fill_value is None,\n use self.fill_value().\n\n If mask is nomask, copy data only if not contiguous.\n Result is always a contiguous, numeric array.\n# Is contiguous really necessary now?\n \"\"\"\n d = self._data\n m = self._mask\n if m is nomask:\n if d.flags['CONTIGUOUS']:\n return d\n else:\n return d.copy()\n else:\n if fill_value is None:\n value = self._fill_value\n else:\n value = fill_value\n\n if self is masked:\n result = numeric.array(value)\n else:\n try:\n result = numeric.array(d, dtype=d.dtype, copy=1)\n result[m] = value\n except (TypeError, AttributeError):\n #ok, can't put that value in here\n value = numeric.array(value, dtype=object)\n d = d.astype(object)\n result = oldnumeric.choose(m, (d, value))\n except IndexError:\n #ok, if scalar\n if d.shape:\n raise\n elif m:\n result = numeric.array(value, dtype=d.dtype)\n else:\n result = d\n return result\n\n def ids (self):\n \"\"\"Return the ids of the data and mask areas\"\"\"\n return (id(self._data), id(self._mask))\n\n def iscontiguous (self):\n \"Is the data contiguous?\"\n return self._data.flags['CONTIGUOUS']\n\n def itemsize(self):\n \"Item size of each data item.\"\n return self._data.itemsize\n\n\n def outer(self, other):\n \"s.outer(other) = outerproduct(s, other)\"\n return outerproduct(self, other)\n\n def put (self, values):\n \"\"\"Set the non-masked entries of self to filled(values).\n No change to mask\n \"\"\"\n iota = numeric.arange(self.size)\n d = self._data\n if self._mask is nomask:\n ind = iota\n else:\n ind = oldnumeric.compress(1 - self._mask, iota)\n d[ind] = filled(values).astype(d.dtype)\n\n def putmask (self, values):\n \"\"\"Set the masked entries of self to filled(values).\n Mask changed to nomask.\n \"\"\"\n d = self._data\n if self._mask is not nomask:\n d[self._mask] = filled(values).astype(d.dtype)\n self._shared_mask = 0\n self._mask = nomask\n\n def ravel (self):\n \"\"\"Return a 1-D view of self.\"\"\"\n if self._mask is nomask:\n return masked_array(self._data.ravel())\n else:\n return masked_array(self._data.ravel(), self._mask.ravel())\n\n def raw_data (self):\n \"\"\" Obsolete; use data property instead.\n The raw data; portions may be meaningless.\n May be noncontiguous. Expert use only.\"\"\"\n return self._data\n data = property(fget=raw_data,\n doc=\"The data, but values at masked locations are meaningless.\")\n\n def raw_mask (self):\n \"\"\" Obsolete; use mask property instead.\n May be noncontiguous. Expert use only.\n \"\"\"\n return self._mask\n mask = property(fget=raw_mask,\n doc=\"The mask, may be nomask. Values where mask true are meaningless.\")\n\n def reshape (self, *s):\n \"\"\"This array reshaped to shape s\"\"\"\n d = self._data.reshape(*s)\n if self._mask is nomask:\n return masked_array(d)\n else:\n m = self._mask.reshape(*s)\n return masked_array(d, m)\n\n def set_fill_value (self, v=None):\n \"Set the fill value to v. Omit v to restore default.\"\n if v is None:\n v = default_fill_value (self.raw_data())\n self._fill_value = v\n\n def _get_ndim(self):\n return self._data.ndim\n ndim = property(_get_ndim, doc=numeric.ndarray.ndim.__doc__)\n\n def _get_size (self):\n return self._data.size\n size = property(fget=_get_size, doc=\"Number of elements in the array.\")\n## CHECK THIS: signature of numeric.array.size?\n\n def _get_dtype(self):\n return self._data.dtype\n dtype = property(fget=_get_dtype, doc=\"type of the array elements.\")\n\n def item(self):\n \"Return Python scalar if possible.\"\n if self._mask is not nomask:\n m = oldnumeric.ravel(self._mask)\n try:\n if m[0]:\n return masked\n except IndexError:\n return masked\n return self._data.item()\n\n def tolist(self, fill_value=None):\n \"Convert to list\"\n return self.filled(fill_value).tolist()\n\n def tostring(self, fill_value=None):\n \"Convert to string\"\n return self.filled(fill_value).tostring()\n\n def unmask (self):\n \"Replace the mask by nomask if possible.\"\n if self._mask is nomask: return\n m = make_mask(self._mask, flag=1)\n if m is nomask:\n self._mask = nomask\n self._shared_mask = 0\n\n def unshare_mask (self):\n \"If currently sharing mask, make a copy.\"\n if self._shared_mask:\n self._mask = make_mask (self._mask, copy=1, flag=0)\n self._shared_mask = 0\n\n shape = property(_get_shape, _set_shape,\n doc = 'tuple giving the shape of the array')\n\n flat = property(_get_flat, _set_flat,\n doc = 'Access array in flat form.')\n\n real = property(_get_real, _set_real,\n doc = 'Access the real part of the array')\n\n imaginary = property(_get_imaginary, _set_imaginary,\n doc = 'Access the imaginary part of the array')\n\n imag = imaginary\n\n#end class MaskedArray\n\narray = MaskedArray\n\ndef isMaskedArray (x):\n \"Is x a masked array, that is, an instance of MaskedArray?\"\n return isinstance(x, MaskedArray)\n\nisarray = isMaskedArray\nisMA = isMaskedArray #backward compatibility\n\ndef allclose (a, b, fill_value=1, rtol=1.e-5, atol=1.e-8):\n \"\"\" Returns true if all components of a and b are equal\n subject to given tolerances.\n If fill_value is 1, masked values considered equal.\n If fill_value is 0, masked values considered unequal.\n The relative error rtol should be positive and << 1.0\n The absolute error atol comes into play for those elements\n of b that are very small or zero; it says how small a must be also.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a)\n d2 = filled(b)\n x = filled(array(d1, copy=0, mask=m), fill_value).astype(float)\n y = filled(array(d2, copy=0, mask=m), 1).astype(float)\n d = umath.less_equal(umath.absolute(x-y), atol + rtol * umath.absolute(y))\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n\ndef allequal (a, b, fill_value=1):\n \"\"\"\n True if all entries of a and b are equal, using\n fill_value as a truth value where either or both are masked.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n if m is nomask:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n elif fill_value:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n dm = array(d, mask=m, copy=0)\n return oldnumeric.alltrue(oldnumeric.ravel(filled(dm, 1)))\n else:\n return 0\n\ndef masked_values (data, value, rtol=1.e-5, atol=1.e-8, copy=1):\n \"\"\"\n masked_values(data, value, rtol=1.e-5, atol=1.e-8)\n Create a masked array; mask is nomask if possible.\n If copy==0, and otherwise possible, result\n may share data values with original array.\n Let d = filled(data, value). Returns d\n masked where abs(data-value)<= atol + rtol * abs(value)\n if d is of a floating point type. Otherwise returns\n masked_object(d, value, copy)\n \"\"\"\n abs = umath.absolute\n d = filled(data, value)\n if issubclass(d.dtype.type, numeric.floating):\n m = umath.less_equal(abs(d-value), atol+rtol*abs(value))\n m = make_mask(m, flag=1)\n return array(d, mask = m, copy=copy,\n fill_value=value)\n else:\n return masked_object(d, value, copy=copy)\n\ndef masked_object (data, value, copy=1):\n \"Create array masked where exactly data equal to value\"\n d = filled(data, value)\n dm = make_mask(umath.equal(d, value), flag=1)\n return array(d, mask=dm, copy=copy, fill_value=value)\n\ndef arrayrange(start, stop=None, step=1, dtype=None):\n \"\"\"Just like range() except it returns a array whose type can be specified\n by the keyword argument dtype.\n \"\"\"\n return array(numeric.arrayrange(start, stop, step, dtype))\n\narange = arrayrange\n\ndef fromstring (s, t):\n \"Construct a masked array from a string. Result will have no mask.\"\n return masked_array(numeric.fromstring(s, t))\n\ndef left_shift (a, n):\n \"Left shift n bits\"\n m = getmask(a)\n if m is nomask:\n d = umath.left_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.left_shift(filled(a, 0), n)\n return masked_array(d, m)\n\ndef right_shift (a, n):\n \"Right shift n bits\"\n m = getmask(a)\n if m is nomask:\n d = umath.right_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.right_shift(filled(a, 0), n)\n return masked_array(d, m)\n\ndef resize (a, new_shape):\n \"\"\"resize(a, new_shape) returns a new array with the specified shape.\n The original array's total size can be any size.\"\"\"\n m = getmask(a)\n if m is not nomask:\n m = oldnumeric.resize(m, new_shape)\n result = array(oldnumeric.resize(filled(a), new_shape), mask=m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n \"\"\"\n af = filled(a)\n if isinstance(repeats, types.IntType):\n repeats = tuple([repeats]*(shape(af)[axis]))\n\n m = getmask(a)\n if m is not nomask:\n m = oldnumeric.repeat(m, repeats, axis)\n d = oldnumeric.repeat(af, repeats, axis)\n result = masked_array(d, m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef identity(n):\n \"\"\"identity(n) returns the identity matrix of shape n x n.\n \"\"\"\n return array(numeric.identity(n))\n\ndef indices (dimensions, dtype=None):\n \"\"\"indices(dimensions,dtype=None) returns an array representing a grid\n of indices with row-only, and column-only variation.\n \"\"\"\n return array(numeric.indices(dimensions, dtype))\n\ndef zeros (shape, dtype=int):\n \"\"\"zeros(n, dtype=int) =\n an array of all zeros of the given length or shape.\"\"\"\n return array(numeric.zeros(shape, dtype))\n\ndef ones (shape, dtype=int):\n \"\"\"ones(n, dtype=int) =\n an array of all ones of the given length or shape.\"\"\"\n return array(numeric.ones(shape, dtype))\n\n\ndef count (a, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n a = masked_array(a)\n return a.count(axis)\n\ndef power (a, b, third=None):\n \"a**b\"\n if third is not None:\n raise MAError, \"3-argument power not supported.\"\n ma = getmask(a)\n mb = getmask(b)\n m = mask_or(ma, mb)\n fa = filled(a, 1)\n fb = filled(b, 1)\n if fb.dtype.char in typecodes[\"Integer\"]:\n return masked_array(umath.power(fa, fb), m)\n md = make_mask(umath.less_equal (fa, 0), flag=1)\n m = mask_or(m, md)\n if m is nomask:\n return masked_array(umath.power(fa, fb))\n else:\n fa = numeric.where(m, 1, fa)\n return masked_array(umath.power(fa, fb), m)\n\ndef masked_array (a, mask=nomask, fill_value=None):\n \"\"\"masked_array(a, mask=nomask) =\n array(a, mask=mask, copy=0, fill_value=fill_value)\n \"\"\"\n return array(a, mask=mask, copy=0, fill_value=fill_value)\n\nsum = add.reduce\nproduct = multiply.reduce\n\ndef average (a, axis=0, weights=None, returned = 0):\n \"\"\"average(a, axis=0, weights=None)\n Computes average along indicated axis.\n If axis is None, average over the entire array\n Inputs can be integer or floating types; result is of type float.\n\n If weights are given, result is sum(a*weights)/(sum(weights)*1.0)\n weights must have a's shape or be the 1-d with length the size\n of a in the given axis.\n\n If returned, return a tuple: the result and the sum of the weights\n or count of values. Results will have the same shape.\n\n masked values in the weights will be set to 0.0\n \"\"\"\n a = masked_array(a)\n mask = a.mask\n ash = a.shape\n if ash == ():\n ash = (1,)\n if axis is None:\n if mask is nomask:\n if weights is None:\n n = add.reduce(a.raw_data().ravel())\n d = reduce(lambda x, y: x * y, ash, 1.0)\n else:\n w = filled(weights, 0.0).ravel()\n n = umath.add.reduce(a.raw_data().ravel() * w)\n d = umath.add.reduce(w)\n del w\n else:\n if weights is None:\n n = add.reduce(a.ravel())\n w = oldnumeric.choose(mask, (1.0, 0.0)).ravel()\n d = umath.add.reduce(w)\n del w\n else:\n w = array(filled(weights, 0.0), float, mask=mask).ravel()\n n = add.reduce(a.ravel() * w)\n d = add.reduce(w)\n del w\n else:\n if mask is nomask:\n if weights is None:\n d = ash[axis] * 1.0\n n = umath.add.reduce(a.raw_data(), axis)\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = numeric.array(w, float, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None, None, 1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * ones(ash, float)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w, r\n else:\n raise ValueError, 'average: weights wrong shape.'\n else:\n if weights is None:\n n = add.reduce(a, axis)\n w = numeric.choose(mask, (1.0, 0.0))\n d = umath.add.reduce(w, axis)\n del w\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = array(w, float, mask=mask, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None, None, 1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * masked_array(ones(ash, float), mask)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n else:\n raise ValueError, 'average: weights wrong shape.'\n del w\n #print n, d, repr(mask), repr(weights)\n if n is masked or d is masked: return masked\n result = divide (n, d)\n del n\n\n if isinstance(result, MaskedArray):\n result.unmask()\n if returned:\n if not isinstance(d, MaskedArray):\n d = masked_array(d)\n if not d.shape == result.shape:\n d = ones(result.shape, float) * d\n d.unmask()\n if returned:\n return result, d\n else:\n return result\n\ndef where (condition, x, y):\n \"\"\"where(condition, x, y) is x where condition is nonzero, y otherwise.\n condition must be convertible to an integer array.\n Answer is always the shape of condition.\n The type depends on x and y. It is integer if both x and y are\n the value masked.\n \"\"\"\n fc = filled(not_equal(condition, 0), 0)\n xv = filled(x)\n xm = getmask(x)\n yv = filled(y)\n ym = getmask(y)\n d = numeric.choose(fc, (yv, xv))\n md = numeric.choose(fc, (ym, xm))\n m = getmask(condition)\n m = make_mask(mask_or(m, md), copy=0, flag=1)\n return masked_array(d, m)\n\ndef choose (indices, t):\n \"Returns array shaped like indices with elements chosen from t\"\n def fmask (x):\n if x is masked: return 1\n return filled(x)\n def nmask (x):\n if x is masked: return 1\n m = getmask(x)\n if m is nomask: return 0\n return m\n c = filled(indices, 0)\n masks = [nmask(x) for x in t]\n a = [fmask(x) for x in t]\n d = numeric.choose(c, a)\n m = numeric.choose(c, masks)\n m = make_mask(mask_or(m, getmask(indices)), copy=0, flag=1)\n return masked_array(d, m)\n\ndef masked_where(condition, x, copy=1):\n \"\"\"Return x as an array masked where condition is true.\n Also masked where x or condition masked.\n \"\"\"\n cm = filled(condition,1)\n m = mask_or(getmask(x), cm)\n return array(filled(x), copy=copy, mask=m)\n\ndef masked_greater(x, value, copy=1):\n \"masked_greater(x, value) = x masked where x > value\"\n return masked_where(greater(x, value), x, copy)\n\ndef masked_greater_equal(x, value, copy=1):\n \"masked_greater_equal(x, value) = x masked where x >= value\"\n return masked_where(greater_equal(x, value), x, copy)\n\ndef masked_less(x, value, copy=1):\n \"masked_less(x, value) = x masked where x < value\"\n return masked_where(less(x, value), x, copy)\n\ndef masked_less_equal(x, value, copy=1):\n \"masked_less_equal(x, value) = x masked where x <= value\"\n return masked_where(less_equal(x, value), x, copy)\n\ndef masked_not_equal(x, value, copy=1):\n \"masked_not_equal(x, value) = x masked where x != value\"\n d = filled(x, 0)\n c = umath.not_equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_equal(x, value, copy=1):\n \"\"\"masked_equal(x, value) = x masked where x == value\n For floating point consider masked_values(x, value) instead.\n \"\"\"\n d = filled(x, 0)\n c = umath.equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_inside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are inside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d = filled(x, 0)\n c = umath.logical_and(umath.less_equal(d, v2), umath.greater_equal(d, v1))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef masked_outside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are outside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d = filled(x, 0)\n c = umath.logical_or(umath.less(d, v1), umath.greater(d, v2))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef reshape (a, *newshape):\n \"Copy of a with a new shape.\"\n m = getmask(a)\n d = filled(a).reshape(*newshape)\n if m is nomask:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.reshape(m, *newshape))\n\ndef ravel (a):\n \"a as one-dimensional, may share data and mask\"\n m = getmask(a)\n d = oldnumeric.ravel(filled(a))\n if m is nomask:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.ravel(m))\n\ndef concatenate (arrays, axis=0):\n \"Concatenate the arrays along the given axis\"\n d = []\n for x in arrays:\n d.append(filled(x))\n d = numeric.concatenate(d, axis)\n for x in arrays:\n if getmask(x) is not nomask: break\n else:\n return masked_array(d)\n dm = []\n for x in arrays:\n dm.append(getmaskarray(x))\n dm = numeric.concatenate(dm, axis)\n return masked_array(d, mask=dm)\n\ndef take (a, indices, axis=0):\n \"take(a, indices, axis=0) returns selection of items from a.\"\n m = getmask(a)\n d = masked_array(a).raw_data()\n if m is nomask:\n return masked_array(numeric.take(d, indices, axis))\n else:\n return masked_array(numeric.take(d, indices, axis),\n mask = numeric.take(m, indices, axis))\n\ndef transpose(a, axes=None):\n \"transpose(a, axes=None) reorder dimensions per tuple axes\"\n m = getmask(a)\n d = filled(a)\n if m is nomask:\n return masked_array(numeric.transpose(d, axes))\n else:\n return masked_array(numeric.transpose(d, axes),\n mask = numeric.transpose(m, axes))\n\n\ndef put(a, indices, values):\n \"\"\"put(a, indices, values) sets storage-indexed locations to corresponding values.\n\n Values and indices are filled if necessary.\n\n \"\"\"\n d = a.raw_data()\n ind = filled(indices)\n v = filled(values)\n numeric.put (d, ind, v)\n m = getmask(a)\n if m is not nomask:\n a.unshare_mask()\n numeric.put(a.raw_mask(), ind, 0)\n\ndef putmask(a, mask, values):\n \"putmask(a, mask, values) sets a where mask is true.\"\n if mask is nomask:\n return\n numeric.putmask(a.raw_data(), mask, values)\n m = getmask(a)\n if m is nomask: return\n a.unshare_mask()\n numeric.putmask(a.raw_mask(), mask, 0)\n\ndef innerproduct(a, b):\n \"\"\"innerproduct(a,b) returns the dot product of two arrays, which has\n shape a.shape[:-1] + b.shape[:-1] with elements computed by summing the\n product of the elements from the last dimensions of a and b.\n Masked elements are replace by zeros.\n \"\"\"\n fa = filled(a, 0)\n fb = filled(b, 0)\n if len(fa.shape) == 0: fa.shape = (1,)\n if len(fb.shape) == 0: fb.shape = (1,)\n return masked_array(numeric.innerproduct(fa, fb))\n\ndef outerproduct(a, b):\n \"\"\"outerproduct(a,b) = {a[i]*b[j]}, has shape (len(a),len(b))\"\"\"\n fa = filled(a, 0).ravel()\n fb = filled(b, 0).ravel()\n d = numeric.outerproduct(fa, fb)\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n return masked_array(d)\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = make_mask(1-numeric.outerproduct(1-ma, 1-mb), copy=0)\n return masked_array(d, m)\n\ndef dot(a, b):\n \"\"\"dot(a,b) returns matrix-multiplication between a and b. The product-sum\n is over the last dimension of a and the second-to-last dimension of b.\n Masked values are replaced by zeros. See also innerproduct.\n \"\"\"\n return innerproduct(filled(a, 0), numeric.swapaxes(filled(b, 0), -1, -2))\n\ndef compress(condition, x, dimension=-1):\n \"\"\"Select those parts of x for which condition is true.\n Masked values in condition are considered false.\n \"\"\"\n c = filled(condition, 0)\n m = getmask(x)\n if m is not nomask:\n m = numeric.compress(c, m, dimension)\n d = numeric.compress(c, filled(x), dimension)\n return masked_array(d, m)\n\nclass _minimum_operation:\n \"Object to calculate minima\"\n def __init__ (self):\n \"\"\"minimum(a, b) or minimum(a)\n In one argument case returns the scalar minimum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is nomask:\n d = amin(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amin(ac.raw_data())\n else:\n return where(less(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is nomask:\n t = filled(target)\n return masked_array (umath.minimum.reduce (t, axis))\n else:\n t = umath.minimum.reduce(filled(target, minimum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.minimum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nminimum = _minimum_operation ()\n\nclass _maximum_operation:\n \"Object to calculate maxima\"\n def __init__ (self):\n \"\"\"maximum(a, b) or maximum(a)\n In one argument case returns the scalar maximum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is nomask:\n d = amax(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amax(ac.raw_data())\n else:\n return where(greater(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is nomask:\n t = filled(target)\n return masked_array (umath.maximum.reduce (t, axis))\n else:\n t = umath.maximum.reduce(filled(target, maximum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.maximum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nmaximum = _maximum_operation ()\n\ndef sort (x, axis = -1, fill_value=None):\n \"\"\"If x does not have a mask, return a masked array formed from the\n result of numeric.sort(x, axis).\n Otherwise, fill x with fill_value. Sort it.\n Set a mask where the result is equal to fill_value.\n Note that this may have unintended consequences if the data contains the\n fill value at a non-masked site.\n\n If fill_value is not given the default fill value for x's type will be\n used.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n d = filled(x, fill_value)\n s = oldnumeric.sort(d, axis)\n if getmask(x) is nomask:\n return masked_array(s)\n return masked_values(s, fill_value, copy=0)\n\ndef diagonal(a, k = 0, axis1=0, axis2=1):\n \"\"\"diagonal(a,k=0,axis1=0, axis2=1) = the k'th diagonal of a\"\"\"\n d = oldnumeric.diagonal(filled(a), k, axis1, axis2)\n m = getmask(a)\n if m is nomask:\n return masked_array(d, m)\n else:\n return masked_array(d, oldnumeric.diagonal(m, k, axis1, axis2))\n\ndef argsort (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for sorting along given axis.\n if fill_value is None, use get_fill_value(x)\n Returns a numpy array.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argsort(d, axis)\n\ndef argmin (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return indices for minimum values along given axis.\n if fill_value is None, use get_fill_value(x).\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argmin(d, axis)\n\ndef argmax (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for maximum along given axis.\n if fill_value is None, use -get_fill_value(x) if it exists.\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n try:\n fill_value = - fill_value\n except:\n pass\n d = filled(x, fill_value)\n return oldnumeric.argmax(d, axis)\n\ndef fromfunction (f, s):\n \"\"\"apply f to s to create array as in umath.\"\"\"\n return masked_array(numeric.fromfunction(f, s))\n\ndef asarray(data, dtype=None):\n \"\"\"asarray(data, dtype) = array(data, dtype, copy=0)\n \"\"\"\n if isinstance(data, MaskedArray) and \\\n (dtype is None or dtype == data.dtype):\n return data\n return array(data, dtype=dtype, copy=0)\n\n# Add methods to support ndarray interface\n# XXX: I is better to to change the masked_*_operation adaptors\n# XXX: to wrap ndarray methods directly to create ma.array methods.\nfrom types import MethodType\ndef _m(f):\n return MethodType(f, None, array)\ndef not_implemented(*args, **kwds):\n raise NotImplementedError, \"not yet implemented for numpy.ma arrays\"\narray.all = _m(alltrue)\narray.any = _m(sometrue)\narray.argmax = _m(argmax)\narray.argmin = _m(argmin)\narray.argsort = _m(argsort)\narray.base = property(_m(not_implemented))\narray.byteswap = _m(not_implemented)\n\ndef _choose(self, *args):\n return choose(self, args)\narray.choose = _m(_choose)\ndel _choose\n\narray.clip = _m(not_implemented)\n\ndef _compress(self, cond, axis=None):\n return compress(cond, self, axis)\narray.compress = _m(_compress)\ndel _compress\n\narray.conj = array.conjugate = _m(conjugate)\narray.copy = _m(not_implemented)\narray.cumprod = _m(not_implemented)\narray.cumsum = _m(not_implemented)\narray.diagonal = _m(diagonal)\narray.dump = _m(not_implemented)\narray.dumps = _m(not_implemented)\narray.fill = _m(not_implemented)\narray.flags = property(_m(not_implemented))\narray.flatten = _m(ravel)\narray.getfield = _m(not_implemented)\ndef _max(a, axis=None):\n if axis is None:\n return maximum(a)\n else:\n return maximum.reduce(a, axis)\narray.max = _m(_max)\ndel _max\ndef _min(a, axis=None):\n if axis is None:\n return minimum(a)\n else:\n return minimum.reduce(a, axis)\narray.min = _m(_min)\ndel _min\narray.mean = _m(average)\narray.nbytes = property(_m(not_implemented))\narray.newbyteorder = _m(not_implemented)\narray.nonzero = _m(nonzero)\narray.prod = _m(product)\narray.ptp = _m(not_implemented)\narray.repeat = _m(repeat)\narray.resize = _m(resize)\narray.searchsorted = _m(not_implemented)\narray.setfield = _m(not_implemented)\narray.setflags = _m(not_implemented)\narray.sort = _m(not_implemented) # NB: ndarray.sort is inplace\narray.squeeze = _m(not_implemented)\narray.std = _m(not_implemented)\narray.strides = property(_m(not_implemented))\narray.sum = _m(sum)\narray.swapaxes = _m(not_implemented)\narray.take = _m(take)\narray.tofile = _m(not_implemented)\narray.trace = _m(not_implemented)\narray.transpose = _m(transpose)\narray.var = _m(not_implemented)\narray.view = _m(not_implemented)\narray.round = _m(around)\ndel _m, MethodType, not_implemented\n\n\nmasked = MaskedArray(0, int, mask=1)\n", + "methods": [ + { + "name": "__init__", + "long_name": "__init__( self , args = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 30, + "end_line": 32, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 33, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , display )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "display" + ], + "start_line": 40, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "display", + "long_name": "display( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 45, + "end_line": 47, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "set_display", + "long_name": "set_display( self , s )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "s" + ], + "start_line": 49, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enabled", + "long_name": "enabled( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 53, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enable", + "long_name": "enable( self , flag = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "flag" + ], + "start_line": 57, + "end_line": 59, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 61, + "end_line": 62, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "default_fill_value", + "long_name": "default_fill_value( obj )", + "filename": "ma.py", + "nloc": 25, + "complexity": 13, + "token_count": 146, + "parameters": [ + "obj" + ], + "start_line": 76, + "end_line": 100, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "minimum_fill_value", + "long_name": "minimum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 107, + "parameters": [ + "obj" + ], + "start_line": 102, + "end_line": 117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "maximum_fill_value", + "long_name": "maximum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 105, + "parameters": [ + "obj" + ], + "start_line": 119, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( a , fill_value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 2, + "token_count": 20, + "parameters": [ + "a", + "fill_value" + ], + "start_line": 136, + "end_line": 139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "getmask", + "long_name": "getmask( a )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "a" + ], + "start_line": 141, + "end_line": 148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "getmaskarray", + "long_name": "getmaskarray( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 150, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "is_mask", + "long_name": "is_mask( m )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 21, + "parameters": [ + "m" + ], + "start_line": 161, + "end_line": 167, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "make_mask", + "long_name": "make_mask( m , copy = 0 , flag = 0 )", + "filename": "ma.py", + "nloc": 17, + "complexity": 7, + "token_count": 109, + "parameters": [ + "m", + "copy", + "flag" + ], + "start_line": 169, + "end_line": 192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "make_mask_none", + "long_name": "make_mask_none( s )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 25, + "parameters": [ + "s" + ], + "start_line": 194, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "mask_or", + "long_name": "mask_or( m1 , m2 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 5, + "token_count": 52, + "parameters": [ + "m1", + "m2" + ], + "start_line": 200, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "filled", + "long_name": "filled( a , value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 5, + "token_count": 70, + "parameters": [ + "a", + "value" + ], + "start_line": 209, + "end_line": 227, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "get_fill_value", + "long_name": "get_fill_value( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 229, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "common_fill_value", + "long_name": "common_fill_value( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a", + "b" + ], + "start_line": 240, + "end_line": 245, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , y1 , y2 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "y1", + "y2" + ], + "start_line": 250, + "end_line": 253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 35, + "parameters": [ + "self", + "x" + ], + "start_line": 255, + "end_line": 259, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , eps )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "eps" + ], + "start_line": 263, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "x" + ], + "start_line": 267, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 273, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 277, + "end_line": 279, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 283, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 287, + "end_line": 289, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , aufunc , fill = 0 , domain = None )", + "filename": "ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 74, + "parameters": [ + "self", + "aufunc", + "fill", + "domain" + ], + "start_line": 292, + "end_line": 304, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 72, + "parameters": [ + "self", + "a", + "args", + "kwargs" + ], + "start_line": 306, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 316, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , tolerance = divide_tolerance )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "tolerance" + ], + "start_line": 321, + "end_line": 322, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 323, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , domain , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 1, + "token_count": 82, + "parameters": [ + "self", + "abfunc", + "domain", + "fillx", + "filly" + ], + "start_line": 330, + "end_line": 341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 13, + "complexity": 2, + "token_count": 107, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 343, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 358, + "end_line": 359, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 60, + "parameters": [ + "self", + "abfunc", + "fillx", + "filly" + ], + "start_line": 362, + "end_line": 371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 73, + "parameters": [ + "self", + "a", + "b", + "args", + "kwargs" + ], + "start_line": 373, + "end_line": 379, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 20, + "complexity": 6, + "token_count": 157, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 381, + "end_line": 401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 403, + "end_line": 414, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "accumulate", + "long_name": "accumulate( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 416, + "end_line": 419, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 420, + "end_line": 421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "nonzero", + "long_name": "nonzero( a )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a" + ], + "start_line": 445, + "end_line": 450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "rank", + "long_name": "rank( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 490, + "end_line": 491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 493, + "end_line": 494, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( object , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 21, + "parameters": [ + "object", + "axis" + ], + "start_line": 496, + "end_line": 497, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , data , dtype = None , copy = True , fortran = False , mask = nomask , fill_value = None )", + "filename": "ma.py", + "nloc": 58, + "complexity": 19, + "token_count": 393, + "parameters": [ + "self", + "data", + "dtype", + "copy", + "fortran", + "mask", + "fill_value" + ], + "start_line": 528, + "end_line": 592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "top_nesting_level": 1 + }, + { + "name": "__array__", + "long_name": "__array__( self , t = None , context = None )", + "filename": "ma.py", + "nloc": 22, + "complexity": 6, + "token_count": 124, + "parameters": [ + "self", + "t", + "context" + ], + "start_line": 594, + "end_line": 620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "__array_wrap__", + "long_name": "__array_wrap__( self , array , context )", + "filename": "ma.py", + "nloc": 16, + "complexity": 8, + "token_count": 129, + "parameters": [ + "self", + "array", + "context" + ], + "start_line": 622, + "end_line": 643, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "_get_shape", + "long_name": "_get_shape( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 645, + "end_line": 647, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_set_shape", + "long_name": "_set_shape( self , newshape )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "newshape" + ], + "start_line": 649, + "end_line": 654, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_get_flat", + "long_name": "_get_flat( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 656, + "end_line": 665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "_set_flat", + "long_name": "_set_flat( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "value" + ], + "start_line": 667, + "end_line": 670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_real", + "long_name": "_get_real( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 672, + "end_line": 679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_real", + "long_name": "_set_real( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 681, + "end_line": 684, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_imaginary", + "long_name": "_get_imaginary( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 686, + "end_line": 693, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_imaginary", + "long_name": "_set_imaginary( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 695, + "end_line": 698, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 13, + "complexity": 6, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 700, + "end_line": 720, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "ma.py", + "nloc": 42, + "complexity": 5, + "token_count": 207, + "parameters": [ + "self" + ], + "start_line": 722, + "end_line": 767, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 1 + }, + { + "name": "__float__", + "long_name": "__float__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 769, + "end_line": 774, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__int__", + "long_name": "__int__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 776, + "end_line": 781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , i )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 70, + "parameters": [ + "self", + "i" + ], + "start_line": 783, + "end_line": 797, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 799, + "end_line": 807, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__setitem__", + "long_name": "__setitem__( self , index , value )", + "filename": "ma.py", + "nloc": 27, + "complexity": 7, + "token_count": 157, + "parameters": [ + "self", + "index", + "value" + ], + "start_line": 814, + "end_line": 840, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "__setslice__", + "long_name": "__setslice__( self , i , j , value )", + "filename": "ma.py", + "nloc": 23, + "complexity": 7, + "token_count": 155, + "parameters": [ + "self", + "i", + "j", + "value" + ], + "start_line": 842, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "__nonzero__", + "long_name": "__nonzero__( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 866, + "end_line": 876, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 878, + "end_line": 881, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__and__", + "long_name": "__and__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 883, + "end_line": 885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__or__", + "long_name": "__or__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 887, + "end_line": 889, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__xor__", + "long_name": "__xor__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 891, + "end_line": 893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__abs__", + "long_name": "__abs__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 899, + "end_line": 901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__neg__", + "long_name": "__neg__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 903, + "end_line": 905, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pos__", + "long_name": "__pos__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 907, + "end_line": 909, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__add__", + "long_name": "__add__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 911, + "end_line": 913, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mod__", + "long_name": "__mod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 917, + "end_line": 919, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rmod__", + "long_name": "__rmod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 921, + "end_line": 923, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__lshift__", + "long_name": "__lshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 925, + "end_line": 926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__rshift__", + "long_name": "__rshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 928, + "end_line": 929, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__sub__", + "long_name": "__sub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 931, + "end_line": 933, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rsub__", + "long_name": "__rsub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 935, + "end_line": 937, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mul__", + "long_name": "__mul__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 939, + "end_line": 941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__div__", + "long_name": "__div__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 945, + "end_line": 947, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rdiv__", + "long_name": "__rdiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 949, + "end_line": 951, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__truediv__", + "long_name": "__truediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 953, + "end_line": 955, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rtruediv__", + "long_name": "__rtruediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 957, + "end_line": 959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__floordiv__", + "long_name": "__floordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 961, + "end_line": 963, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rfloordiv__", + "long_name": "__rfloordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 965, + "end_line": 967, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pow__", + "long_name": "__pow__( self , other , third = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "other", + "third" + ], + "start_line": 969, + "end_line": 971, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__sqrt__", + "long_name": "__sqrt__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 973, + "end_line": 975, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__iadd__", + "long_name": "__iadd__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 254, + "parameters": [ + "self", + "other" + ], + "start_line": 977, + "end_line": 1018, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__imul__", + "long_name": "__imul__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 255, + "parameters": [ + "self", + "other" + ], + "start_line": 1020, + "end_line": 1061, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__isub__", + "long_name": "__isub__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 254, + "parameters": [ + "self", + "other" + ], + "start_line": 1063, + "end_line": 1104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__idiv__", + "long_name": "__idiv__( self , other )", + "filename": "ma.py", + "nloc": 38, + "complexity": 12, + "token_count": 237, + "parameters": [ + "self", + "other" + ], + "start_line": 1108, + "end_line": 1145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 1 + }, + { + "name": "__eq__", + "long_name": "__eq__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1147, + "end_line": 1148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ne__", + "long_name": "__ne__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1150, + "end_line": 1151, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__lt__", + "long_name": "__lt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1153, + "end_line": 1154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__le__", + "long_name": "__le__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1156, + "end_line": 1157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__gt__", + "long_name": "__gt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1159, + "end_line": 1160, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ge__", + "long_name": "__ge__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1162, + "end_line": 1163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "astype", + "long_name": "astype( self , tc )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "tc" + ], + "start_line": 1165, + "end_line": 1168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "byte_swapped", + "long_name": "byte_swapped( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 1170, + "end_line": 1174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "compressed", + "long_name": "compressed( self )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 1176, + "end_line": 1184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "count", + "long_name": "count( self , axis = None )", + "filename": "ma.py", + "nloc": 29, + "complexity": 7, + "token_count": 173, + "parameters": [ + "self", + "axis" + ], + "start_line": 1186, + "end_line": 1214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "dot", + "long_name": "dot( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1216, + "end_line": 1218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "fill_value", + "long_name": "fill_value( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1220, + "end_line": 1222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "filled", + "long_name": "filled( self , fill_value = None )", + "filename": "ma.py", + "nloc": 31, + "complexity": 9, + "token_count": 175, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1224, + "end_line": 1264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + }, + { + "name": "ids", + "long_name": "ids( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 1266, + "end_line": 1268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "iscontiguous", + "long_name": "iscontiguous( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 1270, + "end_line": 1272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "itemsize", + "long_name": "itemsize( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 1274, + "end_line": 1276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1279, + "end_line": 1281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "put", + "long_name": "put( self , values )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "values" + ], + "start_line": 1283, + "end_line": 1293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "putmask", + "long_name": "putmask( self , values )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "values" + ], + "start_line": 1295, + "end_line": 1303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "ravel", + "long_name": "ravel( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 1305, + "end_line": 1310, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "raw_data", + "long_name": "raw_data( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1312, + "end_line": 1316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "raw_mask", + "long_name": "raw_mask( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1320, + "end_line": 1324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "reshape", + "long_name": "reshape( self , * s )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self", + "s" + ], + "start_line": 1328, + "end_line": 1335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( self , v = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self", + "v" + ], + "start_line": 1337, + "end_line": 1341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_ndim", + "long_name": "_get_ndim( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1343, + "end_line": 1344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_size", + "long_name": "_get_size( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1347, + "end_line": 1348, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtype", + "long_name": "_get_dtype( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1352, + "end_line": 1353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "item", + "long_name": "item( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 4, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 1356, + "end_line": 1365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "tolist", + "long_name": "tolist( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1367, + "end_line": 1369, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "tostring", + "long_name": "tostring( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1371, + "end_line": 1373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "unmask", + "long_name": "unmask( self )", + "filename": "ma.py", + "nloc": 7, + "complexity": 3, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 1375, + "end_line": 1381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "unshare_mask", + "long_name": "unshare_mask( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 1383, + "end_line": 1387, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "isMaskedArray", + "long_name": "isMaskedArray( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "x" + ], + "start_line": 1407, + "end_line": 1409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "allclose", + "long_name": "allclose( a , b , fill_value = 1 , rtol = 1 . e - 5 , atol = 1 . e - 8 )", + "filename": "ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 140, + "parameters": [ + "a", + "b", + "fill_value", + "rtol", + "atol" + ], + "start_line": 1414, + "end_line": 1429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "allequal", + "long_name": "allequal( a , b , fill_value = 1 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 3, + "token_count": 125, + "parameters": [ + "a", + "b", + "fill_value" + ], + "start_line": 1431, + "end_line": 1449, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "masked_values", + "long_name": "masked_values( data , value , rtol = 1 . e - 5 , atol = 1 . e - 8 , copy = 1 )", + "filename": "ma.py", + "nloc": 10, + "complexity": 2, + "token_count": 117, + "parameters": [ + "data", + "value", + "rtol", + "atol", + "copy" + ], + "start_line": 1451, + "end_line": 1470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "masked_object", + "long_name": "masked_object( data , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "data", + "value", + "copy" + ], + "start_line": 1472, + "end_line": 1476, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayrange", + "long_name": "arrayrange( start , stop = None , step = 1 , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 34, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 1478, + "end_line": 1482, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "fromstring", + "long_name": "fromstring( s , t )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "s", + "t" + ], + "start_line": 1486, + "end_line": 1488, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "left_shift", + "long_name": "left_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1490, + "end_line": 1498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "right_shift", + "long_name": "right_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1500, + "end_line": 1508, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 1510, + "end_line": 1518, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 101, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 1520, + "end_line": 1535, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "identity", + "long_name": "identity( n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "n" + ], + "start_line": 1537, + "end_line": 1540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "indices", + "long_name": "indices( dimensions , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "dimensions", + "dtype" + ], + "start_line": 1542, + "end_line": 1546, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "zeros", + "long_name": "zeros( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1548, + "end_line": 1551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ones", + "long_name": "ones( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1553, + "end_line": 1556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "count", + "long_name": "count( a , axis = None )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a", + "axis" + ], + "start_line": 1559, + "end_line": 1562, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "power", + "long_name": "power( a , b , third = None )", + "filename": "ma.py", + "nloc": 18, + "complexity": 4, + "token_count": 154, + "parameters": [ + "a", + "b", + "third" + ], + "start_line": 1564, + "end_line": 1581, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "masked_array", + "long_name": "masked_array( a , mask = nomask , fill_value = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "mask", + "fill_value" + ], + "start_line": 1583, + "end_line": 1587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "average", + "long_name": "average( a , axis = 0 , weights = None , returned = 0 )", + "filename": "ma.py", + "nloc": 92, + "complexity": 22, + "token_count": 741, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 1592, + "end_line": 1699, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "where", + "long_name": "where( condition , x , y )", + "filename": "ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 107, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 1701, + "end_line": 1717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "choose.fmask", + "long_name": "choose.fmask( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 2, + "token_count": 17, + "parameters": [ + "x" + ], + "start_line": 1721, + "end_line": 1723, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "choose.nmask", + "long_name": "choose.nmask( x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 3, + "token_count": 27, + "parameters": [ + "x" + ], + "start_line": 1724, + "end_line": 1728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "choose", + "long_name": "choose( indices , t )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 93, + "parameters": [ + "indices", + "t" + ], + "start_line": 1719, + "end_line": 1735, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "masked_where", + "long_name": "masked_where( condition , x , copy = 1 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 47, + "parameters": [ + "condition", + "x", + "copy" + ], + "start_line": 1737, + "end_line": 1743, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "masked_greater", + "long_name": "masked_greater( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1745, + "end_line": 1747, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_greater_equal", + "long_name": "masked_greater_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1749, + "end_line": 1751, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less", + "long_name": "masked_less( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1753, + "end_line": 1755, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less_equal", + "long_name": "masked_less_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1757, + "end_line": 1759, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_not_equal", + "long_name": "masked_not_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1761, + "end_line": 1766, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "masked_equal", + "long_name": "masked_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1768, + "end_line": 1775, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "masked_inside", + "long_name": "masked_inside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1777, + "end_line": 1788, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "masked_outside", + "long_name": "masked_outside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1790, + "end_line": 1801, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , * newshape )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 56, + "parameters": [ + "a", + "newshape" + ], + "start_line": 1803, + "end_line": 1810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( a )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "a" + ], + "start_line": 1812, + "end_line": 1819, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "concatenate", + "long_name": "concatenate( arrays , axis = 0 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 5, + "token_count": 97, + "parameters": [ + "arrays", + "axis" + ], + "start_line": 1821, + "end_line": 1835, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 76, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 1837, + "end_line": 1845, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "a", + "axes" + ], + "start_line": 1847, + "end_line": 1855, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , indices , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 70, + "parameters": [ + "a", + "indices", + "values" + ], + "start_line": 1858, + "end_line": 1871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 61, + "parameters": [ + "a", + "mask", + "values" + ], + "start_line": 1873, + "end_line": 1881, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "innerproduct", + "long_name": "innerproduct( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 3, + "token_count": 72, + "parameters": [ + "a", + "b" + ], + "start_line": 1883, + "end_line": 1893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "outerproduct", + "long_name": "outerproduct( a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 110, + "parameters": [ + "a", + "b" + ], + "start_line": 1895, + "end_line": 1907, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dot", + "long_name": "dot( a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 36, + "parameters": [ + "a", + "b" + ], + "start_line": 1909, + "end_line": 1914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , x , dimension = - 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 67, + "parameters": [ + "condition", + "x", + "dimension" + ], + "start_line": 1916, + "end_line": 1925, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1929, + "end_line": 1933, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1935, + "end_line": 1948, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1950, + "end_line": 1959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1961, + "end_line": 1972, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1978, + "end_line": 1982, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1984, + "end_line": 1997, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1999, + "end_line": 2008, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 2010, + "end_line": 2021, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "sort", + "long_name": "sort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 8, + "complexity": 3, + "token_count": 68, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2025, + "end_line": 2042, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , k = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 73, + "parameters": [ + "a", + "k", + "axis1", + "axis2" + ], + "start_line": 2044, + "end_line": 2051, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2053, + "end_line": 2060, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2062, + "end_line": 2070, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 52, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2072, + "end_line": 2086, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "fromfunction", + "long_name": "fromfunction( f , s )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "f", + "s" + ], + "start_line": 2088, + "end_line": 2090, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( data , dtype = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 46, + "parameters": [ + "data", + "dtype" + ], + "start_line": 2092, + "end_line": 2098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_m", + "long_name": "_m( f )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "f" + ], + "start_line": 2104, + "end_line": 2105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "not_implemented", + "long_name": "not_implemented( * args , ** kwds )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "args", + "kwds" + ], + "start_line": 2106, + "end_line": 2107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_choose", + "long_name": "_choose( self , * args )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 2116, + "end_line": 2117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_compress", + "long_name": "_compress( self , cond , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "cond", + "axis" + ], + "start_line": 2123, + "end_line": 2124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_max", + "long_name": "_max( a , axis = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 30, + "parameters": [ + "a", + "axis" + ], + "start_line": 2139, + "end_line": 2143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_min", + "long_name": "_min( a , axis = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 30, + "parameters": [ + "a", + "axis" + ], + "start_line": 2146, + "end_line": 2150, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "__init__", + "long_name": "__init__( self , args = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 30, + "end_line": 32, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 33, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , display )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "display" + ], + "start_line": 40, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "display", + "long_name": "display( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 45, + "end_line": 47, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "set_display", + "long_name": "set_display( self , s )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "s" + ], + "start_line": 49, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enabled", + "long_name": "enabled( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 53, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enable", + "long_name": "enable( self , flag = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "flag" + ], + "start_line": 57, + "end_line": 59, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 61, + "end_line": 62, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "default_fill_value", + "long_name": "default_fill_value( obj )", + "filename": "ma.py", + "nloc": 25, + "complexity": 13, + "token_count": 146, + "parameters": [ + "obj" + ], + "start_line": 76, + "end_line": 100, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "minimum_fill_value", + "long_name": "minimum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 107, + "parameters": [ + "obj" + ], + "start_line": 102, + "end_line": 117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "maximum_fill_value", + "long_name": "maximum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 105, + "parameters": [ + "obj" + ], + "start_line": 119, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( a , fill_value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 2, + "token_count": 20, + "parameters": [ + "a", + "fill_value" + ], + "start_line": 136, + "end_line": 139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "getmask", + "long_name": "getmask( a )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "a" + ], + "start_line": 141, + "end_line": 148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "getmaskarray", + "long_name": "getmaskarray( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 150, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "is_mask", + "long_name": "is_mask( m )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 21, + "parameters": [ + "m" + ], + "start_line": 161, + "end_line": 167, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "make_mask", + "long_name": "make_mask( m , copy = 0 , flag = 0 )", + "filename": "ma.py", + "nloc": 17, + "complexity": 7, + "token_count": 109, + "parameters": [ + "m", + "copy", + "flag" + ], + "start_line": 169, + "end_line": 192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "make_mask_none", + "long_name": "make_mask_none( s )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 25, + "parameters": [ + "s" + ], + "start_line": 194, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "mask_or", + "long_name": "mask_or( m1 , m2 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 5, + "token_count": 52, + "parameters": [ + "m1", + "m2" + ], + "start_line": 200, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "filled", + "long_name": "filled( a , value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 5, + "token_count": 70, + "parameters": [ + "a", + "value" + ], + "start_line": 209, + "end_line": 227, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "get_fill_value", + "long_name": "get_fill_value( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 229, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "common_fill_value", + "long_name": "common_fill_value( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a", + "b" + ], + "start_line": 240, + "end_line": 245, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , y1 , y2 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "y1", + "y2" + ], + "start_line": 250, + "end_line": 253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 35, + "parameters": [ + "self", + "x" + ], + "start_line": 255, + "end_line": 259, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , eps )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "eps" + ], + "start_line": 263, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "x" + ], + "start_line": 267, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 273, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 277, + "end_line": 279, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 283, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 287, + "end_line": 289, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , aufunc , fill = 0 , domain = None )", + "filename": "ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 74, + "parameters": [ + "self", + "aufunc", + "fill", + "domain" + ], + "start_line": 292, + "end_line": 304, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 72, + "parameters": [ + "self", + "a", + "args", + "kwargs" + ], + "start_line": 306, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 316, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , tolerance = divide_tolerance )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "tolerance" + ], + "start_line": 321, + "end_line": 322, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 323, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , domain , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 1, + "token_count": 82, + "parameters": [ + "self", + "abfunc", + "domain", + "fillx", + "filly" + ], + "start_line": 330, + "end_line": 341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 13, + "complexity": 2, + "token_count": 107, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 343, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 358, + "end_line": 359, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 60, + "parameters": [ + "self", + "abfunc", + "fillx", + "filly" + ], + "start_line": 362, + "end_line": 371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 73, + "parameters": [ + "self", + "a", + "b", + "args", + "kwargs" + ], + "start_line": 373, + "end_line": 379, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 20, + "complexity": 6, + "token_count": 157, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 381, + "end_line": 401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 403, + "end_line": 414, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "accumulate", + "long_name": "accumulate( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 416, + "end_line": 419, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 420, + "end_line": 421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "nonzero", + "long_name": "nonzero( a )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a" + ], + "start_line": 445, + "end_line": 450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "rank", + "long_name": "rank( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 490, + "end_line": 491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 493, + "end_line": 494, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( object , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 21, + "parameters": [ + "object", + "axis" + ], + "start_line": 496, + "end_line": 497, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , data , dtype = None , copy = True , fortran = False , mask = nomask , fill_value = None )", + "filename": "ma.py", + "nloc": 58, + "complexity": 19, + "token_count": 393, + "parameters": [ + "self", + "data", + "dtype", + "copy", + "fortran", + "mask", + "fill_value" + ], + "start_line": 528, + "end_line": 592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "top_nesting_level": 1 + }, + { + "name": "__array__", + "long_name": "__array__( self , t = None , context = None )", + "filename": "ma.py", + "nloc": 22, + "complexity": 6, + "token_count": 124, + "parameters": [ + "self", + "t", + "context" + ], + "start_line": 594, + "end_line": 620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "__array_wrap__", + "long_name": "__array_wrap__( self , array , context )", + "filename": "ma.py", + "nloc": 16, + "complexity": 8, + "token_count": 129, + "parameters": [ + "self", + "array", + "context" + ], + "start_line": 622, + "end_line": 643, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "_get_shape", + "long_name": "_get_shape( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 645, + "end_line": 647, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_set_shape", + "long_name": "_set_shape( self , newshape )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "newshape" + ], + "start_line": 649, + "end_line": 654, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_get_flat", + "long_name": "_get_flat( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 656, + "end_line": 665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "_set_flat", + "long_name": "_set_flat( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "value" + ], + "start_line": 667, + "end_line": 670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_real", + "long_name": "_get_real( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 672, + "end_line": 679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_real", + "long_name": "_set_real( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 681, + "end_line": 684, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_imaginary", + "long_name": "_get_imaginary( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 686, + "end_line": 693, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_imaginary", + "long_name": "_set_imaginary( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 695, + "end_line": 698, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 13, + "complexity": 6, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 700, + "end_line": 720, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "ma.py", + "nloc": 42, + "complexity": 5, + "token_count": 207, + "parameters": [ + "self" + ], + "start_line": 722, + "end_line": 767, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 1 + }, + { + "name": "__float__", + "long_name": "__float__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 769, + "end_line": 774, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__int__", + "long_name": "__int__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 776, + "end_line": 781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , i )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 70, + "parameters": [ + "self", + "i" + ], + "start_line": 783, + "end_line": 797, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 799, + "end_line": 807, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__setitem__", + "long_name": "__setitem__( self , index , value )", + "filename": "ma.py", + "nloc": 27, + "complexity": 7, + "token_count": 157, + "parameters": [ + "self", + "index", + "value" + ], + "start_line": 814, + "end_line": 840, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "__setslice__", + "long_name": "__setslice__( self , i , j , value )", + "filename": "ma.py", + "nloc": 23, + "complexity": 7, + "token_count": 155, + "parameters": [ + "self", + "i", + "j", + "value" + ], + "start_line": 842, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "__nonzero__", + "long_name": "__nonzero__( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 866, + "end_line": 876, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 878, + "end_line": 881, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__and__", + "long_name": "__and__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 883, + "end_line": 885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__or__", + "long_name": "__or__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 887, + "end_line": 889, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__xor__", + "long_name": "__xor__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 891, + "end_line": 893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__abs__", + "long_name": "__abs__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 899, + "end_line": 901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__neg__", + "long_name": "__neg__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 903, + "end_line": 905, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pos__", + "long_name": "__pos__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 907, + "end_line": 909, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__add__", + "long_name": "__add__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 911, + "end_line": 913, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mod__", + "long_name": "__mod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 917, + "end_line": 919, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rmod__", + "long_name": "__rmod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 921, + "end_line": 923, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__lshift__", + "long_name": "__lshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 925, + "end_line": 926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__rshift__", + "long_name": "__rshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 928, + "end_line": 929, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__sub__", + "long_name": "__sub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 931, + "end_line": 933, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rsub__", + "long_name": "__rsub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 935, + "end_line": 937, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mul__", + "long_name": "__mul__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 939, + "end_line": 941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__div__", + "long_name": "__div__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 945, + "end_line": 947, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rdiv__", + "long_name": "__rdiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 949, + "end_line": 951, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__truediv__", + "long_name": "__truediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 953, + "end_line": 955, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rtruediv__", + "long_name": "__rtruediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 957, + "end_line": 959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__floordiv__", + "long_name": "__floordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 961, + "end_line": 963, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rfloordiv__", + "long_name": "__rfloordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 965, + "end_line": 967, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pow__", + "long_name": "__pow__( self , other , third = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "other", + "third" + ], + "start_line": 969, + "end_line": 971, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__sqrt__", + "long_name": "__sqrt__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 973, + "end_line": 975, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__iadd__", + "long_name": "__iadd__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 254, + "parameters": [ + "self", + "other" + ], + "start_line": 977, + "end_line": 1018, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__imul__", + "long_name": "__imul__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 255, + "parameters": [ + "self", + "other" + ], + "start_line": 1020, + "end_line": 1061, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__isub__", + "long_name": "__isub__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 254, + "parameters": [ + "self", + "other" + ], + "start_line": 1063, + "end_line": 1104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__idiv__", + "long_name": "__idiv__( self , other )", + "filename": "ma.py", + "nloc": 38, + "complexity": 12, + "token_count": 237, + "parameters": [ + "self", + "other" + ], + "start_line": 1108, + "end_line": 1145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 1 + }, + { + "name": "__eq__", + "long_name": "__eq__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1147, + "end_line": 1148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ne__", + "long_name": "__ne__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1150, + "end_line": 1151, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__lt__", + "long_name": "__lt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1153, + "end_line": 1154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__le__", + "long_name": "__le__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1156, + "end_line": 1157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__gt__", + "long_name": "__gt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1159, + "end_line": 1160, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ge__", + "long_name": "__ge__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1162, + "end_line": 1163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "astype", + "long_name": "astype( self , tc )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "tc" + ], + "start_line": 1165, + "end_line": 1168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "byte_swapped", + "long_name": "byte_swapped( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 1170, + "end_line": 1174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "compressed", + "long_name": "compressed( self )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 1176, + "end_line": 1184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "count", + "long_name": "count( self , axis = None )", + "filename": "ma.py", + "nloc": 29, + "complexity": 7, + "token_count": 173, + "parameters": [ + "self", + "axis" + ], + "start_line": 1186, + "end_line": 1214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "dot", + "long_name": "dot( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1216, + "end_line": 1218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "fill_value", + "long_name": "fill_value( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1220, + "end_line": 1222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "filled", + "long_name": "filled( self , fill_value = None )", + "filename": "ma.py", + "nloc": 31, + "complexity": 9, + "token_count": 175, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1224, + "end_line": 1264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + }, + { + "name": "ids", + "long_name": "ids( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 1266, + "end_line": 1268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "iscontiguous", + "long_name": "iscontiguous( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 1270, + "end_line": 1272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "itemsize", + "long_name": "itemsize( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 1274, + "end_line": 1276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1279, + "end_line": 1281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "put", + "long_name": "put( self , values )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "values" + ], + "start_line": 1283, + "end_line": 1293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "putmask", + "long_name": "putmask( self , values )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "values" + ], + "start_line": 1295, + "end_line": 1303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "ravel", + "long_name": "ravel( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 1305, + "end_line": 1310, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "raw_data", + "long_name": "raw_data( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1312, + "end_line": 1316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "raw_mask", + "long_name": "raw_mask( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1320, + "end_line": 1324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "reshape", + "long_name": "reshape( self , * s )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self", + "s" + ], + "start_line": 1328, + "end_line": 1335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( self , v = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self", + "v" + ], + "start_line": 1337, + "end_line": 1341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_ndim", + "long_name": "_get_ndim( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1343, + "end_line": 1344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_size", + "long_name": "_get_size( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1347, + "end_line": 1348, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtype", + "long_name": "_get_dtype( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1352, + "end_line": 1353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "item", + "long_name": "item( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 4, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 1356, + "end_line": 1365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "tolist", + "long_name": "tolist( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1367, + "end_line": 1369, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "tostring", + "long_name": "tostring( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1371, + "end_line": 1373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "unmask", + "long_name": "unmask( self )", + "filename": "ma.py", + "nloc": 7, + "complexity": 3, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 1375, + "end_line": 1381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "unshare_mask", + "long_name": "unshare_mask( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 1383, + "end_line": 1387, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "isMaskedArray", + "long_name": "isMaskedArray( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "x" + ], + "start_line": 1407, + "end_line": 1409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "allclose", + "long_name": "allclose( a , b , fill_value = 1 , rtol = 1 . e - 5 , atol = 1 . e - 8 )", + "filename": "ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 140, + "parameters": [ + "a", + "b", + "fill_value", + "rtol", + "atol" + ], + "start_line": 1414, + "end_line": 1429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "allequal", + "long_name": "allequal( a , b , fill_value = 1 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 3, + "token_count": 125, + "parameters": [ + "a", + "b", + "fill_value" + ], + "start_line": 1431, + "end_line": 1449, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "masked_values", + "long_name": "masked_values( data , value , rtol = 1 . e - 5 , atol = 1 . e - 8 , copy = 1 )", + "filename": "ma.py", + "nloc": 10, + "complexity": 2, + "token_count": 117, + "parameters": [ + "data", + "value", + "rtol", + "atol", + "copy" + ], + "start_line": 1451, + "end_line": 1470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "masked_object", + "long_name": "masked_object( data , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "data", + "value", + "copy" + ], + "start_line": 1472, + "end_line": 1476, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayrange", + "long_name": "arrayrange( start , stop = None , step = 1 , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 34, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 1478, + "end_line": 1482, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "fromstring", + "long_name": "fromstring( s , t )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "s", + "t" + ], + "start_line": 1486, + "end_line": 1488, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "left_shift", + "long_name": "left_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1490, + "end_line": 1498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "right_shift", + "long_name": "right_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1500, + "end_line": 1508, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 1510, + "end_line": 1518, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 101, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 1520, + "end_line": 1535, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "identity", + "long_name": "identity( n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "n" + ], + "start_line": 1537, + "end_line": 1540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "indices", + "long_name": "indices( dimensions , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "dimensions", + "dtype" + ], + "start_line": 1542, + "end_line": 1546, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "zeros", + "long_name": "zeros( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1548, + "end_line": 1551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ones", + "long_name": "ones( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1553, + "end_line": 1556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "count", + "long_name": "count( a , axis = None )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a", + "axis" + ], + "start_line": 1559, + "end_line": 1562, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "power", + "long_name": "power( a , b , third = None )", + "filename": "ma.py", + "nloc": 18, + "complexity": 4, + "token_count": 154, + "parameters": [ + "a", + "b", + "third" + ], + "start_line": 1564, + "end_line": 1581, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "masked_array", + "long_name": "masked_array( a , mask = nomask , fill_value = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "mask", + "fill_value" + ], + "start_line": 1583, + "end_line": 1587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "average", + "long_name": "average( a , axis = 0 , weights = None , returned = 0 )", + "filename": "ma.py", + "nloc": 92, + "complexity": 22, + "token_count": 741, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 1592, + "end_line": 1699, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "where", + "long_name": "where( condition , x , y )", + "filename": "ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 107, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 1701, + "end_line": 1717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "choose.fmask", + "long_name": "choose.fmask( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 2, + "token_count": 17, + "parameters": [ + "x" + ], + "start_line": 1721, + "end_line": 1723, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "choose.nmask", + "long_name": "choose.nmask( x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 3, + "token_count": 27, + "parameters": [ + "x" + ], + "start_line": 1724, + "end_line": 1728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "choose", + "long_name": "choose( indices , t )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 93, + "parameters": [ + "indices", + "t" + ], + "start_line": 1719, + "end_line": 1735, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "masked_where", + "long_name": "masked_where( condition , x , copy = 1 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 47, + "parameters": [ + "condition", + "x", + "copy" + ], + "start_line": 1737, + "end_line": 1743, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "masked_greater", + "long_name": "masked_greater( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1745, + "end_line": 1747, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_greater_equal", + "long_name": "masked_greater_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1749, + "end_line": 1751, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less", + "long_name": "masked_less( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1753, + "end_line": 1755, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less_equal", + "long_name": "masked_less_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1757, + "end_line": 1759, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_not_equal", + "long_name": "masked_not_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1761, + "end_line": 1766, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "masked_equal", + "long_name": "masked_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1768, + "end_line": 1775, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "masked_inside", + "long_name": "masked_inside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1777, + "end_line": 1788, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "masked_outside", + "long_name": "masked_outside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1790, + "end_line": 1801, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , * newshape )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 56, + "parameters": [ + "a", + "newshape" + ], + "start_line": 1803, + "end_line": 1810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( a )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "a" + ], + "start_line": 1812, + "end_line": 1819, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "concatenate", + "long_name": "concatenate( arrays , axis = 0 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 5, + "token_count": 97, + "parameters": [ + "arrays", + "axis" + ], + "start_line": 1821, + "end_line": 1835, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 76, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 1837, + "end_line": 1845, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "a", + "axes" + ], + "start_line": 1847, + "end_line": 1855, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , indices , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 70, + "parameters": [ + "a", + "indices", + "values" + ], + "start_line": 1858, + "end_line": 1871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 61, + "parameters": [ + "a", + "mask", + "values" + ], + "start_line": 1873, + "end_line": 1881, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "innerproduct", + "long_name": "innerproduct( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 3, + "token_count": 72, + "parameters": [ + "a", + "b" + ], + "start_line": 1883, + "end_line": 1893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "outerproduct", + "long_name": "outerproduct( a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 110, + "parameters": [ + "a", + "b" + ], + "start_line": 1895, + "end_line": 1907, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dot", + "long_name": "dot( a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 36, + "parameters": [ + "a", + "b" + ], + "start_line": 1909, + "end_line": 1914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , x , dimension = - 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 67, + "parameters": [ + "condition", + "x", + "dimension" + ], + "start_line": 1916, + "end_line": 1925, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1929, + "end_line": 1933, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1935, + "end_line": 1948, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1950, + "end_line": 1959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1961, + "end_line": 1972, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1978, + "end_line": 1982, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1984, + "end_line": 1997, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1999, + "end_line": 2008, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 2010, + "end_line": 2021, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "sort", + "long_name": "sort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 8, + "complexity": 3, + "token_count": 68, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2025, + "end_line": 2042, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , k = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 73, + "parameters": [ + "a", + "k", + "axis1", + "axis2" + ], + "start_line": 2044, + "end_line": 2051, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2053, + "end_line": 2060, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2062, + "end_line": 2070, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 52, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2072, + "end_line": 2086, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "fromfunction", + "long_name": "fromfunction( f , s )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "f", + "s" + ], + "start_line": 2088, + "end_line": 2090, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( data , dtype = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 46, + "parameters": [ + "data", + "dtype" + ], + "start_line": 2092, + "end_line": 2098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_m", + "long_name": "_m( f )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "f" + ], + "start_line": 2104, + "end_line": 2105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "not_implemented", + "long_name": "not_implemented( * args , ** kwds )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "args", + "kwds" + ], + "start_line": 2106, + "end_line": 2107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_choose", + "long_name": "_choose( self , * args )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 2116, + "end_line": 2117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_compress", + "long_name": "_compress( self , cond , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "cond", + "axis" + ], + "start_line": 2123, + "end_line": 2124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_max", + "long_name": "_max( a , axis = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 30, + "parameters": [ + "a", + "axis" + ], + "start_line": 2139, + "end_line": 2143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_min", + "long_name": "_min( a , axis = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 30, + "parameters": [ + "a", + "axis" + ], + "start_line": 2146, + "end_line": 2150, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 1690, + "complexity": 458, + "token_count": 11889, + "diff_parsed": { + "added": [ + "from numerictypes import bool_" + ], + "deleted": [ + "from numerictypes import *" + ] + } + }, + { + "old_path": "numpy/core/tests/test_ma.py", + "new_path": "numpy/core/tests/test_ma.py", + "filename": "test_ma.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -1,6 +1,7 @@\n import numpy\n import types, time\n from numpy.core.ma import *\n+from numpy.core.numerictypes import float32\n from numpy.testing import ScipyTestCase, ScipyTest\n pi = numpy.pi\n def eq(v,w, msg=''):\n", + "added_lines": 1, + "deleted_lines": 0, + "source_code": "import numpy\nimport types, time\nfrom numpy.core.ma import *\nfrom numpy.core.numerictypes import float32\nfrom numpy.testing import ScipyTestCase, ScipyTest\npi = numpy.pi\ndef eq(v,w, msg=''):\n result = allclose(v,w)\n if not result:\n print \"\"\"Not eq:%s\n%s\n----\n%s\"\"\"% (msg, str(v), str(w))\n return result\n\nclass test_ma(ScipyTestCase):\n def __init__(self, *args, **kwds):\n ScipyTestCase.__init__(self, *args, **kwds)\n self.setUp()\n\n def setUp (self):\n x=numpy.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])\n y=numpy.array([5.,0.,3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])\n a10 = 10.\n m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]\n m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0 ,0, 1]\n xm = array(x, mask=m1)\n ym = array(y, mask=m2)\n z = numpy.array([-.5, 0., .5, .8])\n zm = array(z, mask=[0,1,0,0])\n xf = numpy.where(m1, 1.e+20, x)\n s = x.shape\n xm.set_fill_value(1.e+20)\n self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf, s)\n\n def check_testBasic1d(self):\n \"Test of basic array creation and properties in 1 dimension.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual(xm.dtype, x.dtype)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual(count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n\n def check_testBasic2d(self):\n \"Test of basic array creation and properties in 2 dimensions.\"\n for s in [(4,3), (6,2)]:\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n x.shape = s\n y.shape = s\n xm.shape = s\n ym.shape = s\n xf.shape = s\n\n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual( count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n self.setUp()\n\n def check_testArithmetic (self):\n \"Test of basic arithmetic.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n a2d = array([[1,2],[0,4]])\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n self.failUnless(eq (a2d * a2d, a2d * a2dm))\n self.failUnless(eq (a2d + a2d, a2d + a2dm))\n self.failUnless(eq (a2d - a2d, a2d - a2dm))\n for s in [(12,), (4,3), (2,6)]:\n x = x.reshape(s)\n y = y.reshape(s)\n xm = xm.reshape(s)\n ym = ym.reshape(s)\n xf = xf.reshape(s)\n self.failUnless(eq(-x, -xm))\n self.failUnless(eq(x + y, xm + ym))\n self.failUnless(eq(x - y, xm - ym))\n self.failUnless(eq(x * y, xm * ym))\n self.failUnless(eq(x / y, xm / ym))\n self.failUnless(eq(a10 + y, a10 + ym))\n self.failUnless(eq(a10 - y, a10 - ym))\n self.failUnless(eq(a10 * y, a10 * ym))\n self.failUnless(eq(a10 / y, a10 / ym))\n self.failUnless(eq(x + a10, xm + a10))\n self.failUnless(eq(x - a10, xm - a10))\n self.failUnless(eq(x * a10, xm * a10))\n self.failUnless(eq(x / a10, xm / a10))\n self.failUnless(eq(x**2, xm**2))\n self.failUnless(eq(abs(x)**2.5, abs(xm) **2.5))\n self.failUnless(eq(x**y, xm**ym))\n self.failUnless(eq(numpy.add(x,y), add(xm, ym)))\n self.failUnless(eq(numpy.subtract(x,y), subtract(xm, ym)))\n self.failUnless(eq(numpy.multiply(x,y), multiply(xm, ym)))\n self.failUnless(eq(numpy.divide(x,y), divide(xm, ym)))\n\n\n def check_testMixedArithmetic(self):\n na = numpy.array([1])\n ma = array([1])\n self.failUnless(isinstance(na + ma, MaskedArray))\n self.failUnless(isinstance(ma + na, MaskedArray))\n\n def check_testUfuncs1 (self):\n \"Test various functions such as sin, cos.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.cos(x), cos(xm)))\n self.failUnless (eq(numpy.cosh(x), cosh(xm)))\n self.failUnless (eq(numpy.sin(x), sin(xm)))\n self.failUnless (eq(numpy.sinh(x), sinh(xm)))\n self.failUnless (eq(numpy.tan(x), tan(xm)))\n self.failUnless (eq(numpy.tanh(x), tanh(xm)))\n self.failUnless (eq(numpy.sqrt(abs(x)), sqrt(xm)))\n self.failUnless (eq(numpy.log(abs(x)), log(xm)))\n self.failUnless (eq(numpy.log10(abs(x)), log10(xm)))\n self.failUnless (eq(numpy.exp(x), exp(xm)))\n self.failUnless (eq(numpy.arcsin(z), arcsin(zm)))\n self.failUnless (eq(numpy.arccos(z), arccos(zm)))\n self.failUnless (eq(numpy.arctan(z), arctan(zm)))\n self.failUnless (eq(numpy.arctan2(x, y), arctan2(xm, ym)))\n self.failUnless (eq(numpy.absolute(x), absolute(xm)))\n self.failUnless (eq(numpy.equal(x,y), equal(xm, ym)))\n self.failUnless (eq(numpy.not_equal(x,y), not_equal(xm, ym)))\n self.failUnless (eq(numpy.less(x,y), less(xm, ym)))\n self.failUnless (eq(numpy.greater(x,y), greater(xm, ym)))\n self.failUnless (eq(numpy.less_equal(x,y), less_equal(xm, ym)))\n self.failUnless (eq(numpy.greater_equal(x,y), greater_equal(xm, ym)))\n self.failUnless (eq(numpy.conjugate(x), conjugate(xm)))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,ym))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((x,y))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,y))))\n self.failUnless (eq(numpy.concatenate((x,y,x)), concatenate((x,ym,x))))\n\n def check_xtestCount (self):\n \"Test count\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless( isinstance(count(ott), types.IntType))\n self.assertEqual(3, count(ott))\n self.assertEqual(1, count(1))\n self.failUnless (eq(0, array(1,mask=[1])))\n ott=ott.reshape((2,2))\n assert isMaskedArray(count(ott,0))\n assert isinstance(count(ott), types.IntType)\n self.failUnless (eq(3, count(ott)))\n assert getmask(count(ott,0)) is nomask\n self.failUnless (eq([1,2],count(ott,0)))\n\n def check_testMinMax (self):\n \"Test minimum and maximum.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n xr = numpy.ravel(x) #max doesn't work if shaped\n xmr = ravel(xm)\n self.failUnless (eq(max(xr), maximum(xmr))) #true because of careful selection of data\n self.failUnless (eq(min(xr), minimum(xmr))) #true because of careful selection of data\n\n def check_testAddSumProd (self):\n \"Test add, sum, product.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.add.reduce(x), add.reduce(x)))\n self.failUnless (eq(numpy.add.accumulate(x), add.accumulate(x)))\n self.failUnless (eq(4, sum(array(4))))\n self.failUnless (eq(4, sum(array(4), axis=0)))\n self.failUnless (eq(numpy.sum(x), sum(x)))\n self.failUnless (eq(numpy.sum(filled(xm,0)), sum(xm)))\n self.failUnless (eq(numpy.sum(x,0), sum(x,0)))\n self.failUnless (eq(numpy.product(x), product(x)))\n self.failUnless (eq(numpy.product(x,0), product(x,0)))\n self.failUnless (eq(numpy.product(filled(xm,1)), product(xm)))\n if len(s) > 1:\n self.failUnless (eq(numpy.concatenate((x,y),1), concatenate((xm,ym),1)))\n self.failUnless (eq(numpy.add.reduce(x,1), add.reduce(x,1)))\n self.failUnless (eq(numpy.sum(x,1), sum(x,1)))\n self.failUnless (eq(numpy.product(x,1), product(x,1)))\n\n\n def check_testCI(self):\n \"Test of conversions and indexing\"\n x1 = numpy.array([1,2,4,3])\n x2 = array(x1, mask = [1,0,0,0])\n x3 = array(x1, mask = [0,1,0,1])\n x4 = array(x1)\n # test conversion to strings\n junk, garbage = str(x2), repr(x2)\n assert eq(numpy.sort(x1),sort(x2, fill_value=0))\n # tests of indexing\n assert type(x2[1]) is type(x1[1])\n assert x1[1] == x2[1]\n assert x2[0] is masked\n assert eq(x1[2],x2[2])\n assert eq(x1[2:5],x2[2:5])\n assert eq(x1[:],x2[:])\n assert eq(x1[1:], x3[1:])\n x1[2]=9\n x2[2]=9\n assert eq(x1,x2)\n x1[1:3] = 99\n x2[1:3] = 99\n assert eq(x1,x2)\n x2[1] = masked\n assert eq(x1,x2)\n x2[1:3]=masked\n assert eq(x1,x2)\n x2[:] = x1\n x2[1] = masked\n assert allequal(getmask(x2),array([0,1,0,0]))\n x3[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x3), array([0,1,1,0]))\n x4[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x4), array([0,1,1,0]))\n assert allequal(x4, array([1,2,3,4]))\n x1 = numpy.arange(5)*1.0\n x2 = masked_values(x1, 3.0)\n assert eq(x1,x2)\n assert allequal(array([0,0,0,1,0],MaskType), x2.mask)\n assert eq(3.0, x2.fill_value())\n x1 = array([1,'hello',2,3],object)\n x2 = numpy.array([1,'hello',2,3],object)\n s1 = x1[1]\n s2 = x2[1]\n self.assertEqual(type(s2), str)\n self.assertEqual(type(s1), str)\n self.assertEqual(s1, s2)\n assert x1[1:1].shape == (0,)\n\n def check_testCopySize(self):\n \"Tests of some subtle points of copying and sizing.\"\n n = [0,0,1,0,0]\n m = make_mask(n)\n m2 = make_mask(m)\n self.failUnless(m is m2)\n m3 = make_mask(m, copy=1)\n self.failUnless(m is not m3)\n\n x1 = numpy.arange(5)\n y1 = array(x1, mask=m)\n self.failUnless( y1.raw_data() is not x1)\n self.failUnless( allequal(x1,y1.raw_data()))\n self.failUnless( y1.mask is m)\n\n y1a = array(y1, copy=0)\n self.failUnless( y1a.raw_data() is y1.raw_data())\n self.failUnless( y1a.mask is y1.mask)\n\n y2 = array(x1, mask=m, copy=0)\n self.failUnless( y2.raw_data() is x1)\n self.failUnless( y2.mask is m)\n self.failUnless( y2[2] is masked)\n y2[2]=9\n self.failUnless( y2[2] is not masked)\n self.failUnless( y2.mask is not m)\n self.failUnless( allequal(y2.mask, 0))\n\n y3 = array(x1*1.0, mask=m)\n self.failUnless(filled(y3).dtype is (x1*1.0).dtype)\n\n x4 = arange(4)\n x4[2] = masked\n y4 = resize(x4, (8,))\n self.failUnless( eq(concatenate([x4,x4]), y4))\n self.failUnless( eq(getmask(y4),[0,0,1,0,0,0,1,0]))\n y5 = repeat(x4, (2,2,2,2))\n self.failUnless( eq(y5, [0,0,1,1,2,2,3,3]))\n y6 = repeat(x4, 2)\n self.failUnless( eq(y5, y6))\n\n def check_testPut(self):\n \"Test of put\"\n d = arange(5)\n n = [0,0,0,1,1]\n m = make_mask(n)\n x = array(d, mask = m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n x[[1,4]] = [10,40]\n self.failUnless( x.mask is not m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is not masked)\n self.failUnless( eq(x, [0,10,2,-1,40]))\n\n x = array(d, mask = m)\n x.put([-1,100,200])\n self.failUnless( eq(x, [-1,100,200,0,0]))\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n\n x = array(d, mask = m)\n x.putmask([30,40])\n self.failUnless( eq(x, [0,1,2,30,40]))\n self.failUnless( x.mask is nomask)\n\n x = array(d, mask = m)\n y = x.compressed()\n z = array(x, mask = m)\n z.put(y)\n assert eq (x, z)\n\n def check_testMaPut(self):\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]\n i = numpy.nonzero(m)\n putmask(xm, m, z)\n assert take(xm, i) == z\n put(ym, i, zm)\n assert take(ym, i) == zm\n\n def check_testOddFeatures(self):\n \"Test of other odd features\"\n x = arange(20); x=x.reshape(4,5)\n x.flat[5] = 12\n assert x[1,0] == 12\n z = x + 10j * x\n assert eq(z.real, x)\n assert eq(z.imag, 10*x)\n assert eq((z*conjugate(z)).real, 101*x*x)\n z.imag[...] = 0.0\n\n x = arange(10)\n x[3] = masked\n assert str(x[3]) == str(masked)\n c = x >= 8\n assert count(where(c,masked,masked)) == 0\n assert shape(where(c,masked,masked)) == c.shape\n z = where(c , x, masked)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is masked\n assert z[7] is masked\n assert z[8] is not masked\n assert z[9] is not masked\n assert eq(x,z)\n z = where(c , masked, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n z = masked_where(c, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n assert eq(x,z)\n x = array([1.,2.,3.,4.,5.])\n c = array([1,1,1,0,0])\n x[2] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n c[0] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n assert eq(masked_where(greater(x, 2), x), masked_greater(x,2))\n assert eq(masked_where(greater_equal(x, 2), x), masked_greater_equal(x,2))\n assert eq(masked_where(less(x, 2), x), masked_less(x,2))\n assert eq(masked_where(less_equal(x, 2), x), masked_less_equal(x,2))\n assert eq(masked_where(not_equal(x, 2), x), masked_not_equal(x,2))\n assert eq(masked_where(equal(x, 2), x), masked_equal(x,2))\n assert eq(masked_where(not_equal(x,2), x), masked_not_equal(x,2))\n assert eq(masked_inside(range(5), 1, 3), [0, 199, 199, 199, 4])\n assert eq(masked_outside(range(5), 1, 3),[199,1,2,3,199])\n assert eq(masked_inside(array(range(5), mask=[1,0,0,0,0]), 1, 3).mask, [1,1,1,1,0])\n assert eq(masked_outside(array(range(5), mask=[0,1,0,0,0]), 1, 3).mask, [1,1,0,0,1])\n assert eq(masked_equal(array(range(5), mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,0])\n assert eq(masked_not_equal(array([2,2,1,2,1], mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,1])\n assert eq(masked_where([1,1,0,0,0], [1,2,3,4,5]), [99,99,3,4,5])\n atest = ones((10,10,10), dtype=float32)\n btest = zeros(atest.shape, MaskType)\n ctest = masked_where(btest,atest)\n assert eq(atest,ctest)\n z = choose(c, (-x, x))\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n x = arange(6)\n x[5] = masked\n y = arange(6)*10\n y[2]= masked\n c = array([1,1,1,0,0,0], mask=[1,0,0,0,0,0])\n cm = c.filled(1)\n z = where(c,x,y)\n zm = where(cm,x,y)\n assert eq(z, zm)\n assert getmask(zm) is nomask\n assert eq(zm, [0,1,2,30,40,50])\n z = where(c, masked, 1)\n assert eq(z, [99,99,99,1,1,1])\n z = where(c, 1, masked)\n assert eq(z, [99, 1, 1, 99, 99, 99])\n\n def check_testMinMax(self):\n \"Test of minumum, maximum.\"\n assert eq(minimum([1,2,3],[4,0,9]), [1,0,3])\n assert eq(maximum([1,2,3],[4,0,9]), [4,2,9])\n x = arange(5)\n y = arange(5) - 2\n x[3] = masked\n y[0] = masked\n assert eq(minimum(x,y), where(less(x,y), x, y))\n assert eq(maximum(x,y), where(greater(x,y), x, y))\n assert minimum(x) == 0\n assert maximum(x) == 4\n\n def check_testTakeTransposeInnerOuter(self):\n \"Test of take, transpose, inner, outer products\"\n x = arange(24)\n y = numpy.arange(24)\n x[5:6] = masked\n x=x.reshape(2,3,4)\n y=y.reshape(2,3,4)\n assert eq(numpy.transpose(y,(2,0,1)), transpose(x,(2,0,1)))\n assert eq(numpy.take(y, (2,0,1), 1), take(x, (2,0,1), 1))\n assert eq(numpy.innerproduct(filled(x,0),filled(y,0)),\n innerproduct(x, y))\n assert eq(numpy.outerproduct(filled(x,0),filled(y,0)),\n outerproduct(x, y))\n y = array(['abc', 1, 'def', 2, 3], object)\n y[2] = masked\n t = take(y,[0,3,4])\n assert t[0] == 'abc'\n assert t[1] == 2\n assert t[2] == 3\n\n def check_testInplace(self):\n \"\"\"Test of inplace operations and rich comparisons\"\"\"\n y = arange(10)\n\n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x += 1\n assert eq(x, y+1)\n xm += 1\n assert eq(x, y+1)\n\n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x -= 1\n assert eq(x, y-1)\n xm -= 1\n assert eq(xm, y-1)\n\n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x *= 2.0\n assert eq(x, y*2)\n xm *= 2.0\n assert eq(xm, y*2)\n\n x = arange(10)*2\n xm = arange(10)\n xm[2] = masked\n x /= 2\n assert eq(x, y)\n xm /= 2\n assert eq(x, y)\n\n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x /= 2.0\n assert eq(x, y/2.0)\n xm /= arange(10)\n assert eq(xm, ones((10,)))\n\n x = arange(10).astype(float32)\n xm = arange(10)\n xm[2] = masked\n id1 = id(x.raw_data())\n x += 1.\n assert id1 == id(x.raw_data())\n assert eq(x, y+1.)\n\n def check_testPickle(self):\n \"Test of pickling\"\n import pickle\n x = arange(12)\n x[4:10:2] = masked\n x = x.reshape(4,3)\n s = pickle.dumps(x)\n y = pickle.loads(s)\n assert eq(x,y)\n\n def check_testMasked(self):\n \"Test of masked element\"\n xx=arange(6)\n xx[1] = masked\n self.failUnless(str(masked) == '--')\n self.failUnless(xx[1] is masked)\n self.failUnlessEqual(filled(xx[1], 0), 0)\n # don't know why these should raise an exception...\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, masked)\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, 2)\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, xx)\n #self.failUnlessRaises(Exception, lambda x,y: x+y, xx, masked)\n\n def check_testAverage1(self):\n \"Test of average.\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless(eq(2.0, average(ott)))\n self.failUnless(eq(2.0, average(ott, weights=[1., 1., 2., 1.])))\n result, wts = average(ott, weights=[1.,1.,2.,1.], returned=1)\n self.failUnless(eq(2.0, result))\n self.failUnless(wts == 4.0)\n ott[:] = masked\n self.failUnless(average(ott) is masked)\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n ott=ott.reshape(2,2)\n ott[:,1] = masked\n self.failUnless(eq(average(ott), [2.0, 0.0]))\n self.failUnless(average(ott,axis=1)[0] is masked)\n self.failUnless(eq([2.,0.], average(ott)))\n result, wts = average(ott, returned=1)\n self.failUnless(eq(wts, [1., 0.]))\n\n def check_testAverage2(self):\n \"More tests of average.\"\n w1 = [0,1,1,1,1,0]\n w2 = [[0,1,1,1,1,0],[1,0,0,0,0,1]]\n x=arange(6)\n self.failUnless(allclose(average(x), 2.5))\n self.failUnless(allclose(average(x, weights=w1), 2.5))\n y=array([arange(6), 2.0*arange(6)])\n self.failUnless(allclose(average(y, None), numpy.add.reduce(numpy.arange(6))*3./12.))\n self.failUnless(allclose(average(y, axis=0), numpy.arange(6) * 3./2.))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n self.failUnless(allclose(average(y, None, weights=w2), 20./6.))\n self.failUnless(allclose(average(y, axis=0, weights=w2), [0.,1.,2.,3.,4.,10.]))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n m1 = zeros(6)\n m2 = [0,0,1,1,0,0]\n m3 = [[0,0,1,1,0,0],[0,1,1,1,1,0]]\n m4 = ones(6)\n m5 = [0, 1, 1, 1, 1, 1]\n self.failUnless(allclose(average(masked_array(x, m1)), 2.5))\n self.failUnless(allclose(average(masked_array(x, m2)), 2.5))\n self.failUnless(average(masked_array(x, m4)) is masked)\n self.assertEqual(average(masked_array(x, m5)), 0.0)\n self.assertEqual(count(average(masked_array(x, m4))), 0)\n z = masked_array(y, m3)\n self.failUnless(allclose(average(z, None), 20./6.))\n self.failUnless(allclose(average(z, axis=0), [0.,1.,99.,99.,4.0, 7.5]))\n self.failUnless(allclose(average(z, axis=1), [2.5, 5.0]))\n self.failUnless(allclose( average(z,weights=w2), [0.,1., 99., 99., 4.0, 10.0]))\n\n a = arange(6)\n b = arange(6) * 3\n r1, w1 = average([[a,b],[b,a]], axis=1, returned=1)\n self.assertEqual(shape(r1) , shape(w1))\n self.assertEqual(r1.shape , w1.shape)\n r2, w2 = average(ones((2,2,3)), axis=0, weights=[3,1], returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), weights=ones((2,2,3)), returned=1)\n self.failUnless(shape(w2) == shape(r2))\n a2d = array([[1,2],[0,4]], float)\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n a2da = average(a2d)\n self.failUnless(eq (a2da, [0.5, 3.0]))\n a2dma = average(a2dm)\n self.failUnless(eq( a2dma, [1.0, 3.0]))\n a2dma = average(a2dm, axis=None)\n self.failUnless(eq(a2dma, 7./3.))\n a2dma = average(a2dm, axis=1)\n self.failUnless(eq(a2dma, [1.5, 4.0]))\n\n def check_testToPython(self):\n self.assertEqual(1, int(array(1)))\n self.assertEqual(1.0, float(array(1)))\n self.assertEqual(1, int(array([[[1]]])))\n self.assertEqual(1.0, float(array([[1]])))\n self.failUnlessRaises(ValueError, float, array([1,1]))\n self.failUnlessRaises(MAError, float, array([1],mask=[1]))\n self.failUnless(bool(array([0,1])))\n self.failUnless(bool(array([0,0],mask=[0,1])))\n self.failIf(bool(array([0,0])))\n self.failIf(bool(array([0,0],mask=[0,0])))\n\n def check_testScalarArithmetic(self):\n xm = array(0, mask=1)\n self.failUnless((1/array(0)).mask)\n self.failUnless((1 + xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless(maximum(xm, xm).mask)\n self.failUnless(minimum(xm, xm).mask)\n self.failUnless(xm.filled().dtype is xm.data.dtype)\n x = array(0, mask=0)\n self.failUnless(x.filled() is x.data)\n self.failUnlessEqual(str(xm), str(masked_print_option))\n\n def check_testArrayMethods(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnless(eq(a.any(), a.data.any()))\n self.failUnless(eq(a.all(), a.data.all()))\n self.failUnless(eq(a.argmax(), a.data.argmax()))\n self.failUnless(eq(a.argmin(), a.data.argmin()))\n self.failUnless(eq(a.choose(0,1,2,3,4), a.data.choose(0,1,2,3,4)))\n self.failUnless(eq(a.compress([1,0,1]), a.data.compress([1,0,1])))\n self.failUnless(eq(a.conj(), a.data.conj()))\n self.failUnless(eq(a.conjugate(), a.data.conjugate()))\n m = array([[1,2],[3,4]])\n self.failUnless(eq(m.diagonal(), m.data.diagonal()))\n self.failUnless(eq(a.sum(), a.data.sum()))\n self.failUnless(eq(a.take([1,2]), a.data.take([1,2])))\n self.failUnless(eq(m.transpose(), m.data.transpose()))\n\n def check_testArrayAttributes(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnlessEqual(a.ndim, 1)\n\n def check_testAPI(self):\n self.failIf([m for m in dir(numpy.ndarray)\n if m not in dir(array) and not m.startswith('_')])\n\n def check_testSingleElementSubscript(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnlessEqual(a[0].shape, ())\n self.failUnlessEqual(b[0].shape, ())\n self.failUnlessEqual(b[1].shape, ())\n\nclass test_ufuncs(ScipyTestCase):\n def setUp(self):\n self.d = (array([1.0, 0, -1, pi/2]*2, mask=[0,1]+[0]*6),\n array([1.0, 0, -1, pi/2]*2, mask=[1,0]+[0]*6),)\n\n\n def check_testUfuncRegression(self):\n for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate',\n 'sin', 'cos', 'tan',\n 'arcsin', 'arccos', 'arctan',\n 'sinh', 'cosh', 'tanh',\n 'arcsinh',\n 'arccosh',\n 'arctanh',\n 'absolute', 'fabs', 'negative',\n # 'nonzero', 'around',\n 'floor', 'ceil',\n # 'sometrue', 'alltrue',\n 'logical_not',\n 'add', 'subtract', 'multiply',\n 'divide', 'true_divide', 'floor_divide',\n 'remainder', 'fmod', 'hypot', 'arctan2',\n 'equal', 'not_equal', 'less_equal', 'greater_equal',\n 'less', 'greater',\n 'logical_and', 'logical_or', 'logical_xor',\n ]:\n try:\n uf = getattr(umath, f)\n except AttributeError:\n uf = getattr(oldnumeric, f)\n mf = getattr(numpy.ma, f)\n args = self.d[:uf.nin]\n ur = uf(*args)\n mr = mf(*args)\n self.failUnless(eq(ur.filled(0), mr.filled(0), f))\n self.failUnless(eqmask(ur.mask, mr.mask))\n\n def test_reduce(self):\n a = self.d[0]\n self.failIf(alltrue(a))\n self.failUnless(sometrue(a))\n self.failUnlessEqual(sum(a[:3]), 0)\n self.failUnlessEqual(product(a), 0)\n\n def test_minmax(self):\n a = arange(1,13).reshape(3,4)\n amask = masked_where(a < 5,a)\n self.failUnlessEqual(amask.max(), a.max())\n self.failUnlessEqual(amask.min(), 5)\n self.failUnless((amask.max(0) == a.max(0)).all())\n self.failUnless((amask.min(0) == [5,6,7,8]).all())\n self.failUnless(amask.max(1)[0].mask)\n self.failUnless(amask.min(1)[0].mask)\n\n def test_nonzero(self):\n for t in \"?bhilqpBHILQPfdgFDGO\":\n x = array([1,0,2,0], mask=[0,0,1,1])\n self.failUnless(eq(nonzero(x), [0]))\n\ndef eqmask(m1, m2):\n if m1 is nomask:\n return m2 is nomask\n if m2 is nomask:\n return m1 is nomask\n return (m1 == m2).all()\n\ndef timingTest():\n for f in [testf, testinplace]:\n for n in [1000,10000,50000]:\n t = testta(n, f)\n t1 = testtb(n, f)\n t2 = testtc(n, f)\n print f.test_name\n print \"\"\"\\\nn = %7d\nnumpy time (ms) %6.1f\nMA maskless ratio %6.1f\nMA masked ratio %6.1f\n\"\"\" % (n, t*1000.0, t1/t, t2/t)\n\ndef testta(n, f):\n x=numpy.arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtb(n, f):\n x=arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtc(n, f):\n x=arange(n) + 1.0\n x[0] = masked\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testf(x):\n for i in range(25):\n y = x **2 + 2.0 * x - 1.0\n w = x **2 + 1.0\n z = (y / w) ** 2\n return z\ntestf.test_name = 'Simple arithmetic'\n\ndef testinplace(x):\n for i in range(25):\n y = x**2\n y += 2.0*x\n y -= 1.0\n y /= x\n return y\ntestinplace.test_name = 'Inplace operations'\n\nif __name__ == \"__main__\":\n ScipyTest('numpy.core.ma').run()\n #timingTest()\n", + "source_code_before": "import numpy\nimport types, time\nfrom numpy.core.ma import *\nfrom numpy.testing import ScipyTestCase, ScipyTest\npi = numpy.pi\ndef eq(v,w, msg=''):\n result = allclose(v,w)\n if not result:\n print \"\"\"Not eq:%s\n%s\n----\n%s\"\"\"% (msg, str(v), str(w))\n return result\n\nclass test_ma(ScipyTestCase):\n def __init__(self, *args, **kwds):\n ScipyTestCase.__init__(self, *args, **kwds)\n self.setUp()\n\n def setUp (self):\n x=numpy.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])\n y=numpy.array([5.,0.,3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])\n a10 = 10.\n m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]\n m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0 ,0, 1]\n xm = array(x, mask=m1)\n ym = array(y, mask=m2)\n z = numpy.array([-.5, 0., .5, .8])\n zm = array(z, mask=[0,1,0,0])\n xf = numpy.where(m1, 1.e+20, x)\n s = x.shape\n xm.set_fill_value(1.e+20)\n self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf, s)\n\n def check_testBasic1d(self):\n \"Test of basic array creation and properties in 1 dimension.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual(xm.dtype, x.dtype)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual(count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n\n def check_testBasic2d(self):\n \"Test of basic array creation and properties in 2 dimensions.\"\n for s in [(4,3), (6,2)]:\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n x.shape = s\n y.shape = s\n xm.shape = s\n ym.shape = s\n xf.shape = s\n\n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual( count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n self.setUp()\n\n def check_testArithmetic (self):\n \"Test of basic arithmetic.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n a2d = array([[1,2],[0,4]])\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n self.failUnless(eq (a2d * a2d, a2d * a2dm))\n self.failUnless(eq (a2d + a2d, a2d + a2dm))\n self.failUnless(eq (a2d - a2d, a2d - a2dm))\n for s in [(12,), (4,3), (2,6)]:\n x = x.reshape(s)\n y = y.reshape(s)\n xm = xm.reshape(s)\n ym = ym.reshape(s)\n xf = xf.reshape(s)\n self.failUnless(eq(-x, -xm))\n self.failUnless(eq(x + y, xm + ym))\n self.failUnless(eq(x - y, xm - ym))\n self.failUnless(eq(x * y, xm * ym))\n self.failUnless(eq(x / y, xm / ym))\n self.failUnless(eq(a10 + y, a10 + ym))\n self.failUnless(eq(a10 - y, a10 - ym))\n self.failUnless(eq(a10 * y, a10 * ym))\n self.failUnless(eq(a10 / y, a10 / ym))\n self.failUnless(eq(x + a10, xm + a10))\n self.failUnless(eq(x - a10, xm - a10))\n self.failUnless(eq(x * a10, xm * a10))\n self.failUnless(eq(x / a10, xm / a10))\n self.failUnless(eq(x**2, xm**2))\n self.failUnless(eq(abs(x)**2.5, abs(xm) **2.5))\n self.failUnless(eq(x**y, xm**ym))\n self.failUnless(eq(numpy.add(x,y), add(xm, ym)))\n self.failUnless(eq(numpy.subtract(x,y), subtract(xm, ym)))\n self.failUnless(eq(numpy.multiply(x,y), multiply(xm, ym)))\n self.failUnless(eq(numpy.divide(x,y), divide(xm, ym)))\n\n\n def check_testMixedArithmetic(self):\n na = numpy.array([1])\n ma = array([1])\n self.failUnless(isinstance(na + ma, MaskedArray))\n self.failUnless(isinstance(ma + na, MaskedArray))\n\n def check_testUfuncs1 (self):\n \"Test various functions such as sin, cos.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.cos(x), cos(xm)))\n self.failUnless (eq(numpy.cosh(x), cosh(xm)))\n self.failUnless (eq(numpy.sin(x), sin(xm)))\n self.failUnless (eq(numpy.sinh(x), sinh(xm)))\n self.failUnless (eq(numpy.tan(x), tan(xm)))\n self.failUnless (eq(numpy.tanh(x), tanh(xm)))\n self.failUnless (eq(numpy.sqrt(abs(x)), sqrt(xm)))\n self.failUnless (eq(numpy.log(abs(x)), log(xm)))\n self.failUnless (eq(numpy.log10(abs(x)), log10(xm)))\n self.failUnless (eq(numpy.exp(x), exp(xm)))\n self.failUnless (eq(numpy.arcsin(z), arcsin(zm)))\n self.failUnless (eq(numpy.arccos(z), arccos(zm)))\n self.failUnless (eq(numpy.arctan(z), arctan(zm)))\n self.failUnless (eq(numpy.arctan2(x, y), arctan2(xm, ym)))\n self.failUnless (eq(numpy.absolute(x), absolute(xm)))\n self.failUnless (eq(numpy.equal(x,y), equal(xm, ym)))\n self.failUnless (eq(numpy.not_equal(x,y), not_equal(xm, ym)))\n self.failUnless (eq(numpy.less(x,y), less(xm, ym)))\n self.failUnless (eq(numpy.greater(x,y), greater(xm, ym)))\n self.failUnless (eq(numpy.less_equal(x,y), less_equal(xm, ym)))\n self.failUnless (eq(numpy.greater_equal(x,y), greater_equal(xm, ym)))\n self.failUnless (eq(numpy.conjugate(x), conjugate(xm)))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,ym))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((x,y))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,y))))\n self.failUnless (eq(numpy.concatenate((x,y,x)), concatenate((x,ym,x))))\n\n def check_xtestCount (self):\n \"Test count\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless( isinstance(count(ott), types.IntType))\n self.assertEqual(3, count(ott))\n self.assertEqual(1, count(1))\n self.failUnless (eq(0, array(1,mask=[1])))\n ott=ott.reshape((2,2))\n assert isMaskedArray(count(ott,0))\n assert isinstance(count(ott), types.IntType)\n self.failUnless (eq(3, count(ott)))\n assert getmask(count(ott,0)) is nomask\n self.failUnless (eq([1,2],count(ott,0)))\n\n def check_testMinMax (self):\n \"Test minimum and maximum.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n xr = numpy.ravel(x) #max doesn't work if shaped\n xmr = ravel(xm)\n self.failUnless (eq(max(xr), maximum(xmr))) #true because of careful selection of data\n self.failUnless (eq(min(xr), minimum(xmr))) #true because of careful selection of data\n\n def check_testAddSumProd (self):\n \"Test add, sum, product.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.add.reduce(x), add.reduce(x)))\n self.failUnless (eq(numpy.add.accumulate(x), add.accumulate(x)))\n self.failUnless (eq(4, sum(array(4))))\n self.failUnless (eq(4, sum(array(4), axis=0)))\n self.failUnless (eq(numpy.sum(x), sum(x)))\n self.failUnless (eq(numpy.sum(filled(xm,0)), sum(xm)))\n self.failUnless (eq(numpy.sum(x,0), sum(x,0)))\n self.failUnless (eq(numpy.product(x), product(x)))\n self.failUnless (eq(numpy.product(x,0), product(x,0)))\n self.failUnless (eq(numpy.product(filled(xm,1)), product(xm)))\n if len(s) > 1:\n self.failUnless (eq(numpy.concatenate((x,y),1), concatenate((xm,ym),1)))\n self.failUnless (eq(numpy.add.reduce(x,1), add.reduce(x,1)))\n self.failUnless (eq(numpy.sum(x,1), sum(x,1)))\n self.failUnless (eq(numpy.product(x,1), product(x,1)))\n\n\n def check_testCI(self):\n \"Test of conversions and indexing\"\n x1 = numpy.array([1,2,4,3])\n x2 = array(x1, mask = [1,0,0,0])\n x3 = array(x1, mask = [0,1,0,1])\n x4 = array(x1)\n # test conversion to strings\n junk, garbage = str(x2), repr(x2)\n assert eq(numpy.sort(x1),sort(x2, fill_value=0))\n # tests of indexing\n assert type(x2[1]) is type(x1[1])\n assert x1[1] == x2[1]\n assert x2[0] is masked\n assert eq(x1[2],x2[2])\n assert eq(x1[2:5],x2[2:5])\n assert eq(x1[:],x2[:])\n assert eq(x1[1:], x3[1:])\n x1[2]=9\n x2[2]=9\n assert eq(x1,x2)\n x1[1:3] = 99\n x2[1:3] = 99\n assert eq(x1,x2)\n x2[1] = masked\n assert eq(x1,x2)\n x2[1:3]=masked\n assert eq(x1,x2)\n x2[:] = x1\n x2[1] = masked\n assert allequal(getmask(x2),array([0,1,0,0]))\n x3[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x3), array([0,1,1,0]))\n x4[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x4), array([0,1,1,0]))\n assert allequal(x4, array([1,2,3,4]))\n x1 = numpy.arange(5)*1.0\n x2 = masked_values(x1, 3.0)\n assert eq(x1,x2)\n assert allequal(array([0,0,0,1,0],MaskType), x2.mask)\n assert eq(3.0, x2.fill_value())\n x1 = array([1,'hello',2,3],object)\n x2 = numpy.array([1,'hello',2,3],object)\n s1 = x1[1]\n s2 = x2[1]\n self.assertEqual(type(s2), str)\n self.assertEqual(type(s1), str)\n self.assertEqual(s1, s2)\n assert x1[1:1].shape == (0,)\n\n def check_testCopySize(self):\n \"Tests of some subtle points of copying and sizing.\"\n n = [0,0,1,0,0]\n m = make_mask(n)\n m2 = make_mask(m)\n self.failUnless(m is m2)\n m3 = make_mask(m, copy=1)\n self.failUnless(m is not m3)\n\n x1 = numpy.arange(5)\n y1 = array(x1, mask=m)\n self.failUnless( y1.raw_data() is not x1)\n self.failUnless( allequal(x1,y1.raw_data()))\n self.failUnless( y1.mask is m)\n\n y1a = array(y1, copy=0)\n self.failUnless( y1a.raw_data() is y1.raw_data())\n self.failUnless( y1a.mask is y1.mask)\n\n y2 = array(x1, mask=m, copy=0)\n self.failUnless( y2.raw_data() is x1)\n self.failUnless( y2.mask is m)\n self.failUnless( y2[2] is masked)\n y2[2]=9\n self.failUnless( y2[2] is not masked)\n self.failUnless( y2.mask is not m)\n self.failUnless( allequal(y2.mask, 0))\n\n y3 = array(x1*1.0, mask=m)\n self.failUnless(filled(y3).dtype is (x1*1.0).dtype)\n\n x4 = arange(4)\n x4[2] = masked\n y4 = resize(x4, (8,))\n self.failUnless( eq(concatenate([x4,x4]), y4))\n self.failUnless( eq(getmask(y4),[0,0,1,0,0,0,1,0]))\n y5 = repeat(x4, (2,2,2,2))\n self.failUnless( eq(y5, [0,0,1,1,2,2,3,3]))\n y6 = repeat(x4, 2)\n self.failUnless( eq(y5, y6))\n\n def check_testPut(self):\n \"Test of put\"\n d = arange(5)\n n = [0,0,0,1,1]\n m = make_mask(n)\n x = array(d, mask = m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n x[[1,4]] = [10,40]\n self.failUnless( x.mask is not m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is not masked)\n self.failUnless( eq(x, [0,10,2,-1,40]))\n\n x = array(d, mask = m)\n x.put([-1,100,200])\n self.failUnless( eq(x, [-1,100,200,0,0]))\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n\n x = array(d, mask = m)\n x.putmask([30,40])\n self.failUnless( eq(x, [0,1,2,30,40]))\n self.failUnless( x.mask is nomask)\n\n x = array(d, mask = m)\n y = x.compressed()\n z = array(x, mask = m)\n z.put(y)\n assert eq (x, z)\n\n def check_testMaPut(self):\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]\n i = numpy.nonzero(m)\n putmask(xm, m, z)\n assert take(xm, i) == z\n put(ym, i, zm)\n assert take(ym, i) == zm\n\n def check_testOddFeatures(self):\n \"Test of other odd features\"\n x = arange(20); x=x.reshape(4,5)\n x.flat[5] = 12\n assert x[1,0] == 12\n z = x + 10j * x\n assert eq(z.real, x)\n assert eq(z.imag, 10*x)\n assert eq((z*conjugate(z)).real, 101*x*x)\n z.imag[...] = 0.0\n\n x = arange(10)\n x[3] = masked\n assert str(x[3]) == str(masked)\n c = x >= 8\n assert count(where(c,masked,masked)) == 0\n assert shape(where(c,masked,masked)) == c.shape\n z = where(c , x, masked)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is masked\n assert z[7] is masked\n assert z[8] is not masked\n assert z[9] is not masked\n assert eq(x,z)\n z = where(c , masked, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n z = masked_where(c, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n assert eq(x,z)\n x = array([1.,2.,3.,4.,5.])\n c = array([1,1,1,0,0])\n x[2] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n c[0] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n assert eq(masked_where(greater(x, 2), x), masked_greater(x,2))\n assert eq(masked_where(greater_equal(x, 2), x), masked_greater_equal(x,2))\n assert eq(masked_where(less(x, 2), x), masked_less(x,2))\n assert eq(masked_where(less_equal(x, 2), x), masked_less_equal(x,2))\n assert eq(masked_where(not_equal(x, 2), x), masked_not_equal(x,2))\n assert eq(masked_where(equal(x, 2), x), masked_equal(x,2))\n assert eq(masked_where(not_equal(x,2), x), masked_not_equal(x,2))\n assert eq(masked_inside(range(5), 1, 3), [0, 199, 199, 199, 4])\n assert eq(masked_outside(range(5), 1, 3),[199,1,2,3,199])\n assert eq(masked_inside(array(range(5), mask=[1,0,0,0,0]), 1, 3).mask, [1,1,1,1,0])\n assert eq(masked_outside(array(range(5), mask=[0,1,0,0,0]), 1, 3).mask, [1,1,0,0,1])\n assert eq(masked_equal(array(range(5), mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,0])\n assert eq(masked_not_equal(array([2,2,1,2,1], mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,1])\n assert eq(masked_where([1,1,0,0,0], [1,2,3,4,5]), [99,99,3,4,5])\n atest = ones((10,10,10), dtype=float32)\n btest = zeros(atest.shape, MaskType)\n ctest = masked_where(btest,atest)\n assert eq(atest,ctest)\n z = choose(c, (-x, x))\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n x = arange(6)\n x[5] = masked\n y = arange(6)*10\n y[2]= masked\n c = array([1,1,1,0,0,0], mask=[1,0,0,0,0,0])\n cm = c.filled(1)\n z = where(c,x,y)\n zm = where(cm,x,y)\n assert eq(z, zm)\n assert getmask(zm) is nomask\n assert eq(zm, [0,1,2,30,40,50])\n z = where(c, masked, 1)\n assert eq(z, [99,99,99,1,1,1])\n z = where(c, 1, masked)\n assert eq(z, [99, 1, 1, 99, 99, 99])\n\n def check_testMinMax(self):\n \"Test of minumum, maximum.\"\n assert eq(minimum([1,2,3],[4,0,9]), [1,0,3])\n assert eq(maximum([1,2,3],[4,0,9]), [4,2,9])\n x = arange(5)\n y = arange(5) - 2\n x[3] = masked\n y[0] = masked\n assert eq(minimum(x,y), where(less(x,y), x, y))\n assert eq(maximum(x,y), where(greater(x,y), x, y))\n assert minimum(x) == 0\n assert maximum(x) == 4\n\n def check_testTakeTransposeInnerOuter(self):\n \"Test of take, transpose, inner, outer products\"\n x = arange(24)\n y = numpy.arange(24)\n x[5:6] = masked\n x=x.reshape(2,3,4)\n y=y.reshape(2,3,4)\n assert eq(numpy.transpose(y,(2,0,1)), transpose(x,(2,0,1)))\n assert eq(numpy.take(y, (2,0,1), 1), take(x, (2,0,1), 1))\n assert eq(numpy.innerproduct(filled(x,0),filled(y,0)),\n innerproduct(x, y))\n assert eq(numpy.outerproduct(filled(x,0),filled(y,0)),\n outerproduct(x, y))\n y = array(['abc', 1, 'def', 2, 3], object)\n y[2] = masked\n t = take(y,[0,3,4])\n assert t[0] == 'abc'\n assert t[1] == 2\n assert t[2] == 3\n\n def check_testInplace(self):\n \"\"\"Test of inplace operations and rich comparisons\"\"\"\n y = arange(10)\n\n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x += 1\n assert eq(x, y+1)\n xm += 1\n assert eq(x, y+1)\n\n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x -= 1\n assert eq(x, y-1)\n xm -= 1\n assert eq(xm, y-1)\n\n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x *= 2.0\n assert eq(x, y*2)\n xm *= 2.0\n assert eq(xm, y*2)\n\n x = arange(10)*2\n xm = arange(10)\n xm[2] = masked\n x /= 2\n assert eq(x, y)\n xm /= 2\n assert eq(x, y)\n\n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x /= 2.0\n assert eq(x, y/2.0)\n xm /= arange(10)\n assert eq(xm, ones((10,)))\n\n x = arange(10).astype(float32)\n xm = arange(10)\n xm[2] = masked\n id1 = id(x.raw_data())\n x += 1.\n assert id1 == id(x.raw_data())\n assert eq(x, y+1.)\n\n def check_testPickle(self):\n \"Test of pickling\"\n import pickle\n x = arange(12)\n x[4:10:2] = masked\n x = x.reshape(4,3)\n s = pickle.dumps(x)\n y = pickle.loads(s)\n assert eq(x,y)\n\n def check_testMasked(self):\n \"Test of masked element\"\n xx=arange(6)\n xx[1] = masked\n self.failUnless(str(masked) == '--')\n self.failUnless(xx[1] is masked)\n self.failUnlessEqual(filled(xx[1], 0), 0)\n # don't know why these should raise an exception...\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, masked)\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, 2)\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, xx)\n #self.failUnlessRaises(Exception, lambda x,y: x+y, xx, masked)\n\n def check_testAverage1(self):\n \"Test of average.\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless(eq(2.0, average(ott)))\n self.failUnless(eq(2.0, average(ott, weights=[1., 1., 2., 1.])))\n result, wts = average(ott, weights=[1.,1.,2.,1.], returned=1)\n self.failUnless(eq(2.0, result))\n self.failUnless(wts == 4.0)\n ott[:] = masked\n self.failUnless(average(ott) is masked)\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n ott=ott.reshape(2,2)\n ott[:,1] = masked\n self.failUnless(eq(average(ott), [2.0, 0.0]))\n self.failUnless(average(ott,axis=1)[0] is masked)\n self.failUnless(eq([2.,0.], average(ott)))\n result, wts = average(ott, returned=1)\n self.failUnless(eq(wts, [1., 0.]))\n\n def check_testAverage2(self):\n \"More tests of average.\"\n w1 = [0,1,1,1,1,0]\n w2 = [[0,1,1,1,1,0],[1,0,0,0,0,1]]\n x=arange(6)\n self.failUnless(allclose(average(x), 2.5))\n self.failUnless(allclose(average(x, weights=w1), 2.5))\n y=array([arange(6), 2.0*arange(6)])\n self.failUnless(allclose(average(y, None), numpy.add.reduce(numpy.arange(6))*3./12.))\n self.failUnless(allclose(average(y, axis=0), numpy.arange(6) * 3./2.))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n self.failUnless(allclose(average(y, None, weights=w2), 20./6.))\n self.failUnless(allclose(average(y, axis=0, weights=w2), [0.,1.,2.,3.,4.,10.]))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n m1 = zeros(6)\n m2 = [0,0,1,1,0,0]\n m3 = [[0,0,1,1,0,0],[0,1,1,1,1,0]]\n m4 = ones(6)\n m5 = [0, 1, 1, 1, 1, 1]\n self.failUnless(allclose(average(masked_array(x, m1)), 2.5))\n self.failUnless(allclose(average(masked_array(x, m2)), 2.5))\n self.failUnless(average(masked_array(x, m4)) is masked)\n self.assertEqual(average(masked_array(x, m5)), 0.0)\n self.assertEqual(count(average(masked_array(x, m4))), 0)\n z = masked_array(y, m3)\n self.failUnless(allclose(average(z, None), 20./6.))\n self.failUnless(allclose(average(z, axis=0), [0.,1.,99.,99.,4.0, 7.5]))\n self.failUnless(allclose(average(z, axis=1), [2.5, 5.0]))\n self.failUnless(allclose( average(z,weights=w2), [0.,1., 99., 99., 4.0, 10.0]))\n\n a = arange(6)\n b = arange(6) * 3\n r1, w1 = average([[a,b],[b,a]], axis=1, returned=1)\n self.assertEqual(shape(r1) , shape(w1))\n self.assertEqual(r1.shape , w1.shape)\n r2, w2 = average(ones((2,2,3)), axis=0, weights=[3,1], returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), weights=ones((2,2,3)), returned=1)\n self.failUnless(shape(w2) == shape(r2))\n a2d = array([[1,2],[0,4]], float)\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n a2da = average(a2d)\n self.failUnless(eq (a2da, [0.5, 3.0]))\n a2dma = average(a2dm)\n self.failUnless(eq( a2dma, [1.0, 3.0]))\n a2dma = average(a2dm, axis=None)\n self.failUnless(eq(a2dma, 7./3.))\n a2dma = average(a2dm, axis=1)\n self.failUnless(eq(a2dma, [1.5, 4.0]))\n\n def check_testToPython(self):\n self.assertEqual(1, int(array(1)))\n self.assertEqual(1.0, float(array(1)))\n self.assertEqual(1, int(array([[[1]]])))\n self.assertEqual(1.0, float(array([[1]])))\n self.failUnlessRaises(ValueError, float, array([1,1]))\n self.failUnlessRaises(MAError, float, array([1],mask=[1]))\n self.failUnless(bool(array([0,1])))\n self.failUnless(bool(array([0,0],mask=[0,1])))\n self.failIf(bool(array([0,0])))\n self.failIf(bool(array([0,0],mask=[0,0])))\n\n def check_testScalarArithmetic(self):\n xm = array(0, mask=1)\n self.failUnless((1/array(0)).mask)\n self.failUnless((1 + xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless(maximum(xm, xm).mask)\n self.failUnless(minimum(xm, xm).mask)\n self.failUnless(xm.filled().dtype is xm.data.dtype)\n x = array(0, mask=0)\n self.failUnless(x.filled() is x.data)\n self.failUnlessEqual(str(xm), str(masked_print_option))\n\n def check_testArrayMethods(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnless(eq(a.any(), a.data.any()))\n self.failUnless(eq(a.all(), a.data.all()))\n self.failUnless(eq(a.argmax(), a.data.argmax()))\n self.failUnless(eq(a.argmin(), a.data.argmin()))\n self.failUnless(eq(a.choose(0,1,2,3,4), a.data.choose(0,1,2,3,4)))\n self.failUnless(eq(a.compress([1,0,1]), a.data.compress([1,0,1])))\n self.failUnless(eq(a.conj(), a.data.conj()))\n self.failUnless(eq(a.conjugate(), a.data.conjugate()))\n m = array([[1,2],[3,4]])\n self.failUnless(eq(m.diagonal(), m.data.diagonal()))\n self.failUnless(eq(a.sum(), a.data.sum()))\n self.failUnless(eq(a.take([1,2]), a.data.take([1,2])))\n self.failUnless(eq(m.transpose(), m.data.transpose()))\n\n def check_testArrayAttributes(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnlessEqual(a.ndim, 1)\n\n def check_testAPI(self):\n self.failIf([m for m in dir(numpy.ndarray)\n if m not in dir(array) and not m.startswith('_')])\n\n def check_testSingleElementSubscript(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnlessEqual(a[0].shape, ())\n self.failUnlessEqual(b[0].shape, ())\n self.failUnlessEqual(b[1].shape, ())\n\nclass test_ufuncs(ScipyTestCase):\n def setUp(self):\n self.d = (array([1.0, 0, -1, pi/2]*2, mask=[0,1]+[0]*6),\n array([1.0, 0, -1, pi/2]*2, mask=[1,0]+[0]*6),)\n\n\n def check_testUfuncRegression(self):\n for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate',\n 'sin', 'cos', 'tan',\n 'arcsin', 'arccos', 'arctan',\n 'sinh', 'cosh', 'tanh',\n 'arcsinh',\n 'arccosh',\n 'arctanh',\n 'absolute', 'fabs', 'negative',\n # 'nonzero', 'around',\n 'floor', 'ceil',\n # 'sometrue', 'alltrue',\n 'logical_not',\n 'add', 'subtract', 'multiply',\n 'divide', 'true_divide', 'floor_divide',\n 'remainder', 'fmod', 'hypot', 'arctan2',\n 'equal', 'not_equal', 'less_equal', 'greater_equal',\n 'less', 'greater',\n 'logical_and', 'logical_or', 'logical_xor',\n ]:\n try:\n uf = getattr(umath, f)\n except AttributeError:\n uf = getattr(oldnumeric, f)\n mf = getattr(numpy.ma, f)\n args = self.d[:uf.nin]\n ur = uf(*args)\n mr = mf(*args)\n self.failUnless(eq(ur.filled(0), mr.filled(0), f))\n self.failUnless(eqmask(ur.mask, mr.mask))\n\n def test_reduce(self):\n a = self.d[0]\n self.failIf(alltrue(a))\n self.failUnless(sometrue(a))\n self.failUnlessEqual(sum(a[:3]), 0)\n self.failUnlessEqual(product(a), 0)\n\n def test_minmax(self):\n a = arange(1,13).reshape(3,4)\n amask = masked_where(a < 5,a)\n self.failUnlessEqual(amask.max(), a.max())\n self.failUnlessEqual(amask.min(), 5)\n self.failUnless((amask.max(0) == a.max(0)).all())\n self.failUnless((amask.min(0) == [5,6,7,8]).all())\n self.failUnless(amask.max(1)[0].mask)\n self.failUnless(amask.min(1)[0].mask)\n\n def test_nonzero(self):\n for t in \"?bhilqpBHILQPfdgFDGO\":\n x = array([1,0,2,0], mask=[0,0,1,1])\n self.failUnless(eq(nonzero(x), [0]))\n\ndef eqmask(m1, m2):\n if m1 is nomask:\n return m2 is nomask\n if m2 is nomask:\n return m1 is nomask\n return (m1 == m2).all()\n\ndef timingTest():\n for f in [testf, testinplace]:\n for n in [1000,10000,50000]:\n t = testta(n, f)\n t1 = testtb(n, f)\n t2 = testtc(n, f)\n print f.test_name\n print \"\"\"\\\nn = %7d\nnumpy time (ms) %6.1f\nMA maskless ratio %6.1f\nMA masked ratio %6.1f\n\"\"\" % (n, t*1000.0, t1/t, t2/t)\n\ndef testta(n, f):\n x=numpy.arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtb(n, f):\n x=arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtc(n, f):\n x=arange(n) + 1.0\n x[0] = masked\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testf(x):\n for i in range(25):\n y = x **2 + 2.0 * x - 1.0\n w = x **2 + 1.0\n z = (y / w) ** 2\n return z\ntestf.test_name = 'Simple arithmetic'\n\ndef testinplace(x):\n for i in range(25):\n y = x**2\n y += 2.0*x\n y -= 1.0\n y /= x\n return y\ntestinplace.test_name = 'Inplace operations'\n\nif __name__ == \"__main__\":\n ScipyTest('numpy.core.ma').run()\n #timingTest()\n", + "methods": [ + { + "name": "eq", + "long_name": "eq( v , w , msg = '' )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 41, + "parameters": [ + "v", + "w", + "msg" + ], + "start_line": 7, + "end_line": 14, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , * args , ** kwds )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 17, + "end_line": 19, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 276, + "parameters": [ + "self" + ], + "start_line": 21, + "end_line": 34, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic1d", + "long_name": "check_testBasic1d( self )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 1, + "token_count": 174, + "parameters": [ + "self" + ], + "start_line": 36, + "end_line": 48, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic2d", + "long_name": "check_testBasic2d( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 2, + "token_count": 209, + "parameters": [ + "self" + ], + "start_line": 50, + "end_line": 69, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "check_testArithmetic", + "long_name": "check_testArithmetic( self )", + "filename": "test_ma.py", + "nloc": 34, + "complexity": 2, + "token_count": 518, + "parameters": [ + "self" + ], + "start_line": 71, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "check_testMixedArithmetic", + "long_name": "check_testMixedArithmetic( self )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 107, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_testUfuncs1", + "long_name": "check_testUfuncs1( self )", + "filename": "test_ma.py", + "nloc": 29, + "complexity": 1, + "token_count": 600, + "parameters": [ + "self" + ], + "start_line": 113, + "end_line": 141, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "check_xtestCount", + "long_name": "check_xtestCount( self )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 1, + "token_count": 174, + "parameters": [ + "self" + ], + "start_line": 143, + "end_line": 155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 157, + "end_line": 163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_testAddSumProd", + "long_name": "check_testAddSumProd( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 2, + "token_count": 361, + "parameters": [ + "self" + ], + "start_line": 165, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testCI", + "long_name": "check_testCI( self )", + "filename": "test_ma.py", + "nloc": 46, + "complexity": 1, + "token_count": 560, + "parameters": [ + "self" + ], + "start_line": 185, + "end_line": 232, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 1 + }, + { + "name": "check_testCopySize", + "long_name": "check_testCopySize( self )", + "filename": "test_ma.py", + "nloc": 35, + "complexity": 1, + "token_count": 409, + "parameters": [ + "self" + ], + "start_line": 234, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 1 + }, + { + "name": "check_testPut", + "long_name": "check_testPut( self )", + "filename": "test_ma.py", + "nloc": 27, + "complexity": 1, + "token_count": 291, + "parameters": [ + "self" + ], + "start_line": 275, + "end_line": 304, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "check_testMaPut", + "long_name": "check_testMaPut( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 101, + "parameters": [ + "self" + ], + "start_line": 306, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_testOddFeatures", + "long_name": "check_testOddFeatures( self )", + "filename": "test_ma.py", + "nloc": 88, + "complexity": 1, + "token_count": 1188, + "parameters": [ + "self" + ], + "start_line": 315, + "end_line": 403, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 154, + "parameters": [ + "self" + ], + "start_line": 405, + "end_line": 416, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testTakeTransposeInnerOuter", + "long_name": "check_testTakeTransposeInnerOuter( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 1, + "token_count": 235, + "parameters": [ + "self" + ], + "start_line": 418, + "end_line": 436, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "check_testInplace", + "long_name": "check_testInplace( self )", + "filename": "test_ma.py", + "nloc": 44, + "complexity": 1, + "token_count": 315, + "parameters": [ + "self" + ], + "start_line": 438, + "end_line": 488, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testPickle", + "long_name": "check_testPickle( self )", + "filename": "test_ma.py", + "nloc": 9, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 490, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_testMasked", + "long_name": "check_testMasked( self )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 500, + "end_line": 506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage1", + "long_name": "check_testAverage1( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 1, + "token_count": 289, + "parameters": [ + "self" + ], + "start_line": 513, + "end_line": 530, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage2", + "long_name": "check_testAverage2( self )", + "filename": "test_ma.py", + "nloc": 50, + "complexity": 1, + "token_count": 945, + "parameters": [ + "self" + ], + "start_line": 532, + "end_line": 582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testToPython", + "long_name": "check_testToPython( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 193, + "parameters": [ + "self" + ], + "start_line": 584, + "end_line": 594, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testScalarArithmetic", + "long_name": "check_testScalarArithmetic( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 146, + "parameters": [ + "self" + ], + "start_line": 596, + "end_line": 607, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testArrayMethods", + "long_name": "check_testArrayMethods( self )", + "filename": "test_ma.py", + "nloc": 16, + "complexity": 1, + "token_count": 351, + "parameters": [ + "self" + ], + "start_line": 609, + "end_line": 624, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "check_testArrayAttributes", + "long_name": "check_testArrayAttributes( self )", + "filename": "test_ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 626, + "end_line": 629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "check_testAPI", + "long_name": "check_testAPI( self )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 4, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 631, + "end_line": 633, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_testSingleElementSubscript", + "long_name": "check_testSingleElementSubscript( self )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 635, + "end_line": 640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 643, + "end_line": 645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_testUfuncRegression", + "long_name": "check_testUfuncRegression( self )", + "filename": "test_ma.py", + "nloc": 28, + "complexity": 3, + "token_count": 189, + "parameters": [ + "self" + ], + "start_line": 648, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "test_reduce", + "long_name": "test_reduce( self )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 679, + "end_line": 684, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "test_minmax", + "long_name": "test_minmax( self )", + "filename": "test_ma.py", + "nloc": 9, + "complexity": 1, + "token_count": 141, + "parameters": [ + "self" + ], + "start_line": 686, + "end_line": 694, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "test_nonzero", + "long_name": "test_nonzero( self )", + "filename": "test_ma.py", + "nloc": 4, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 696, + "end_line": 699, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "eqmask", + "long_name": "eqmask( m1 , m2 )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 3, + "token_count": 35, + "parameters": [ + "m1", + "m2" + ], + "start_line": 701, + "end_line": 706, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "timingTest", + "long_name": "timingTest( )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 3, + "token_count": 72, + "parameters": [], + "start_line": 708, + "end_line": 720, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "testta", + "long_name": "testta( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 40, + "parameters": [ + "n", + "f" + ], + "start_line": 722, + "end_line": 726, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtb", + "long_name": "testtb( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 38, + "parameters": [ + "n", + "f" + ], + "start_line": 728, + "end_line": 732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtc", + "long_name": "testtc( n , f )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 44, + "parameters": [ + "n", + "f" + ], + "start_line": 734, + "end_line": 739, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testf", + "long_name": "testf( x )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 48, + "parameters": [ + "x" + ], + "start_line": 741, + "end_line": 746, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testinplace", + "long_name": "testinplace( x )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 36, + "parameters": [ + "x" + ], + "start_line": 749, + "end_line": 755, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "eq", + "long_name": "eq( v , w , msg = '' )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 41, + "parameters": [ + "v", + "w", + "msg" + ], + "start_line": 6, + "end_line": 13, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , * args , ** kwds )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 16, + "end_line": 18, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 276, + "parameters": [ + "self" + ], + "start_line": 20, + "end_line": 33, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic1d", + "long_name": "check_testBasic1d( self )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 1, + "token_count": 174, + "parameters": [ + "self" + ], + "start_line": 35, + "end_line": 47, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic2d", + "long_name": "check_testBasic2d( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 2, + "token_count": 209, + "parameters": [ + "self" + ], + "start_line": 49, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "check_testArithmetic", + "long_name": "check_testArithmetic( self )", + "filename": "test_ma.py", + "nloc": 34, + "complexity": 2, + "token_count": 518, + "parameters": [ + "self" + ], + "start_line": 70, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "check_testMixedArithmetic", + "long_name": "check_testMixedArithmetic( self )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 106, + "end_line": 110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_testUfuncs1", + "long_name": "check_testUfuncs1( self )", + "filename": "test_ma.py", + "nloc": 29, + "complexity": 1, + "token_count": 600, + "parameters": [ + "self" + ], + "start_line": 112, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "check_xtestCount", + "long_name": "check_xtestCount( self )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 1, + "token_count": 174, + "parameters": [ + "self" + ], + "start_line": 142, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 156, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_testAddSumProd", + "long_name": "check_testAddSumProd( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 2, + "token_count": 361, + "parameters": [ + "self" + ], + "start_line": 164, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testCI", + "long_name": "check_testCI( self )", + "filename": "test_ma.py", + "nloc": 46, + "complexity": 1, + "token_count": 560, + "parameters": [ + "self" + ], + "start_line": 184, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 1 + }, + { + "name": "check_testCopySize", + "long_name": "check_testCopySize( self )", + "filename": "test_ma.py", + "nloc": 35, + "complexity": 1, + "token_count": 409, + "parameters": [ + "self" + ], + "start_line": 233, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 1 + }, + { + "name": "check_testPut", + "long_name": "check_testPut( self )", + "filename": "test_ma.py", + "nloc": 27, + "complexity": 1, + "token_count": 291, + "parameters": [ + "self" + ], + "start_line": 274, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "check_testMaPut", + "long_name": "check_testMaPut( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 101, + "parameters": [ + "self" + ], + "start_line": 305, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_testOddFeatures", + "long_name": "check_testOddFeatures( self )", + "filename": "test_ma.py", + "nloc": 88, + "complexity": 1, + "token_count": 1188, + "parameters": [ + "self" + ], + "start_line": 314, + "end_line": 402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 154, + "parameters": [ + "self" + ], + "start_line": 404, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testTakeTransposeInnerOuter", + "long_name": "check_testTakeTransposeInnerOuter( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 1, + "token_count": 235, + "parameters": [ + "self" + ], + "start_line": 417, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "check_testInplace", + "long_name": "check_testInplace( self )", + "filename": "test_ma.py", + "nloc": 44, + "complexity": 1, + "token_count": 315, + "parameters": [ + "self" + ], + "start_line": 437, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testPickle", + "long_name": "check_testPickle( self )", + "filename": "test_ma.py", + "nloc": 9, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 489, + "end_line": 497, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_testMasked", + "long_name": "check_testMasked( self )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 499, + "end_line": 505, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage1", + "long_name": "check_testAverage1( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 1, + "token_count": 289, + "parameters": [ + "self" + ], + "start_line": 512, + "end_line": 529, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage2", + "long_name": "check_testAverage2( self )", + "filename": "test_ma.py", + "nloc": 50, + "complexity": 1, + "token_count": 945, + "parameters": [ + "self" + ], + "start_line": 531, + "end_line": 581, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testToPython", + "long_name": "check_testToPython( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 193, + "parameters": [ + "self" + ], + "start_line": 583, + "end_line": 593, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testScalarArithmetic", + "long_name": "check_testScalarArithmetic( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 146, + "parameters": [ + "self" + ], + "start_line": 595, + "end_line": 606, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testArrayMethods", + "long_name": "check_testArrayMethods( self )", + "filename": "test_ma.py", + "nloc": 16, + "complexity": 1, + "token_count": 351, + "parameters": [ + "self" + ], + "start_line": 608, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "check_testArrayAttributes", + "long_name": "check_testArrayAttributes( self )", + "filename": "test_ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 625, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "check_testAPI", + "long_name": "check_testAPI( self )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 4, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 630, + "end_line": 632, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_testSingleElementSubscript", + "long_name": "check_testSingleElementSubscript( self )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 634, + "end_line": 639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 642, + "end_line": 644, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_testUfuncRegression", + "long_name": "check_testUfuncRegression( self )", + "filename": "test_ma.py", + "nloc": 28, + "complexity": 3, + "token_count": 189, + "parameters": [ + "self" + ], + "start_line": 647, + "end_line": 676, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "test_reduce", + "long_name": "test_reduce( self )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 678, + "end_line": 683, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "test_minmax", + "long_name": "test_minmax( self )", + "filename": "test_ma.py", + "nloc": 9, + "complexity": 1, + "token_count": 141, + "parameters": [ + "self" + ], + "start_line": 685, + "end_line": 693, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "test_nonzero", + "long_name": "test_nonzero( self )", + "filename": "test_ma.py", + "nloc": 4, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 695, + "end_line": 698, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "eqmask", + "long_name": "eqmask( m1 , m2 )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 3, + "token_count": 35, + "parameters": [ + "m1", + "m2" + ], + "start_line": 700, + "end_line": 705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "timingTest", + "long_name": "timingTest( )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 3, + "token_count": 72, + "parameters": [], + "start_line": 707, + "end_line": 719, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "testta", + "long_name": "testta( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 40, + "parameters": [ + "n", + "f" + ], + "start_line": 721, + "end_line": 725, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtb", + "long_name": "testtb( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 38, + "parameters": [ + "n", + "f" + ], + "start_line": 727, + "end_line": 731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtc", + "long_name": "testtc( n , f )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 44, + "parameters": [ + "n", + "f" + ], + "start_line": 733, + "end_line": 738, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testf", + "long_name": "testf( x )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 48, + "parameters": [ + "x" + ], + "start_line": 740, + "end_line": 745, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testinplace", + "long_name": "testinplace( x )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 36, + "parameters": [ + "x" + ], + "start_line": 748, + "end_line": 754, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 688, + "complexity": 57, + "token_count": 8911, + "diff_parsed": { + "added": [ + "from numpy.core.numerictypes import float32" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "8f28c43e00c6622e6ca654be1652d5a5a77fd28b", + "msg": "whoops, readd cc_dynamic to libs to link with for darwin platform.", + "author": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "committer": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "author_date": "2006-03-21T03:54:15+00:00", + "author_timezone": 0, + "committer_date": "2006-03-21T03:54:15+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "0838fa5177a802345d1bab2bc6cbdf36bc57d7bd" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 2, + "insertions": 2, + "lines": 4, + "files": 1, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/distutils/fcompiler/gnu.py", + "new_path": "numpy/distutils/fcompiler/gnu.py", + "filename": "gnu.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -111,8 +111,8 @@ def get_libraries(self):\n opt.append('gcc')\n if g2c is not None:\n opt.append(g2c)\n-# if sys.platform == 'darwin':\n-# opt.append('cc_dynamic')\n+ if sys.platform == 'darwin':\n+ opt.append('cc_dynamic')\n return opt\n \n def get_flags_debug(self):\n", + "added_lines": 2, + "deleted_lines": 2, + "source_code": "\nimport re\nimport os\nimport sys\nimport warnings\n\nfrom numpy.distutils.cpuinfo import cpu\nfrom numpy.distutils.ccompiler import simple_version_match\nfrom numpy.distutils.fcompiler import FCompiler\nfrom numpy.distutils.exec_command import exec_command, find_executable\nfrom numpy.distutils.misc_util import mingw32\n\nclass GnuFCompiler(FCompiler):\n\n compiler_type = 'gnu'\n version_match = simple_version_match(start=r'GNU Fortran (?!95)')\n\n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)\n # GNU Fortran (GCC) 3.3.3 (Debian 20040401)\n # GNU Fortran 0.5.25 20010319 (prerelease)\n # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)\n\n for fc_exe in map(find_executable,['g77','f77']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_f90' : None,\n 'compiler_fix' : None,\n 'linker_so' : [fc_exe,\"-Wall\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n 'linker_exe' : [fc_exe,\"-Wall\"]\n }\n module_dir_switch = None\n module_include_switch = None\n\n # Cygwin: f771: warning: -fPIC ignored for target (all code is position independent)\n if os.name != 'nt' and sys.platform!='cygwin':\n pic_flags = ['-fPIC']\n\n g2c = 'g2c'\n\n #def get_linker_so(self):\n # # win32 linking should be handled by standard linker\n # # Darwin g77 cannot be used as a linker.\n # #if re.match(r'(darwin)', sys.platform):\n # # return\n # return FCompiler.get_linker_so(self)\n\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', None)\n if target is None:\n target = '10.3'\n major, minor = target.split('.')\n if int(minor) < 3:\n minor = '3'\n warnings.warn('Environment variable '\n 'MACOSX_DEPLOYMENT_TARGET reset to 10.3')\n os.environ['MACOSX_DEPLOYMENT_TARGET'] = '%s.%s' % (major,\n minor)\n\n opt.extend(['-undefined', 'dynamic_lookup', '-bundle'])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work. 'man gcc' says:\n # \".. Instead of using -mimpure-text, you should compile all\n # source code with -fpic or -fPIC.\"\n opt.append('-mimpure-text')\n return opt\n\n def get_libgcc_dir(self):\n status, output = exec_command('%s -print-libgcc-file-name' \\\n % (self.compiler_f77[0]),use_tee=0)\n if not status:\n return os.path.dirname(output)\n return\n\n def get_library_dirs(self):\n opt = []\n if sys.platform[:5] != 'linux':\n d = self.get_libgcc_dir()\n if d:\n opt.append(d)\n return opt\n\n def get_libraries(self):\n opt = []\n d = self.get_libgcc_dir()\n if d is not None:\n g2c = self.g2c + '-pic'\n f = self.static_lib_format % (g2c, self.static_lib_extension)\n if not os.path.isfile(os.path.join(d,f)):\n g2c = self.g2c\n else:\n g2c = self.g2c\n\n if sys.platform=='win32':\n # To avoid undefined reference __EH_FRAME_BEGIN__ linker error,\n # don't use -lgcc option for mingw32 g77 linker.\n if not mingw32():\n opt.append('gcc')\n if g2c is not None:\n opt.append(g2c)\n if sys.platform == 'darwin':\n opt.append('cc_dynamic')\n return opt\n\n def get_flags_debug(self):\n return ['-g']\n\n def get_flags_opt(self):\n if self.get_version()<='3.3.3':\n # With this compiler version building Fortran BLAS/LAPACK\n # with -O3 caused failures in lib.lapack heevr,syevr tests.\n opt = ['-O2']\n else:\n opt = ['-O3']\n opt.append('-funroll-loops')\n return opt\n\n def get_flags_arch(self):\n opt = []\n if sys.platform=='darwin':\n if os.name != 'posix':\n # this should presumably correspond to Apple\n if cpu.is_ppc():\n opt.append('-arch ppc')\n elif cpu.is_i386():\n opt.append('-arch i386')\n for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\\\n '403 505 801 821 823 860'.split():\n if getattr(cpu,'is_ppc%s'%a)():\n opt.append('-mcpu='+a)\n opt.append('-mtune='+a)\n break\n return opt\n\n # default march options in case we find nothing better\n if cpu.is_i686():\n march_opt = '-march=i686'\n elif cpu.is_i586():\n march_opt = '-march=i586'\n elif cpu.is_i486():\n march_opt = '-march=i486'\n elif cpu.is_i386():\n march_opt = '-march=i386'\n else:\n march_opt = ''\n\n gnu_ver = self.get_version()\n\n if gnu_ver >= '0.5.26': # gcc 3.0\n if cpu.is_AthlonK6():\n march_opt = '-march=k6'\n elif cpu.is_AthlonK7():\n march_opt = '-march=athlon'\n\n if gnu_ver >= '3.1.1':\n if cpu.is_AthlonK6_2():\n march_opt = '-march=k6-2'\n elif cpu.is_AthlonK6_3():\n march_opt = '-march=k6-3'\n elif cpu.is_AthlonMP():\n march_opt = '-march=athlon-mp'\n # there's also: athlon-tbird, athlon-4, athlon-xp\n elif cpu.is_Nocona():\n march_opt = '-march=nocona'\n elif cpu.is_Prescott():\n march_opt = '-march=prescott'\n elif cpu.is_PentiumIV():\n march_opt = '-march=pentium4'\n elif cpu.is_PentiumIII():\n march_opt = '-march=pentium3'\n elif cpu.is_PentiumM():\n march_opt = '-march=pentium3'\n elif cpu.is_PentiumII():\n march_opt = '-march=pentium2'\n\n if gnu_ver >= '3.4':\n if cpu.is_Opteron():\n march_opt = '-march=opteron'\n elif cpu.is_Athlon64():\n march_opt = '-march=athlon64'\n\n if gnu_ver >= '3.4.4':\n if cpu.is_PentiumM():\n march_opt = '-march=pentium-m'\n\n # Note: gcc 3.2 on win32 has breakage with -march specified\n if '3.1.1' <= gnu_ver <= '3.4' and sys.platform=='win32':\n march_opt = ''\n\n if march_opt:\n opt.append(march_opt)\n\n # other CPU flags\n if gnu_ver >= '3.1.1':\n if cpu.has_mmx(): opt.append('-mmmx')\n if cpu.has_3dnow(): opt.append('-m3dnow')\n\n if gnu_ver > '3.2.2':\n if cpu.has_sse2(): opt.append('-msse2')\n if cpu.has_sse(): opt.append('-msse')\n if gnu_ver >= '3.4':\n if cpu.has_sse3(): opt.append('-msse3')\n if cpu.is_Intel():\n opt.append('-fomit-frame-pointer')\n if cpu.is_32bit():\n opt.append('-malign-double')\n return opt\n\nclass Gnu95FCompiler(GnuFCompiler):\n\n compiler_type = 'gnu95'\n version_match = simple_version_match(start='GNU Fortran 95')\n\n # 'gfortran --version' results:\n # Debian: GNU Fortran 95 (GCC 4.0.3 20051023 (prerelease) (Debian 4.0.2-3))\n # OS X: GNU Fortran 95 (GCC) 4.1.0\n # GNU Fortran 95 (GCC) 4.2.0 20060218 (experimental)\n\n for fc_exe in map(find_executable,['gfortran','f95']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-ffixed-form\",\"-fno-second-underscore\"],\n 'compiler_f90' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_fix' : [fc_exe,\"-Wall\",\"-ffixed-form\",\"-fno-second-underscore\"],\n 'linker_so' : [fc_exe,\"-Wall\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n 'linker_exe' : [fc_exe,\"-Wall\"]\n }\n module_dir_switch = '-J'\n module_include_switch = '-I'\n\n g2c = 'gfortran'\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from numpy.distutils.fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n compiler = GnuFCompiler()\n compiler.customize()\n print compiler.get_version()\n", + "source_code_before": "\nimport re\nimport os\nimport sys\nimport warnings\n\nfrom numpy.distutils.cpuinfo import cpu\nfrom numpy.distutils.ccompiler import simple_version_match\nfrom numpy.distutils.fcompiler import FCompiler\nfrom numpy.distutils.exec_command import exec_command, find_executable\nfrom numpy.distutils.misc_util import mingw32\n\nclass GnuFCompiler(FCompiler):\n\n compiler_type = 'gnu'\n version_match = simple_version_match(start=r'GNU Fortran (?!95)')\n\n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)\n # GNU Fortran (GCC) 3.3.3 (Debian 20040401)\n # GNU Fortran 0.5.25 20010319 (prerelease)\n # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)\n\n for fc_exe in map(find_executable,['g77','f77']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_f90' : None,\n 'compiler_fix' : None,\n 'linker_so' : [fc_exe,\"-Wall\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n 'linker_exe' : [fc_exe,\"-Wall\"]\n }\n module_dir_switch = None\n module_include_switch = None\n\n # Cygwin: f771: warning: -fPIC ignored for target (all code is position independent)\n if os.name != 'nt' and sys.platform!='cygwin':\n pic_flags = ['-fPIC']\n\n g2c = 'g2c'\n\n #def get_linker_so(self):\n # # win32 linking should be handled by standard linker\n # # Darwin g77 cannot be used as a linker.\n # #if re.match(r'(darwin)', sys.platform):\n # # return\n # return FCompiler.get_linker_so(self)\n\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', None)\n if target is None:\n target = '10.3'\n major, minor = target.split('.')\n if int(minor) < 3:\n minor = '3'\n warnings.warn('Environment variable '\n 'MACOSX_DEPLOYMENT_TARGET reset to 10.3')\n os.environ['MACOSX_DEPLOYMENT_TARGET'] = '%s.%s' % (major,\n minor)\n\n opt.extend(['-undefined', 'dynamic_lookup', '-bundle'])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work. 'man gcc' says:\n # \".. Instead of using -mimpure-text, you should compile all\n # source code with -fpic or -fPIC.\"\n opt.append('-mimpure-text')\n return opt\n\n def get_libgcc_dir(self):\n status, output = exec_command('%s -print-libgcc-file-name' \\\n % (self.compiler_f77[0]),use_tee=0)\n if not status:\n return os.path.dirname(output)\n return\n\n def get_library_dirs(self):\n opt = []\n if sys.platform[:5] != 'linux':\n d = self.get_libgcc_dir()\n if d:\n opt.append(d)\n return opt\n\n def get_libraries(self):\n opt = []\n d = self.get_libgcc_dir()\n if d is not None:\n g2c = self.g2c + '-pic'\n f = self.static_lib_format % (g2c, self.static_lib_extension)\n if not os.path.isfile(os.path.join(d,f)):\n g2c = self.g2c\n else:\n g2c = self.g2c\n\n if sys.platform=='win32':\n # To avoid undefined reference __EH_FRAME_BEGIN__ linker error,\n # don't use -lgcc option for mingw32 g77 linker.\n if not mingw32():\n opt.append('gcc')\n if g2c is not None:\n opt.append(g2c)\n# if sys.platform == 'darwin':\n# opt.append('cc_dynamic')\n return opt\n\n def get_flags_debug(self):\n return ['-g']\n\n def get_flags_opt(self):\n if self.get_version()<='3.3.3':\n # With this compiler version building Fortran BLAS/LAPACK\n # with -O3 caused failures in lib.lapack heevr,syevr tests.\n opt = ['-O2']\n else:\n opt = ['-O3']\n opt.append('-funroll-loops')\n return opt\n\n def get_flags_arch(self):\n opt = []\n if sys.platform=='darwin':\n if os.name != 'posix':\n # this should presumably correspond to Apple\n if cpu.is_ppc():\n opt.append('-arch ppc')\n elif cpu.is_i386():\n opt.append('-arch i386')\n for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\\\n '403 505 801 821 823 860'.split():\n if getattr(cpu,'is_ppc%s'%a)():\n opt.append('-mcpu='+a)\n opt.append('-mtune='+a)\n break\n return opt\n\n # default march options in case we find nothing better\n if cpu.is_i686():\n march_opt = '-march=i686'\n elif cpu.is_i586():\n march_opt = '-march=i586'\n elif cpu.is_i486():\n march_opt = '-march=i486'\n elif cpu.is_i386():\n march_opt = '-march=i386'\n else:\n march_opt = ''\n\n gnu_ver = self.get_version()\n\n if gnu_ver >= '0.5.26': # gcc 3.0\n if cpu.is_AthlonK6():\n march_opt = '-march=k6'\n elif cpu.is_AthlonK7():\n march_opt = '-march=athlon'\n\n if gnu_ver >= '3.1.1':\n if cpu.is_AthlonK6_2():\n march_opt = '-march=k6-2'\n elif cpu.is_AthlonK6_3():\n march_opt = '-march=k6-3'\n elif cpu.is_AthlonMP():\n march_opt = '-march=athlon-mp'\n # there's also: athlon-tbird, athlon-4, athlon-xp\n elif cpu.is_Nocona():\n march_opt = '-march=nocona'\n elif cpu.is_Prescott():\n march_opt = '-march=prescott'\n elif cpu.is_PentiumIV():\n march_opt = '-march=pentium4'\n elif cpu.is_PentiumIII():\n march_opt = '-march=pentium3'\n elif cpu.is_PentiumM():\n march_opt = '-march=pentium3'\n elif cpu.is_PentiumII():\n march_opt = '-march=pentium2'\n\n if gnu_ver >= '3.4':\n if cpu.is_Opteron():\n march_opt = '-march=opteron'\n elif cpu.is_Athlon64():\n march_opt = '-march=athlon64'\n\n if gnu_ver >= '3.4.4':\n if cpu.is_PentiumM():\n march_opt = '-march=pentium-m'\n\n # Note: gcc 3.2 on win32 has breakage with -march specified\n if '3.1.1' <= gnu_ver <= '3.4' and sys.platform=='win32':\n march_opt = ''\n\n if march_opt:\n opt.append(march_opt)\n\n # other CPU flags\n if gnu_ver >= '3.1.1':\n if cpu.has_mmx(): opt.append('-mmmx')\n if cpu.has_3dnow(): opt.append('-m3dnow')\n\n if gnu_ver > '3.2.2':\n if cpu.has_sse2(): opt.append('-msse2')\n if cpu.has_sse(): opt.append('-msse')\n if gnu_ver >= '3.4':\n if cpu.has_sse3(): opt.append('-msse3')\n if cpu.is_Intel():\n opt.append('-fomit-frame-pointer')\n if cpu.is_32bit():\n opt.append('-malign-double')\n return opt\n\nclass Gnu95FCompiler(GnuFCompiler):\n\n compiler_type = 'gnu95'\n version_match = simple_version_match(start='GNU Fortran 95')\n\n # 'gfortran --version' results:\n # Debian: GNU Fortran 95 (GCC 4.0.3 20051023 (prerelease) (Debian 4.0.2-3))\n # OS X: GNU Fortran 95 (GCC) 4.1.0\n # GNU Fortran 95 (GCC) 4.2.0 20060218 (experimental)\n\n for fc_exe in map(find_executable,['gfortran','f95']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-ffixed-form\",\"-fno-second-underscore\"],\n 'compiler_f90' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_fix' : [fc_exe,\"-Wall\",\"-ffixed-form\",\"-fno-second-underscore\"],\n 'linker_so' : [fc_exe,\"-Wall\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n 'linker_exe' : [fc_exe,\"-Wall\"]\n }\n module_dir_switch = '-J'\n module_include_switch = '-I'\n\n g2c = 'gfortran'\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from numpy.distutils.fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n compiler = GnuFCompiler()\n compiler.customize()\n print compiler.get_version()\n", + "methods": [ + { + "name": "get_flags_linker_so", + "long_name": "get_flags_linker_so( self )", + "filename": "gnu.py", + "nloc": 19, + "complexity": 5, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 54, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "get_libgcc_dir", + "long_name": "get_libgcc_dir( self )", + "filename": "gnu.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 81, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self )", + "filename": "gnu.py", + "nloc": 7, + "complexity": 3, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 88, + "end_line": 94, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "gnu.py", + "nloc": 18, + "complexity": 7, + "token_count": 120, + "parameters": [ + "self" + ], + "start_line": 96, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "get_flags_debug", + "long_name": "get_flags_debug( self )", + "filename": "gnu.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 118, + "end_line": 119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_flags_opt", + "long_name": "get_flags_opt( self )", + "filename": "gnu.py", + "nloc": 7, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 121, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_flags_arch", + "long_name": "get_flags_arch( self )", + "filename": "gnu.py", + "nloc": 75, + "complexity": 42, + "token_count": 436, + "parameters": [ + "self" + ], + "start_line": 131, + "end_line": 220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 90, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "get_flags_linker_so", + "long_name": "get_flags_linker_so( self )", + "filename": "gnu.py", + "nloc": 19, + "complexity": 5, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 54, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "get_libgcc_dir", + "long_name": "get_libgcc_dir( self )", + "filename": "gnu.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 81, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self )", + "filename": "gnu.py", + "nloc": 7, + "complexity": 3, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 88, + "end_line": 94, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "gnu.py", + "nloc": 16, + "complexity": 6, + "token_count": 107, + "parameters": [ + "self" + ], + "start_line": 96, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "get_flags_debug", + "long_name": "get_flags_debug( self )", + "filename": "gnu.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 118, + "end_line": 119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_flags_opt", + "long_name": "get_flags_opt( self )", + "filename": "gnu.py", + "nloc": 7, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 121, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_flags_arch", + "long_name": "get_flags_arch( self )", + "filename": "gnu.py", + "nloc": 75, + "complexity": 42, + "token_count": 436, + "parameters": [ + "self" + ], + "start_line": 131, + "end_line": 220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 90, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "gnu.py", + "nloc": 18, + "complexity": 7, + "token_count": 120, + "parameters": [ + "self" + ], + "start_line": 96, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + } + ], + "nloc": 190, + "complexity": 62, + "token_count": 1146, + "diff_parsed": { + "added": [ + " if sys.platform == 'darwin':", + " opt.append('cc_dynamic')" + ], + "deleted": [ + "# if sys.platform == 'darwin':", + "# opt.append('cc_dynamic')" + ] + } + } + ] + }, + { + "hash": "cd5f36dc87fd462bc0391a3f7e13036bf1ad3c40", + "msg": "Better version matching for Sun Fortran, and don't panic when we can't match the version number", + "author": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "committer": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "author_date": "2006-03-21T04:14:29+00:00", + "author_timezone": 0, + "committer_date": "2006-03-21T04:14:29+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "8f28c43e00c6622e6ca654be1652d5a5a77fd28b" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 3, + "insertions": 8, + "lines": 11, + "files": 2, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/distutils/ccompiler.py", + "new_path": "numpy/distutils/ccompiler.py", + "filename": "ccompiler.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -253,8 +253,9 @@ def matcher(version_string):\n if status in ok_status:\n version = matcher(output)\n if not version:\n- raise ValueError(\"compiler version not matched (%r)\" % (version,))\n- version = LooseVersion(version)\n+ log.warn(\"Couldn't match compiler version for %r\" % (output,))\n+ else:\n+ version = LooseVersion(version)\n self.version = version\n return version\n \n", + "added_lines": 3, + "deleted_lines": 2, + "source_code": "import re\nimport os\nimport sys\nimport new\n\nfrom distutils.ccompiler import *\nfrom distutils import ccompiler\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.version import LooseVersion\n\nimport log\nfrom exec_command import exec_command\nfrom misc_util import cyg2win32, is_sequence, mingw32\nfrom distutils.spawn import _nt_quote_args\n\n# hack to set compiler optimizing options. Needs to integrated with something.\nimport distutils.sysconfig\n_old_init_posix = distutils.sysconfig._init_posix\ndef _new_init_posix():\n _old_init_posix()\n distutils.sysconfig._config_vars['OPT'] = '-Wall -g -O2'\n#distutils.sysconfig._init_posix = _new_init_posix\n\n# Using customized CCompiler.spawn.\ndef CCompiler_spawn(self, cmd, display=None):\n if display is None:\n display = cmd\n if is_sequence(display):\n display = ' '.join(list(display))\n log.info(display)\n if is_sequence(cmd) and os.name == 'nt':\n cmd = _nt_quote_args(list(cmd))\n s,o = exec_command(cmd)\n if s:\n if is_sequence(cmd):\n cmd = ' '.join(list(cmd))\n print o\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\nCCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n\ndef CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):\n if output_dir is None:\n output_dir = ''\n obj_names = []\n for src_name in source_filenames:\n base, ext = os.path.splitext(os.path.normpath(src_name))\n base = os.path.splitdrive(base)[1] # Chop off the drive\n base = base[os.path.isabs(base):] # If abs, chop off leading /\n if base.startswith('..'):\n # Resolve starting relative path components, middle ones\n # (if any) have been handled by os.path.normpath above.\n i = base.rfind('..')+2\n d = base[:i]\n d = os.path.basename(os.path.abspath(d))\n base = d + base[i:]\n if ext not in self.src_extensions:\n raise UnknownFileError, \\\n \"unknown file type '%s' (from '%s')\" % (ext, src_name)\n if strip_dir:\n base = os.path.basename(base)\n obj_name = os.path.join(output_dir,base + self.obj_extension)\n obj_names.append(obj_name)\n return obj_names\n\nCCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,\n None,CCompiler)\n\ndef CCompiler_compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n # This method is effective only with Python >=2.3 distutils.\n # Any changes here should be applied also to fcompiler.compile\n # method to support pre Python 2.3 distutils.\n if not sources:\n return []\n from fcompiler import FCompiler\n if isinstance(self, FCompiler):\n display = []\n for fc in ['f77','f90','fix']:\n fcomp = getattr(self,'compiler_'+fc)\n if fcomp is None:\n continue\n display.append(\"%s(%s) options: '%s'\" % (os.path.basename(fcomp[0]),\n fc,\n ' '.join(fcomp[1:])))\n display = '\\n'.join(display)\n else:\n ccomp = self.compiler_so\n display = \"%s options: '%s'\" % (os.path.basename(ccomp[0]),\n ' '.join(ccomp[1:]))\n log.info(display)\n macros, objects, extra_postargs, pp_opts, build = \\\n self._setup_compile(output_dir, macros, include_dirs, sources,\n depends, extra_postargs)\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n display = \"compile options: '%s'\" % (' '.join(cc_args))\n if extra_postargs:\n display += \"\\nextra options: '%s'\" % (' '.join(extra_postargs))\n log.info(display)\n\n # build any sources in same order as they were originally specified\n # especially important for fortran .f90 files using modules\n if isinstance(self, FCompiler):\n objects_to_build = build.keys()\n for obj in objects:\n if obj in objects_to_build:\n src, ext = build[obj]\n if self.compiler_type=='absoft':\n obj = cyg2win32(obj)\n src = cyg2win32(src)\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n else:\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n\n # Return *all* object filenames, not just the ones we just built.\n return objects\n\nCCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)\n\ndef CCompiler_customize_cmd(self, cmd):\n \"\"\" Customize compiler using distutils command.\n \"\"\"\n log.info('customize %s using %s' % (self.__class__.__name__,\n cmd.__class__.__name__))\n if getattr(cmd,'include_dirs',None) is not None:\n self.set_include_dirs(cmd.include_dirs)\n if getattr(cmd,'define',None) is not None:\n for (name,value) in cmd.define:\n self.define_macro(name, value)\n if getattr(cmd,'undef',None) is not None:\n for macro in cmd.undef:\n self.undefine_macro(macro)\n if getattr(cmd,'libraries',None) is not None:\n self.set_libraries(self.libraries + cmd.libraries)\n if getattr(cmd,'library_dirs',None) is not None:\n self.set_library_dirs(self.library_dirs + cmd.library_dirs)\n if getattr(cmd,'rpath',None) is not None:\n self.set_runtime_library_dirs(cmd.rpath)\n if getattr(cmd,'link_objects',None) is not None:\n self.set_link_objects(cmd.link_objects)\n return\n\nCCompiler.customize_cmd = new.instancemethod(\\\n CCompiler_customize_cmd,None,CCompiler)\n\ndef _compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,repr(v)))\n lines = []\n format = '%-' + repr(mx+1) + 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef CCompiler_show_customization(self):\n if 0:\n for attrname in ['include_dirs','define','undef',\n 'libraries','library_dirs',\n 'rpath','link_objects']:\n attr = getattr(self,attrname,None)\n if not attr:\n continue\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n if log._global_log.threshold<2:\n print '*'*80\n print self.__class__\n print _compiler_to_string(self)\n print '*'*80\n\nCCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n\n\ndef CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)\n return\n\nCCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n\ndef simple_version_match(pat=r'[-.\\d]+', ignore=None, start=''):\n def matcher(self, version_string):\n pos = 0\n if start:\n m = re.match(start, version_string)\n if not m:\n return None\n pos = m.end()\n while 1:\n m = re.search(pat, version_string[pos:])\n if not m:\n return None\n if ignore and re.match(ignore, m.group(0)):\n pos = m.end()\n continue\n break\n return m.group(0)\n return matcher\n\ndef CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n try:\n version_cmd = self.version_cmd\n except AttributeError:\n return\n cmd = ' '.join(version_cmd)\n try:\n matcher = self.version_match\n except AttributeError:\n try:\n pat = self.version_pattern\n except AttributeError:\n return\n def matcher(version_string):\n m = re.match(pat, version_string)\n if not m:\n return None\n version = m.group('version')\n return version\n\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n version = matcher(output)\n if not version:\n log.warn(\"Couldn't match compiler version for %r\" % (output,))\n else:\n version = LooseVersion(version)\n self.version = version\n return version\n\nCCompiler.get_version = new.instancemethod(\\\n CCompiler_get_version,None,CCompiler)\n\ncompiler_class['intel'] = ('intelccompiler','IntelCCompiler',\n \"Intel C Compiler for 32-bit applications\")\ncompiler_class['intele'] = ('intelccompiler','IntelItaniumCCompiler',\n \"Intel C Itanium Compiler for Itanium-based applications\")\nccompiler._default_compilers = ccompiler._default_compilers \\\n + (('linux.*','intel'),('linux.*','intele'))\n\nif sys.platform == 'win32':\n compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',\n \"Mingw32 port of GNU C Compiler for Win32\"\\\n \"(for MSC built Python)\")\n if mingw32():\n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n log.info('Setting mingw32 as default compiler for nt.')\n ccompiler._default_compilers = (('nt', 'mingw32'),) \\\n + ccompiler._default_compilers\n\n\n_distutils_new_compiler = new_compiler\ndef new_compiler (plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n # Try first C compilers from numpy.distutils.\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_compiler(plat)\n (module_name, class_name, long_description) = compiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile C/C++ code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n module_name = \"numpy.distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n print msg,'in numpy.distutils, trying from distutils..'\n module_name = module_name[6:]\n try:\n __import__(module_name)\n except ImportError, msg:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n try:\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile C/C++ code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\nccompiler.new_compiler = new_compiler\n\n\n_distutils_gen_lib_options = gen_lib_options\ndef gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries):\n r = _distutils_gen_lib_options(compiler, library_dirs,\n runtime_library_dirs, libraries)\n lib_opts = []\n for i in r:\n if is_sequence(i):\n lib_opts.extend(list(i))\n else:\n lib_opts.append(i)\n return lib_opts\nccompiler.gen_lib_options = gen_lib_options\n\n\n##Fix distutils.util.split_quoted:\nimport re,string\n_wordchars_re = re.compile(r'[^\\\\\\'\\\"%s ]*' % string.whitespace)\n_squote_re = re.compile(r\"'(?:[^'\\\\]|\\\\.)*'\")\n_dquote_re = re.compile(r'\"(?:[^\"\\\\]|\\\\.)*\"')\n_has_white_re = re.compile(r'\\s')\ndef split_quoted(s):\n s = string.strip(s)\n words = []\n pos = 0\n\n while s:\n m = _wordchars_re.match(s, pos)\n end = m.end()\n if end == len(s):\n words.append(s[:end])\n break\n\n if s[end] in string.whitespace: # unescaped, unquoted whitespace: now\n words.append(s[:end]) # we definitely have a word delimiter\n s = string.lstrip(s[end:])\n pos = 0\n\n elif s[end] == '\\\\': # preserve whatever is being escaped;\n # will become part of the current word\n s = s[:end] + s[end+1:]\n pos = end+1\n\n else:\n if s[end] == \"'\": # slurp singly-quoted string\n m = _squote_re.match(s, end)\n elif s[end] == '\"': # slurp doubly-quoted string\n m = _dquote_re.match(s, end)\n else:\n raise RuntimeError, \\\n \"this can't happen (bad char '%c')\" % s[end]\n\n if m is None:\n raise ValueError, \\\n \"bad string (mismatched %s quotes?)\" % s[end]\n\n (beg, end) = m.span()\n if _has_white_re.search(s[beg+1:end-1]):\n s = s[:beg] + s[beg+1:end-1] + s[end:]\n pos = m.end() - 2\n else:\n # Keeping quotes when a quoted word does not contain\n # white-space. XXX: send a patch to distutils\n pos = m.end()\n\n if pos >= len(s):\n words.append(s)\n break\n\n return words\nccompiler.split_quoted = split_quoted\n", + "source_code_before": "import re\nimport os\nimport sys\nimport new\n\nfrom distutils.ccompiler import *\nfrom distutils import ccompiler\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.version import LooseVersion\n\nimport log\nfrom exec_command import exec_command\nfrom misc_util import cyg2win32, is_sequence, mingw32\nfrom distutils.spawn import _nt_quote_args\n\n# hack to set compiler optimizing options. Needs to integrated with something.\nimport distutils.sysconfig\n_old_init_posix = distutils.sysconfig._init_posix\ndef _new_init_posix():\n _old_init_posix()\n distutils.sysconfig._config_vars['OPT'] = '-Wall -g -O2'\n#distutils.sysconfig._init_posix = _new_init_posix\n\n# Using customized CCompiler.spawn.\ndef CCompiler_spawn(self, cmd, display=None):\n if display is None:\n display = cmd\n if is_sequence(display):\n display = ' '.join(list(display))\n log.info(display)\n if is_sequence(cmd) and os.name == 'nt':\n cmd = _nt_quote_args(list(cmd))\n s,o = exec_command(cmd)\n if s:\n if is_sequence(cmd):\n cmd = ' '.join(list(cmd))\n print o\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\nCCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n\ndef CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):\n if output_dir is None:\n output_dir = ''\n obj_names = []\n for src_name in source_filenames:\n base, ext = os.path.splitext(os.path.normpath(src_name))\n base = os.path.splitdrive(base)[1] # Chop off the drive\n base = base[os.path.isabs(base):] # If abs, chop off leading /\n if base.startswith('..'):\n # Resolve starting relative path components, middle ones\n # (if any) have been handled by os.path.normpath above.\n i = base.rfind('..')+2\n d = base[:i]\n d = os.path.basename(os.path.abspath(d))\n base = d + base[i:]\n if ext not in self.src_extensions:\n raise UnknownFileError, \\\n \"unknown file type '%s' (from '%s')\" % (ext, src_name)\n if strip_dir:\n base = os.path.basename(base)\n obj_name = os.path.join(output_dir,base + self.obj_extension)\n obj_names.append(obj_name)\n return obj_names\n\nCCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,\n None,CCompiler)\n\ndef CCompiler_compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n # This method is effective only with Python >=2.3 distutils.\n # Any changes here should be applied also to fcompiler.compile\n # method to support pre Python 2.3 distutils.\n if not sources:\n return []\n from fcompiler import FCompiler\n if isinstance(self, FCompiler):\n display = []\n for fc in ['f77','f90','fix']:\n fcomp = getattr(self,'compiler_'+fc)\n if fcomp is None:\n continue\n display.append(\"%s(%s) options: '%s'\" % (os.path.basename(fcomp[0]),\n fc,\n ' '.join(fcomp[1:])))\n display = '\\n'.join(display)\n else:\n ccomp = self.compiler_so\n display = \"%s options: '%s'\" % (os.path.basename(ccomp[0]),\n ' '.join(ccomp[1:]))\n log.info(display)\n macros, objects, extra_postargs, pp_opts, build = \\\n self._setup_compile(output_dir, macros, include_dirs, sources,\n depends, extra_postargs)\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n display = \"compile options: '%s'\" % (' '.join(cc_args))\n if extra_postargs:\n display += \"\\nextra options: '%s'\" % (' '.join(extra_postargs))\n log.info(display)\n\n # build any sources in same order as they were originally specified\n # especially important for fortran .f90 files using modules\n if isinstance(self, FCompiler):\n objects_to_build = build.keys()\n for obj in objects:\n if obj in objects_to_build:\n src, ext = build[obj]\n if self.compiler_type=='absoft':\n obj = cyg2win32(obj)\n src = cyg2win32(src)\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n else:\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n\n # Return *all* object filenames, not just the ones we just built.\n return objects\n\nCCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)\n\ndef CCompiler_customize_cmd(self, cmd):\n \"\"\" Customize compiler using distutils command.\n \"\"\"\n log.info('customize %s using %s' % (self.__class__.__name__,\n cmd.__class__.__name__))\n if getattr(cmd,'include_dirs',None) is not None:\n self.set_include_dirs(cmd.include_dirs)\n if getattr(cmd,'define',None) is not None:\n for (name,value) in cmd.define:\n self.define_macro(name, value)\n if getattr(cmd,'undef',None) is not None:\n for macro in cmd.undef:\n self.undefine_macro(macro)\n if getattr(cmd,'libraries',None) is not None:\n self.set_libraries(self.libraries + cmd.libraries)\n if getattr(cmd,'library_dirs',None) is not None:\n self.set_library_dirs(self.library_dirs + cmd.library_dirs)\n if getattr(cmd,'rpath',None) is not None:\n self.set_runtime_library_dirs(cmd.rpath)\n if getattr(cmd,'link_objects',None) is not None:\n self.set_link_objects(cmd.link_objects)\n return\n\nCCompiler.customize_cmd = new.instancemethod(\\\n CCompiler_customize_cmd,None,CCompiler)\n\ndef _compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,repr(v)))\n lines = []\n format = '%-' + repr(mx+1) + 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef CCompiler_show_customization(self):\n if 0:\n for attrname in ['include_dirs','define','undef',\n 'libraries','library_dirs',\n 'rpath','link_objects']:\n attr = getattr(self,attrname,None)\n if not attr:\n continue\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n if log._global_log.threshold<2:\n print '*'*80\n print self.__class__\n print _compiler_to_string(self)\n print '*'*80\n\nCCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n\n\ndef CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)\n return\n\nCCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n\ndef simple_version_match(pat=r'[-.\\d]+', ignore=None, start=''):\n def matcher(self, version_string):\n pos = 0\n if start:\n m = re.match(start, version_string)\n if not m:\n return None\n pos = m.end()\n while 1:\n m = re.search(pat, version_string[pos:])\n if not m:\n return None\n if ignore and re.match(ignore, m.group(0)):\n pos = m.end()\n continue\n break\n return m.group(0)\n return matcher\n\ndef CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n try:\n version_cmd = self.version_cmd\n except AttributeError:\n return\n cmd = ' '.join(version_cmd)\n try:\n matcher = self.version_match\n except AttributeError:\n try:\n pat = self.version_pattern\n except AttributeError:\n return\n def matcher(version_string):\n m = re.match(pat, version_string)\n if not m:\n return None\n version = m.group('version')\n return version\n\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n version = matcher(output)\n if not version:\n raise ValueError(\"compiler version not matched (%r)\" % (version,))\n version = LooseVersion(version)\n self.version = version\n return version\n\nCCompiler.get_version = new.instancemethod(\\\n CCompiler_get_version,None,CCompiler)\n\ncompiler_class['intel'] = ('intelccompiler','IntelCCompiler',\n \"Intel C Compiler for 32-bit applications\")\ncompiler_class['intele'] = ('intelccompiler','IntelItaniumCCompiler',\n \"Intel C Itanium Compiler for Itanium-based applications\")\nccompiler._default_compilers = ccompiler._default_compilers \\\n + (('linux.*','intel'),('linux.*','intele'))\n\nif sys.platform == 'win32':\n compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',\n \"Mingw32 port of GNU C Compiler for Win32\"\\\n \"(for MSC built Python)\")\n if mingw32():\n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n log.info('Setting mingw32 as default compiler for nt.')\n ccompiler._default_compilers = (('nt', 'mingw32'),) \\\n + ccompiler._default_compilers\n\n\n_distutils_new_compiler = new_compiler\ndef new_compiler (plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n # Try first C compilers from numpy.distutils.\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_compiler(plat)\n (module_name, class_name, long_description) = compiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile C/C++ code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n module_name = \"numpy.distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n print msg,'in numpy.distutils, trying from distutils..'\n module_name = module_name[6:]\n try:\n __import__(module_name)\n except ImportError, msg:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n try:\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile C/C++ code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\nccompiler.new_compiler = new_compiler\n\n\n_distutils_gen_lib_options = gen_lib_options\ndef gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries):\n r = _distutils_gen_lib_options(compiler, library_dirs,\n runtime_library_dirs, libraries)\n lib_opts = []\n for i in r:\n if is_sequence(i):\n lib_opts.extend(list(i))\n else:\n lib_opts.append(i)\n return lib_opts\nccompiler.gen_lib_options = gen_lib_options\n\n\n##Fix distutils.util.split_quoted:\nimport re,string\n_wordchars_re = re.compile(r'[^\\\\\\'\\\"%s ]*' % string.whitespace)\n_squote_re = re.compile(r\"'(?:[^'\\\\]|\\\\.)*'\")\n_dquote_re = re.compile(r'\"(?:[^\"\\\\]|\\\\.)*\"')\n_has_white_re = re.compile(r'\\s')\ndef split_quoted(s):\n s = string.strip(s)\n words = []\n pos = 0\n\n while s:\n m = _wordchars_re.match(s, pos)\n end = m.end()\n if end == len(s):\n words.append(s[:end])\n break\n\n if s[end] in string.whitespace: # unescaped, unquoted whitespace: now\n words.append(s[:end]) # we definitely have a word delimiter\n s = string.lstrip(s[end:])\n pos = 0\n\n elif s[end] == '\\\\': # preserve whatever is being escaped;\n # will become part of the current word\n s = s[:end] + s[end+1:]\n pos = end+1\n\n else:\n if s[end] == \"'\": # slurp singly-quoted string\n m = _squote_re.match(s, end)\n elif s[end] == '\"': # slurp doubly-quoted string\n m = _dquote_re.match(s, end)\n else:\n raise RuntimeError, \\\n \"this can't happen (bad char '%c')\" % s[end]\n\n if m is None:\n raise ValueError, \\\n \"bad string (mismatched %s quotes?)\" % s[end]\n\n (beg, end) = m.span()\n if _has_white_re.search(s[beg+1:end-1]):\n s = s[:beg] + s[beg+1:end-1] + s[end:]\n pos = m.end() - 2\n else:\n # Keeping quotes when a quoted word does not contain\n # white-space. XXX: send a patch to distutils\n pos = m.end()\n\n if pos >= len(s):\n words.append(s)\n break\n\n return words\nccompiler.split_quoted = split_quoted\n", + "methods": [ + { + "name": "_new_init_posix", + "long_name": "_new_init_posix( )", + "filename": "ccompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 17, + "parameters": [], + "start_line": 19, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_spawn", + "long_name": "CCompiler_spawn( self , cmd , display = None )", + "filename": "ccompiler.py", + "nloc": 15, + "complexity": 7, + "token_count": 104, + "parameters": [ + "self", + "cmd", + "display" + ], + "start_line": 25, + "end_line": 39, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_object_filenames", + "long_name": "CCompiler_object_filenames( self , source_filenames , strip_dir = 0 , output_dir = '' )", + "filename": "ccompiler.py", + "nloc": 21, + "complexity": 6, + "token_count": 185, + "parameters": [ + "self", + "source_filenames", + "strip_dir", + "output_dir" + ], + "start_line": 42, + "end_line": 64, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_compile", + "long_name": "CCompiler_compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", + "filename": "ccompiler.py", + "nloc": 42, + "complexity": 11, + "token_count": 342, + "parameters": [ + "self", + "sources", + "output_dir", + "macros", + "include_dirs", + "debug", + "extra_preargs", + "extra_postargs", + "depends" + ], + "start_line": 69, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_customize_cmd", + "long_name": "CCompiler_customize_cmd( self , cmd )", + "filename": "ccompiler.py", + "nloc": 20, + "complexity": 10, + "token_count": 200, + "parameters": [ + "self", + "cmd" + ], + "start_line": 122, + "end_line": 143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "_compiler_to_string", + "long_name": "_compiler_to_string( compiler )", + "filename": "ccompiler.py", + "nloc": 19, + "complexity": 6, + "token_count": 139, + "parameters": [ + "compiler" + ], + "start_line": 148, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_show_customization", + "long_name": "CCompiler_show_customization( self )", + "filename": "ccompiler.py", + "nloc": 16, + "complexity": 6, + "token_count": 90, + "parameters": [ + "self" + ], + "start_line": 168, + "end_line": 183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_customize", + "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", + "filename": "ccompiler.py", + "nloc": 15, + "complexity": 6, + "token_count": 144, + "parameters": [ + "self", + "dist", + "need_cxx" + ], + "start_line": 189, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "simple_version_match.matcher", + "long_name": "simple_version_match.matcher( self , version_string )", + "filename": "ccompiler.py", + "nloc": 16, + "complexity": 7, + "token_count": 92, + "parameters": [ + "self", + "version_string" + ], + "start_line": 210, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "simple_version_match", + "long_name": "simple_version_match( pat = r '[-.\\d]+' , ignore = None , start = '' )", + "filename": "ccompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "pat", + "ignore", + "start" + ], + "start_line": 209, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_get_version.matcher", + "long_name": "CCompiler_get_version.matcher( version_string )", + "filename": "ccompiler.py", + "nloc": 6, + "complexity": 2, + "token_count": 31, + "parameters": [ + "version_string" + ], + "start_line": 244, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 2 + }, + { + "name": "CCompiler_get_version", + "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", + "filename": "ccompiler.py", + "nloc": 26, + "complexity": 8, + "token_count": 129, + "parameters": [ + "self", + "force", + "ok_status" + ], + "start_line": 228, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "new_compiler", + "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", + "filename": "ccompiler.py", + "nloc": 38, + "complexity": 8, + "token_count": 188, + "parameters": [ + "plat", + "compiler", + "verbose", + "dry_run", + "force" + ], + "start_line": 285, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "gen_lib_options", + "long_name": "gen_lib_options( compiler , library_dirs , runtime_library_dirs , libraries )", + "filename": "ccompiler.py", + "nloc": 10, + "complexity": 3, + "token_count": 57, + "parameters": [ + "compiler", + "library_dirs", + "runtime_library_dirs", + "libraries" + ], + "start_line": 329, + "end_line": 338, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "split_quoted", + "long_name": "split_quoted( s )", + "filename": "ccompiler.py", + "nloc": 38, + "complexity": 10, + "token_count": 274, + "parameters": [ + "s" + ], + "start_line": 348, + "end_line": 396, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 49, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "_new_init_posix", + "long_name": "_new_init_posix( )", + "filename": "ccompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 17, + "parameters": [], + "start_line": 19, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_spawn", + "long_name": "CCompiler_spawn( self , cmd , display = None )", + "filename": "ccompiler.py", + "nloc": 15, + "complexity": 7, + "token_count": 104, + "parameters": [ + "self", + "cmd", + "display" + ], + "start_line": 25, + "end_line": 39, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_object_filenames", + "long_name": "CCompiler_object_filenames( self , source_filenames , strip_dir = 0 , output_dir = '' )", + "filename": "ccompiler.py", + "nloc": 21, + "complexity": 6, + "token_count": 185, + "parameters": [ + "self", + "source_filenames", + "strip_dir", + "output_dir" + ], + "start_line": 42, + "end_line": 64, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_compile", + "long_name": "CCompiler_compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", + "filename": "ccompiler.py", + "nloc": 42, + "complexity": 11, + "token_count": 342, + "parameters": [ + "self", + "sources", + "output_dir", + "macros", + "include_dirs", + "debug", + "extra_preargs", + "extra_postargs", + "depends" + ], + "start_line": 69, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_customize_cmd", + "long_name": "CCompiler_customize_cmd( self , cmd )", + "filename": "ccompiler.py", + "nloc": 20, + "complexity": 10, + "token_count": 200, + "parameters": [ + "self", + "cmd" + ], + "start_line": 122, + "end_line": 143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "_compiler_to_string", + "long_name": "_compiler_to_string( compiler )", + "filename": "ccompiler.py", + "nloc": 19, + "complexity": 6, + "token_count": 139, + "parameters": [ + "compiler" + ], + "start_line": 148, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_show_customization", + "long_name": "CCompiler_show_customization( self )", + "filename": "ccompiler.py", + "nloc": 16, + "complexity": 6, + "token_count": 90, + "parameters": [ + "self" + ], + "start_line": 168, + "end_line": 183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_customize", + "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", + "filename": "ccompiler.py", + "nloc": 15, + "complexity": 6, + "token_count": 144, + "parameters": [ + "self", + "dist", + "need_cxx" + ], + "start_line": 189, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "simple_version_match.matcher", + "long_name": "simple_version_match.matcher( self , version_string )", + "filename": "ccompiler.py", + "nloc": 16, + "complexity": 7, + "token_count": 92, + "parameters": [ + "self", + "version_string" + ], + "start_line": 210, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "simple_version_match", + "long_name": "simple_version_match( pat = r '[-.\\d]+' , ignore = None , start = '' )", + "filename": "ccompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "pat", + "ignore", + "start" + ], + "start_line": 209, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "CCompiler_get_version.matcher", + "long_name": "CCompiler_get_version.matcher( version_string )", + "filename": "ccompiler.py", + "nloc": 6, + "complexity": 2, + "token_count": 31, + "parameters": [ + "version_string" + ], + "start_line": 244, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 2 + }, + { + "name": "CCompiler_get_version", + "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", + "filename": "ccompiler.py", + "nloc": 25, + "complexity": 8, + "token_count": 126, + "parameters": [ + "self", + "force", + "ok_status" + ], + "start_line": 228, + "end_line": 259, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "new_compiler", + "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", + "filename": "ccompiler.py", + "nloc": 38, + "complexity": 8, + "token_count": 188, + "parameters": [ + "plat", + "compiler", + "verbose", + "dry_run", + "force" + ], + "start_line": 284, + "end_line": 322, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "gen_lib_options", + "long_name": "gen_lib_options( compiler , library_dirs , runtime_library_dirs , libraries )", + "filename": "ccompiler.py", + "nloc": 10, + "complexity": 3, + "token_count": 57, + "parameters": [ + "compiler", + "library_dirs", + "runtime_library_dirs", + "libraries" + ], + "start_line": 328, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "split_quoted", + "long_name": "split_quoted( s )", + "filename": "ccompiler.py", + "nloc": 38, + "complexity": 10, + "token_count": 274, + "parameters": [ + "s" + ], + "start_line": 347, + "end_line": 395, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 49, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "CCompiler_get_version", + "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", + "filename": "ccompiler.py", + "nloc": 26, + "complexity": 8, + "token_count": 129, + "parameters": [ + "self", + "force", + "ok_status" + ], + "start_line": 228, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + } + ], + "nloc": 336, + "complexity": 92, + "token_count": 2346, + "diff_parsed": { + "added": [ + " log.warn(\"Couldn't match compiler version for %r\" % (output,))", + " else:", + " version = LooseVersion(version)" + ], + "deleted": [ + " raise ValueError(\"compiler version not matched (%r)\" % (version,))", + " version = LooseVersion(version)" + ] + } + }, + { + "old_path": "numpy/distutils/fcompiler/sun.py", + "new_path": "numpy/distutils/fcompiler/sun.py", + "filename": "sun.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -2,12 +2,16 @@\n import sys\n \n from numpy.distutils.cpuinfo import cpu\n+from numpy.distutils.ccompiler import simple_version_match\n from numpy.distutils.fcompiler import FCompiler\n \n class SunFCompiler(FCompiler):\n \n compiler_type = 'sun'\n- version_pattern = r'(f90|f95): (Sun|Forte Developer 7|WorkShop 6 update \\d+) Fortran 95 (?P[^\\s]+).*'\n+ # ex:\n+ # f90: Sun WorkShop 6 update 2 Fortran 95 6.2 Patch 111690-10 2003/08/28\n+ version_match = simple_version_match(\n+ start=r'f9[05]: (Sun|Forte|WorkShop).*Fortran 95')\n \n executables = {\n 'version_cmd' : [\"f90\", \"-V\"],\n", + "added_lines": 5, + "deleted_lines": 1, + "source_code": "import os\nimport sys\n\nfrom numpy.distutils.cpuinfo import cpu\nfrom numpy.distutils.ccompiler import simple_version_match\nfrom numpy.distutils.fcompiler import FCompiler\n\nclass SunFCompiler(FCompiler):\n\n compiler_type = 'sun'\n # ex:\n # f90: Sun WorkShop 6 update 2 Fortran 95 6.2 Patch 111690-10 2003/08/28\n version_match = simple_version_match(\n start=r'f9[05]: (Sun|Forte|WorkShop).*Fortran 95')\n\n executables = {\n 'version_cmd' : [\"f90\", \"-V\"],\n 'compiler_f77' : [\"f90\"],\n 'compiler_fix' : [\"f90\", \"-fixed\"],\n 'compiler_f90' : [\"f90\"],\n 'linker_so' : [\"f90\",\"-Bdynamic\",\"-G\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n module_dir_switch = '-moddir='\n module_include_switch = '-M'\n pic_flags = ['-xcode=pic32']\n\n def get_flags_f77(self):\n ret = [\"-ftrap=%none\"]\n if (self.get_version() or '') >= '7':\n ret.append(\"-f77\")\n else:\n ret.append(\"-fixed\")\n return ret\n def get_opt(self):\n return ['-fast','-dalign']\n def get_arch(self):\n return ['-xtarget=generic']\n def get_libraries(self):\n opt = []\n opt.extend(['fsu','sunmath','mvec','f77compat'])\n return opt\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from numpy.distutils.fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='sun')\n compiler.customize()\n print compiler.get_version()\n", + "source_code_before": "import os\nimport sys\n\nfrom numpy.distutils.cpuinfo import cpu\nfrom numpy.distutils.fcompiler import FCompiler\n\nclass SunFCompiler(FCompiler):\n\n compiler_type = 'sun'\n version_pattern = r'(f90|f95): (Sun|Forte Developer 7|WorkShop 6 update \\d+) Fortran 95 (?P[^\\s]+).*'\n\n executables = {\n 'version_cmd' : [\"f90\", \"-V\"],\n 'compiler_f77' : [\"f90\"],\n 'compiler_fix' : [\"f90\", \"-fixed\"],\n 'compiler_f90' : [\"f90\"],\n 'linker_so' : [\"f90\",\"-Bdynamic\",\"-G\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n module_dir_switch = '-moddir='\n module_include_switch = '-M'\n pic_flags = ['-xcode=pic32']\n\n def get_flags_f77(self):\n ret = [\"-ftrap=%none\"]\n if (self.get_version() or '') >= '7':\n ret.append(\"-f77\")\n else:\n ret.append(\"-fixed\")\n return ret\n def get_opt(self):\n return ['-fast','-dalign']\n def get_arch(self):\n return ['-xtarget=generic']\n def get_libraries(self):\n opt = []\n opt.extend(['fsu','sunmath','mvec','f77compat'])\n return opt\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from numpy.distutils.fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='sun')\n compiler.customize()\n print compiler.get_version()\n", + "methods": [ + { + "name": "get_flags_f77", + "long_name": "get_flags_f77( self )", + "filename": "sun.py", + "nloc": 7, + "complexity": 3, + "token_count": 39, + "parameters": [ + "self" + ], + "start_line": 29, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "sun.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 36, + "end_line": 37, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_arch", + "long_name": "get_arch( self )", + "filename": "sun.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 38, + "end_line": 39, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "sun.py", + "nloc": 4, + "complexity": 1, + "token_count": 25, + "parameters": [ + "self" + ], + "start_line": 40, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "get_flags_f77", + "long_name": "get_flags_f77( self )", + "filename": "sun.py", + "nloc": 7, + "complexity": 3, + "token_count": 39, + "parameters": [ + "self" + ], + "start_line": 25, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "sun.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 32, + "end_line": 33, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_arch", + "long_name": "get_arch( self )", + "filename": "sun.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "sun.py", + "nloc": 4, + "complexity": 1, + "token_count": 25, + "parameters": [ + "self" + ], + "start_line": 36, + "end_line": 39, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + } + ], + "changed_methods": [], + "nloc": 43, + "complexity": 6, + "token_count": 242, + "diff_parsed": { + "added": [ + "from numpy.distutils.ccompiler import simple_version_match", + " # ex:", + " # f90: Sun WorkShop 6 update 2 Fortran 95 6.2 Patch 111690-10 2003/08/28", + " version_match = simple_version_match(", + " start=r'f9[05]: (Sun|Forte|WorkShop).*Fortran 95')" + ], + "deleted": [ + " version_pattern = r'(f90|f95): (Sun|Forte Developer 7|WorkShop 6 update \\d+) Fortran 95 (?P[^\\s]+).*'" + ] + } + } + ] + }, + { + "hash": "cdbcee59fbe407dcfa3a81fc18f95eca4e8ec6c4", + "msg": "Fix reshape to always interpret as C-contiguous unless fortran=True is given or fortran=None and array is already fortran array.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-03-21T05:21:43+00:00", + "author_timezone": 0, + "committer_date": "2006-03-21T05:21:43+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "cd5f36dc87fd462bc0391a3f7e13036bf1ad3c40" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpo4zn5o3l/repo_copy", + "deletions": 112, + "insertions": 185, + "lines": 297, + "files": 9, + "dmm_unit_size": 0.2978723404255319, + "dmm_unit_complexity": 0.3404255319148936, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/core/code_generators/generate_array_api.py", + "new_path": "numpy/core/code_generators/generate_array_api.py", + "filename": "generate_array_api.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -17,6 +17,7 @@\n \tBool obval;\n } PyBoolScalarObject;\n \n+static unsigned int PyArray_GetNDArrayCVersion (void);\n static PyTypeObject PyBigArray_Type;\n static PyTypeObject PyArray_Type;\n static PyTypeObject PyArrayDescr_Type;\n@@ -46,15 +47,16 @@\n #endif\n #endif\n \n-#define PyBigArray_Type (*(PyTypeObject *)PyArray_API[0])\n-#define PyArray_Type (*(PyTypeObject *)PyArray_API[1])\n-#define PyArrayDescr_Type (*(PyTypeObject *)PyArray_API[2])\n-#define PyArrayFlags_Type (*(PyTypeObject *)PyArray_API[3])\n-#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[4])\n-#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[5])\n-#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[6])\n-#define PyBoolArrType_Type (*(PyTypeObject *)PyArray_API[7])\n-#define _PyArrayScalar_BoolValues (*(PyObject **)PyArray_API[8])\n+#define PyArray_GetNDArrayCVersion (*(unsigned int (*)(void)) PyArray_API[0])\n+#define PyBigArray_Type (*(PyTypeObject *)PyArray_API[1])\n+#define PyArray_Type (*(PyTypeObject *)PyArray_API[2])\n+#define PyArrayDescr_Type (*(PyTypeObject *)PyArray_API[3])\n+#define PyArrayFlags_Type (*(PyTypeObject *)PyArray_API[4])\n+#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[5])\n+#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[6])\n+#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[7])\n+#define PyBoolArrType_Type (*(PyTypeObject *)PyArray_API[8])\n+#define _PyArrayScalar_BoolValues (*(PyObject **)PyArray_API[9])\n \n %s\n \n@@ -94,6 +96,7 @@\n */\n \n void *PyArray_API[] = {\n+ (void *) PyArray_GetNDArrayCVersion,\n (void *) &PyBigArray_Type,\n (void *) &PyArray_Type,\n (void *) &PyArrayDescr_Type,\n@@ -114,7 +117,7 @@ def generate_api(output_dir):\n 'multiarray_api_order.txt')\n # API fixes for __arrayobject_api.h\n \n- fixed = 9\n+ fixed = 10\n numtypes = len(types) + fixed\n numobject = len(objectapi_list) + numtypes\n nummulti = len(multiapi_list)\n", + "added_lines": 13, + "deleted_lines": 10, + "source_code": "import os\nimport genapi\n\ntypes = ['Generic','Number','Integer','SignedInteger','UnsignedInteger',\n 'Inexact',\n 'Floating', 'ComplexFloating', 'Flexible', 'Character',\n 'Byte','Short','Int', 'Long', 'LongLong', 'UByte', 'UShort',\n 'UInt', 'ULong', 'ULongLong', 'Float', 'Double', 'LongDouble',\n 'CFloat', 'CDouble', 'CLongDouble', 'Object', 'String', 'Unicode',\n 'Void']\n\nh_template = r\"\"\"\n#ifdef _MULTIARRAYMODULE\n\ntypedef struct {\n\tPyObject_HEAD\n\tBool obval;\n} PyBoolScalarObject;\n\nstatic unsigned int PyArray_GetNDArrayCVersion (void);\nstatic PyTypeObject PyBigArray_Type;\nstatic PyTypeObject PyArray_Type;\nstatic PyTypeObject PyArrayDescr_Type;\nstatic PyTypeObject PyArrayFlags_Type;\nstatic PyTypeObject PyArrayIter_Type;\nstatic PyTypeObject PyArrayMapIter_Type;\nstatic PyTypeObject PyArrayMultiIter_Type;\nstatic int PyArray_NUMUSERTYPES=0;\nstatic PyTypeObject PyBoolArrType_Type;\nstatic PyBoolScalarObject _PyArrayScalar_BoolValues[2];\n\n%s\n\n#else\n\n#if defined(PY_ARRAY_UNIQUE_SYMBOL)\n#define PyArray_API PY_ARRAY_UNIQUE_SYMBOL\n#endif\n\n#if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)\nextern void **PyArray_API;\n#else\n#if defined(PY_ARRAY_UNIQUE_SYMBOL)\nvoid **PyArray_API;\n#else\nstatic void **PyArray_API=NULL;\n#endif\n#endif\n\n#define PyArray_GetNDArrayCVersion (*(unsigned int (*)(void)) PyArray_API[0])\n#define PyBigArray_Type (*(PyTypeObject *)PyArray_API[1])\n#define PyArray_Type (*(PyTypeObject *)PyArray_API[2])\n#define PyArrayDescr_Type (*(PyTypeObject *)PyArray_API[3])\n#define PyArrayFlags_Type (*(PyTypeObject *)PyArray_API[4])\n#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[5])\n#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[6])\n#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[7])\n#define PyBoolArrType_Type (*(PyTypeObject *)PyArray_API[8])\n#define _PyArrayScalar_BoolValues (*(PyObject **)PyArray_API[9])\n\n%s\n\n#if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)\nstatic int\nimport_array(void)\n{\n PyObject *numpy = PyImport_ImportModule(\"numpy.core.multiarray\");\n PyObject *c_api = NULL;\n if (numpy == NULL) return -1;\n c_api = PyObject_GetAttrString(numpy, \"_ARRAY_API\");\n if (c_api == NULL) {Py_DECREF(numpy); return -1;}\n if (PyCObject_Check(c_api)) {\n PyArray_API = (void **)PyCObject_AsVoidPtr(c_api);\n }\n Py_DECREF(c_api);\n Py_DECREF(numpy);\n if (PyArray_API == NULL) return -1;\n /* Perform runtime check of C API version */\n if (NDARRAY_VERSION != PyArray_GetNDArrayCVersion()) {\n PyErr_Format(PyExc_RuntimeError, \"module compiled against \"\\\n \"version %%x of C-API but this version of numpy is %%x\", \\\n (int) NDARRAY_VERSION, (int) PyArray_GetNDArrayCVersion());\n return -1;\n }\n return 0;\n}\n#endif\n\n#endif\n\"\"\"\n\n\nc_template = r\"\"\"\n/* These pointers will be stored in the C-object for use in other\n extension modules\n*/\n\nvoid *PyArray_API[] = {\n (void *) PyArray_GetNDArrayCVersion,\n (void *) &PyBigArray_Type,\n (void *) &PyArray_Type,\n (void *) &PyArrayDescr_Type,\n (void *) &PyArrayFlags_Type,\n (void *) &PyArrayIter_Type,\n (void *) &PyArrayMultiIter_Type,\n (int *) &PyArray_NUMUSERTYPES,\n (void *) &PyBoolArrType_Type,\n (void *) &_PyArrayScalar_BoolValues,\n%s\n};\n\"\"\"\n\ndef generate_api(output_dir):\n objectapi_list = genapi.get_api_functions('OBJECT_API',\n 'array_api_order.txt')\n multiapi_list = genapi.get_api_functions('MULTIARRAY_API',\n 'multiarray_api_order.txt')\n # API fixes for __arrayobject_api.h\n\n fixed = 10\n numtypes = len(types) + fixed\n numobject = len(objectapi_list) + numtypes\n nummulti = len(multiapi_list)\n numtotal = numobject + nummulti\n\n module_list = []\n extension_list = []\n init_list = []\n\n # setup types\n for k, atype in enumerate(types):\n num = fixed + k\n astr = \" (void *) &Py%sArrType_Type,\" % types[k]\n init_list.append(astr)\n astr = \"static PyTypeObject Py%sArrType_Type;\" % types[k]\n module_list.append(astr)\n astr = \"#define Py%sArrType_Type (*(PyTypeObject *)PyArray_API[%d])\" % \\\n (types[k], num)\n extension_list.append(astr)\n\n #setup object API\n genapi.add_api_list(numtypes, 'PyArray_API', objectapi_list,\n module_list, extension_list, init_list)\n\n # setup multiarray module API\n genapi.add_api_list(numobject, 'PyArray_API', multiapi_list,\n module_list, extension_list, init_list)\n\n\n # Write to header\n fid = open(os.path.join(output_dir, '__multiarray_api.h'),'w')\n s = h_template % ('\\n'.join(module_list), '\\n'.join(extension_list))\n fid.write(s)\n fid.close()\n\n # Write to c-code\n fid = open(os.path.join(output_dir,'__multiarray_api.c'),'w')\n s = c_template % '\\n'.join(init_list)\n fid.write(s)\n fid.close()\n", + "source_code_before": "import os\nimport genapi\n\ntypes = ['Generic','Number','Integer','SignedInteger','UnsignedInteger',\n 'Inexact',\n 'Floating', 'ComplexFloating', 'Flexible', 'Character',\n 'Byte','Short','Int', 'Long', 'LongLong', 'UByte', 'UShort',\n 'UInt', 'ULong', 'ULongLong', 'Float', 'Double', 'LongDouble',\n 'CFloat', 'CDouble', 'CLongDouble', 'Object', 'String', 'Unicode',\n 'Void']\n\nh_template = r\"\"\"\n#ifdef _MULTIARRAYMODULE\n\ntypedef struct {\n\tPyObject_HEAD\n\tBool obval;\n} PyBoolScalarObject;\n\nstatic PyTypeObject PyBigArray_Type;\nstatic PyTypeObject PyArray_Type;\nstatic PyTypeObject PyArrayDescr_Type;\nstatic PyTypeObject PyArrayFlags_Type;\nstatic PyTypeObject PyArrayIter_Type;\nstatic PyTypeObject PyArrayMapIter_Type;\nstatic PyTypeObject PyArrayMultiIter_Type;\nstatic int PyArray_NUMUSERTYPES=0;\nstatic PyTypeObject PyBoolArrType_Type;\nstatic PyBoolScalarObject _PyArrayScalar_BoolValues[2];\n\n%s\n\n#else\n\n#if defined(PY_ARRAY_UNIQUE_SYMBOL)\n#define PyArray_API PY_ARRAY_UNIQUE_SYMBOL\n#endif\n\n#if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)\nextern void **PyArray_API;\n#else\n#if defined(PY_ARRAY_UNIQUE_SYMBOL)\nvoid **PyArray_API;\n#else\nstatic void **PyArray_API=NULL;\n#endif\n#endif\n\n#define PyBigArray_Type (*(PyTypeObject *)PyArray_API[0])\n#define PyArray_Type (*(PyTypeObject *)PyArray_API[1])\n#define PyArrayDescr_Type (*(PyTypeObject *)PyArray_API[2])\n#define PyArrayFlags_Type (*(PyTypeObject *)PyArray_API[3])\n#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[4])\n#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[5])\n#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[6])\n#define PyBoolArrType_Type (*(PyTypeObject *)PyArray_API[7])\n#define _PyArrayScalar_BoolValues (*(PyObject **)PyArray_API[8])\n\n%s\n\n#if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)\nstatic int\nimport_array(void)\n{\n PyObject *numpy = PyImport_ImportModule(\"numpy.core.multiarray\");\n PyObject *c_api = NULL;\n if (numpy == NULL) return -1;\n c_api = PyObject_GetAttrString(numpy, \"_ARRAY_API\");\n if (c_api == NULL) {Py_DECREF(numpy); return -1;}\n if (PyCObject_Check(c_api)) {\n PyArray_API = (void **)PyCObject_AsVoidPtr(c_api);\n }\n Py_DECREF(c_api);\n Py_DECREF(numpy);\n if (PyArray_API == NULL) return -1;\n /* Perform runtime check of C API version */\n if (NDARRAY_VERSION != PyArray_GetNDArrayCVersion()) {\n PyErr_Format(PyExc_RuntimeError, \"module compiled against \"\\\n \"version %%x of C-API but this version of numpy is %%x\", \\\n (int) NDARRAY_VERSION, (int) PyArray_GetNDArrayCVersion());\n return -1;\n }\n return 0;\n}\n#endif\n\n#endif\n\"\"\"\n\n\nc_template = r\"\"\"\n/* These pointers will be stored in the C-object for use in other\n extension modules\n*/\n\nvoid *PyArray_API[] = {\n (void *) &PyBigArray_Type,\n (void *) &PyArray_Type,\n (void *) &PyArrayDescr_Type,\n (void *) &PyArrayFlags_Type,\n (void *) &PyArrayIter_Type,\n (void *) &PyArrayMultiIter_Type,\n (int *) &PyArray_NUMUSERTYPES,\n (void *) &PyBoolArrType_Type,\n (void *) &_PyArrayScalar_BoolValues,\n%s\n};\n\"\"\"\n\ndef generate_api(output_dir):\n objectapi_list = genapi.get_api_functions('OBJECT_API',\n 'array_api_order.txt')\n multiapi_list = genapi.get_api_functions('MULTIARRAY_API',\n 'multiarray_api_order.txt')\n # API fixes for __arrayobject_api.h\n\n fixed = 9\n numtypes = len(types) + fixed\n numobject = len(objectapi_list) + numtypes\n nummulti = len(multiapi_list)\n numtotal = numobject + nummulti\n\n module_list = []\n extension_list = []\n init_list = []\n\n # setup types\n for k, atype in enumerate(types):\n num = fixed + k\n astr = \" (void *) &Py%sArrType_Type,\" % types[k]\n init_list.append(astr)\n astr = \"static PyTypeObject Py%sArrType_Type;\" % types[k]\n module_list.append(astr)\n astr = \"#define Py%sArrType_Type (*(PyTypeObject *)PyArray_API[%d])\" % \\\n (types[k], num)\n extension_list.append(astr)\n\n #setup object API\n genapi.add_api_list(numtypes, 'PyArray_API', objectapi_list,\n module_list, extension_list, init_list)\n\n # setup multiarray module API\n genapi.add_api_list(numobject, 'PyArray_API', multiapi_list,\n module_list, extension_list, init_list)\n\n\n # Write to header\n fid = open(os.path.join(output_dir, '__multiarray_api.h'),'w')\n s = h_template % ('\\n'.join(module_list), '\\n'.join(extension_list))\n fid.write(s)\n fid.close()\n\n # Write to c-code\n fid = open(os.path.join(output_dir,'__multiarray_api.c'),'w')\n s = c_template % '\\n'.join(init_list)\n fid.write(s)\n fid.close()\n", + "methods": [ + { + "name": "generate_api", + "long_name": "generate_api( output_dir )", + "filename": "generate_array_api.py", + "nloc": 34, + "complexity": 2, + "token_count": 246, + "parameters": [ + "output_dir" + ], + "start_line": 113, + "end_line": 160, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "generate_api", + "long_name": "generate_api( output_dir )", + "filename": "generate_array_api.py", + "nloc": 34, + "complexity": 2, + "token_count": 246, + "parameters": [ + "output_dir" + ], + "start_line": 110, + "end_line": 157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "generate_api", + "long_name": "generate_api( output_dir )", + "filename": "generate_array_api.py", + "nloc": 34, + "complexity": 2, + "token_count": 246, + "parameters": [ + "output_dir" + ], + "start_line": 113, + "end_line": 160, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + } + ], + "nloc": 141, + "complexity": 2, + "token_count": 322, + "diff_parsed": { + "added": [ + "static unsigned int PyArray_GetNDArrayCVersion (void);", + "#define PyArray_GetNDArrayCVersion (*(unsigned int (*)(void)) PyArray_API[0])", + "#define PyBigArray_Type (*(PyTypeObject *)PyArray_API[1])", + "#define PyArray_Type (*(PyTypeObject *)PyArray_API[2])", + "#define PyArrayDescr_Type (*(PyTypeObject *)PyArray_API[3])", + "#define PyArrayFlags_Type (*(PyTypeObject *)PyArray_API[4])", + "#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[5])", + "#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[6])", + "#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[7])", + "#define PyBoolArrType_Type (*(PyTypeObject *)PyArray_API[8])", + "#define _PyArrayScalar_BoolValues (*(PyObject **)PyArray_API[9])", + " (void *) PyArray_GetNDArrayCVersion,", + " fixed = 10" + ], + "deleted": [ + "#define PyBigArray_Type (*(PyTypeObject *)PyArray_API[0])", + "#define PyArray_Type (*(PyTypeObject *)PyArray_API[1])", + "#define PyArrayDescr_Type (*(PyTypeObject *)PyArray_API[2])", + "#define PyArrayFlags_Type (*(PyTypeObject *)PyArray_API[3])", + "#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[4])", + "#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[5])", + "#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[6])", + "#define PyBoolArrType_Type (*(PyTypeObject *)PyArray_API[7])", + "#define _PyArrayScalar_BoolValues (*(PyObject **)PyArray_API[8])", + " fixed = 9" + ] + } + }, + { + "old_path": "numpy/core/code_generators/multiarray_api_order.txt", + "new_path": "numpy/core/code_generators/multiarray_api_order.txt", + "filename": "multiarray_api_order.txt", + "extension": "txt", + "change_type": "MODIFY", + "diff": "@@ -56,6 +56,7 @@ PyArray_BufferConverter\n PyArray_AxisConverter\n PyArray_BoolConverter\n PyArray_ByteorderConverter\n+PyArray_ConditionConverter\n PyArray_EquivTypes\n PyArray_Zeros\n PyArray_Empty\n@@ -64,6 +65,4 @@ PyArray_Arange\n PyArray_ArangeObj\n PyArray_SortkindConverter\n PyArray_LexSort\n-PyArray_GetNDArrayCVersion\n PyArray_Round\n-\n", + "added_lines": 1, + "deleted_lines": 2, + "source_code": "PyArray_Transpose\nPyArray_Take\nPyArray_Put\nPyArray_PutMask\nPyArray_Repeat\nPyArray_Choose\nPyArray_Sort\nPyArray_ArgSort\nPyArray_SearchSorted\nPyArray_ArgMax\nPyArray_ArgMin\nPyArray_Reshape\nPyArray_Newshape\nPyArray_Squeeze\nPyArray_View\nPyArray_SwapAxes\nPyArray_Max\nPyArray_Min\nPyArray_Ptp\nPyArray_Mean\nPyArray_Trace\nPyArray_Diagonal\nPyArray_Clip\nPyArray_Conjugate\nPyArray_Nonzero\nPyArray_Std\nPyArray_Sum\nPyArray_CumSum\nPyArray_Prod\nPyArray_CumProd\nPyArray_All\nPyArray_Any\nPyArray_Compress\nPyArray_Flatten\nPyArray_Ravel\nPyArray_MultiplyList\nPyArray_MultiplyIntList\nPyArray_GetPtr\nPyArray_CompareLists\nPyArray_AsCArray\nPyArray_As1D\nPyArray_As2D\nPyArray_Free\nPyArray_Converter\nPyArray_IntpFromSequence\nPyArray_Concatenate\nPyArray_InnerProduct\nPyArray_MatrixProduct\nPyArray_CopyAndTranspose\nPyArray_Correlate\nPyArray_TypestrConvert\nPyArray_DescrConverter\nPyArray_DescrConverter2\nPyArray_IntpConverter\nPyArray_BufferConverter\nPyArray_AxisConverter\nPyArray_BoolConverter\nPyArray_ByteorderConverter\nPyArray_ConditionConverter\nPyArray_EquivTypes\nPyArray_Zeros\nPyArray_Empty\nPyArray_Where\nPyArray_Arange\nPyArray_ArangeObj\nPyArray_SortkindConverter\nPyArray_LexSort\nPyArray_Round\n", + "source_code_before": "PyArray_Transpose\nPyArray_Take\nPyArray_Put\nPyArray_PutMask\nPyArray_Repeat\nPyArray_Choose\nPyArray_Sort\nPyArray_ArgSort\nPyArray_SearchSorted\nPyArray_ArgMax\nPyArray_ArgMin\nPyArray_Reshape\nPyArray_Newshape\nPyArray_Squeeze\nPyArray_View\nPyArray_SwapAxes\nPyArray_Max\nPyArray_Min\nPyArray_Ptp\nPyArray_Mean\nPyArray_Trace\nPyArray_Diagonal\nPyArray_Clip\nPyArray_Conjugate\nPyArray_Nonzero\nPyArray_Std\nPyArray_Sum\nPyArray_CumSum\nPyArray_Prod\nPyArray_CumProd\nPyArray_All\nPyArray_Any\nPyArray_Compress\nPyArray_Flatten\nPyArray_Ravel\nPyArray_MultiplyList\nPyArray_MultiplyIntList\nPyArray_GetPtr\nPyArray_CompareLists\nPyArray_AsCArray\nPyArray_As1D\nPyArray_As2D\nPyArray_Free\nPyArray_Converter\nPyArray_IntpFromSequence\nPyArray_Concatenate\nPyArray_InnerProduct\nPyArray_MatrixProduct\nPyArray_CopyAndTranspose\nPyArray_Correlate\nPyArray_TypestrConvert\nPyArray_DescrConverter\nPyArray_DescrConverter2\nPyArray_IntpConverter\nPyArray_BufferConverter\nPyArray_AxisConverter\nPyArray_BoolConverter\nPyArray_ByteorderConverter\nPyArray_EquivTypes\nPyArray_Zeros\nPyArray_Empty\nPyArray_Where\nPyArray_Arange\nPyArray_ArangeObj\nPyArray_SortkindConverter\nPyArray_LexSort\nPyArray_GetNDArrayCVersion\nPyArray_Round\n\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "PyArray_ConditionConverter" + ], + "deleted": [ + "PyArray_GetNDArrayCVersion", + "" + ] + } + }, + { + "old_path": "numpy/core/include/numpy/arrayobject.h", + "new_path": "numpy/core/include/numpy/arrayobject.h", + "filename": "arrayobject.h", + "extension": "h", + "change_type": "MODIFY", + "diff": "@@ -79,7 +79,7 @@ extern \"C\" CONFUSE_EMACS\n #define PY_SUCCEED 1\n \n /* Helpful to distinguish what is installed */\n-#define NDARRAY_VERSION 0x00090702\n+#define NDARRAY_VERSION 0x00090703\n \n \t/* Some platforms don't define bool, long long, or long double.\n \t Handle that here.\n@@ -236,6 +236,12 @@ typedef enum {\n \tPyArray_OBJECT_SCALAR=6,\n } PyArray_SCALARKIND;\n \n+typedef enum {\n+\tPyArray_DONTCARE=-1,\n+\tPyArray_FALSE=0,\n+\tPyArray_TRUE=1,\n+} PyArray_CONDITION;\n+\n \t/* Define bit-width array types and typedefs */\n \n #define MAX_INT8 127\n", + "added_lines": 7, + "deleted_lines": 1, + "source_code": "\n/* This expects the following variables to be defined (besides\n the usual ones from pyconfig.h\n\n SIZEOF_LONG_DOUBLE -- sizeof(long double) or sizeof(double) if no\n long double is present on platform.\n CHAR_BIT -- number of bits in a char (usually 8)\n (should be in limits.h)\n*/\n\n#ifndef Py_ARRAYOBJECT_H\n#define Py_ARRAYOBJECT_H\n#ifdef __cplusplus\n#define CONFUSE_EMACS {\n#define CONFUSE_EMACS2 }\nextern \"C\" CONFUSE_EMACS\n#undef CONFUSE_EMACS\n#undef CONFUSE_EMACS2\n/* ... otherwise a semi-smart idententer (like emacs) tries to indent\n everything when you're typing */\n#endif\n#include \"config.h\"\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# define CAT2(x,y) x ## y\n# define CAT(x,y) CAT2(x,y)\n# define NS(name) CAT(PY_ARRAY_TYPES_PREFIX, name)\n# define longlong NS(longlong)\n# define ulonglong NS(ulonglong)\n# define Bool NS(Bool)\n# define longdouble NS(longdouble)\n# define byte NS(byte)\n# define ubyte NS(ubyte)\n# define ushort NS(ushort)\n# define uint NS(uint)\n# define ulong NS(ulong)\n# define cfloat NS(cfloat)\n# define cdouble NS(cdouble)\n# define clongdouble NS(clongdouble)\n# define Int8 NS(Int8)\n# define UInt8 NS(UInt8)\n# define Int16 NS(Int16)\n# define UInt16 NS(UInt16)\n# define Int32 NS(Int32)\n# define UInt32 NS(UInt32)\n# define Int64 NS(Int64)\n# define UInt64 NS(UInt64)\n# define Int128 NS(Int128)\n# define UInt128 NS(UInt128)\n# define Int256 NS(Int256)\n# define UInt256 NS(UInt256)\n# define Float16 NS(Float16)\n# define Complex32 NS(Complex32)\n# define Float32 NS(Float32)\n# define Complex64 NS(Complex64)\n# define Float64 NS(Float64)\n# define Complex128 NS(Complex128)\n# define Float80 NS(Float80)\n# define Complex160 NS(Complex160)\n# define Float96 NS(Float96)\n# define Complex192 NS(Complex192)\n# define Float128 NS(Float128)\n# define Complex256 NS(Complex256)\n# define intp NS(intp)\n# define uintp NS(uintp)\n#endif\n\n/* There are several places in the code where an array of dimensions is */\n/* allocated statically. This is the size of that static allocation. */\n/* The array creation itself could have arbitrary dimensions but\n * all the places where static allocation is used would need to\n * be changed to dynamic (including inside of structures)\n */\n\n#define MAX_DIMS 32\n\n/* Used for Converter Functions \"O&\" code in ParseTuple */\n#define PY_FAIL 0\n#define PY_SUCCEED 1\n\n /* Helpful to distinguish what is installed */\n#define NDARRAY_VERSION 0x00090703\n\n\t/* Some platforms don't define bool, long long, or long double.\n\t Handle that here.\n\t */\n\n#ifdef PY_LONG_LONG\ntypedef PY_LONG_LONG longlong;\ntypedef unsigned PY_LONG_LONG ulonglong;\n# ifdef _MSC_VER\n# define LONGLONG_FMT \"I64d\"\n# define ULONGLONG_FMT \"I64u\"\n# define LONGLONG_SUFFIX(x) (x##i64)\n# define ULONGLONG_SUFFIX(x) (x##Ui64)\n# else\n\t/* #define LONGLONG_FMT \"lld\" Another possible variant\n #define ULONGLONG_FMT \"llu\"\n\n\t #define LONGLONG_FMT \"qd\" -- BSD perhaps?\n\t #define ULONGLONG_FMT \"qu\"\n\t*/\n# define LONGLONG_FMT \"Ld\"\n# define ULONGLONG_FMT \"Lu\"\n# define LONGLONG_SUFFIX(x) (x##LL)\n# define ULONGLONG_SUFFIX(x) (x##ULL)\n# endif\n#else\ntypedef long longlong;\ntypedef unsigned long ulonglong;\n# define LONGLONG_SUFFIX(x) (x##L)\n# define ULONGLONG_SUFFIX(x) (x##UL)\n#endif\n\ntypedef unsigned char Bool;\n#ifndef FALSE\n#define FALSE 0\n#endif\n#ifndef TRUE\n#define TRUE 1\n#endif\n\n#if SIZEOF_LONG_DOUBLE==SIZEOF_DOUBLE\n\ttypedef double longdouble;\n #define LONGDOUBLE_FMT \"g\"\n#else\n\ttypedef long double longdouble;\n #define LONGDOUBLE_FMT \"Lg\"\n#endif\n\n#ifndef Py_USING_UNICODE\n#error Must use Python with unicode enabled. \n#endif\n\n\ntypedef signed char byte;\ntypedef unsigned char ubyte;\n#ifndef _BSD_SOURCE\ntypedef unsigned short ushort;\ntypedef unsigned int uint;\ntypedef unsigned long ulong;\n#endif\n\ntypedef struct { float real, imag; } cfloat;\ntypedef struct { double real, imag; } cdouble;\ntypedef struct {longdouble real, imag;} clongdouble;\n\nenum PyArray_TYPES { PyArray_BOOL=0,\n PyArray_BYTE, PyArray_UBYTE,\n\t\t PyArray_SHORT, PyArray_USHORT,\n\t\t PyArray_INT, PyArray_UINT,\n\t\t\tPyArray_LONG, PyArray_ULONG,\n PyArray_LONGLONG, PyArray_ULONGLONG,\n\t\t\tPyArray_FLOAT, PyArray_DOUBLE, PyArray_LONGDOUBLE,\n\t\t\tPyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CLONGDOUBLE,\n\t\t\tPyArray_OBJECT=17,\n PyArray_STRING, PyArray_UNICODE,\n\t\t\tPyArray_VOID,\n\t\t\tPyArray_NTYPES,\n\t\t\tPyArray_NOTYPE,\n\t\t\tPyArray_USERDEF=256 /* leave room for characters */\n};\n\n\t/* basetype array priority */\n#define PyArray_PRIORITY 0.0\n#define PyArray_BIG_PRIORITY 0.1\n\t/* default subtype priority */\n#define PyArray_SUBTYPE_PRIORITY 1.0\n\n\t/* How many floating point types are there */\n#define PyArray_NUM_FLOATTYPE 3\n\n\n\t/* We need to match intp to a signed integer of the same size as\n\t a pointer variable. uintp to the equivalent unsigned integer\n\t*/\n\n\n\t/* These characters correspond to the array type and the\n\t struct module */\n\n\t/* except 'p' -- signed integer for pointer type */\n\nenum PyArray_TYPECHAR { PyArray_BOOLLTR = '?',\n\t\t\tPyArray_BYTELTR = 'b',\n\t\t\tPyArray_UBYTELTR = 'B',\n\t\t\tPyArray_SHORTLTR = 'h',\n\t\t\tPyArray_USHORTLTR = 'H',\n\t\t\tPyArray_INTLTR = 'i',\n\t\t\tPyArray_UINTLTR = 'I',\n\t\t\tPyArray_LONGLTR = 'l',\n\t\t\tPyArray_ULONGLTR = 'L',\n\t\t\tPyArray_LONGLONGLTR = 'q',\n\t\t\tPyArray_ULONGLONGLTR = 'Q',\n\t\t\tPyArray_FLOATLTR = 'f',\n\t\t\tPyArray_DOUBLELTR = 'd',\n\t\t\tPyArray_LONGDOUBLELTR = 'g',\n\t\t\tPyArray_CFLOATLTR = 'F',\n\t\t\tPyArray_CDOUBLELTR = 'D',\n\t\t\tPyArray_CLONGDOUBLELTR = 'G',\n\t\t\tPyArray_OBJECTLTR = 'O',\n\t\t\tPyArray_STRINGLTR = 'S',\n\t\t\tPyArray_STRINGLTR2 = 'a',\n\t\t\tPyArray_UNICODELTR = 'U',\n\t\t PyArray_VOIDLTR = 'V',\n\n\t\t\t/* No Descriptor, just a define -- this let's\n\t\t\t Python users specify an array of integers\n\t\t\t large enough to hold a pointer on the platform*/\n\t\t\tPyArray_INTPLTR = 'p',\n\t\t\tPyArray_UINTPLTR = 'P',\n\n\t\t\tPyArray_GENBOOLLTR ='b',\n\t\t\tPyArray_SIGNEDLTR = 'i',\n\t\t\tPyArray_UNSIGNEDLTR = 'u',\n\t\t\tPyArray_FLOATINGLTR = 'f',\n\t\t\tPyArray_COMPLEXLTR = 'c'\n};\n\ntypedef enum {\n\tPyArray_QUICKSORT=0,\n\tPyArray_HEAPSORT=1,\n\tPyArray_MERGESORT=2,\n\tPyArray_TIMSORT=3 /* the sort Python uses -- specialized */\n} PyArray_SORTKIND;\n#define PyArray_NSORTS PyArray_TIMSORT + 1\n\n\ntypedef enum {\n\tPyArray_NOSCALAR=0,\n\tPyArray_BOOL_SCALAR=1,\n\tPyArray_INTPOS_SCALAR=2,\n\tPyArray_INTNEG_SCALAR=3,\n\tPyArray_FLOAT_SCALAR=4,\n\tPyArray_COMPLEX_SCALAR=5,\n\tPyArray_OBJECT_SCALAR=6,\n} PyArray_SCALARKIND;\n\ntypedef enum {\n\tPyArray_DONTCARE=-1,\n\tPyArray_FALSE=0,\n\tPyArray_TRUE=1,\n} PyArray_CONDITION;\n\n\t/* Define bit-width array types and typedefs */\n\n#define MAX_INT8 127\n#define MIN_INT8 -128\n#define MAX_UINT8 255\n#define MAX_INT16 32767\n#define MIN_INT16 -32768\n#define MAX_UINT16 65535\n#define MAX_INT32 2147483647\n#define MIN_INT32 (-MAX_INT32 - 1)\n#define MAX_UINT32 4294967295U\n#define MAX_INT64 LONGLONG_SUFFIX(9223372036854775807)\n#define MIN_INT64 (-MAX_INT64 - LONGLONG_SUFFIX(1))\n#define MAX_UINT64 ULONGLONG_SUFFIX(18446744073709551615)\n#define MAX_INT128 LONGLONG_SUFFIX(85070591730234615865843651857942052864)\n#define MIN_INT128 (-MAX_INT128 - LONGLONG_SUFFIX(1))\n#define MAX_UINT128 ULONGLONG_SUFFIX(170141183460469231731687303715884105728)\n#define MAX_INT256 LONGLONG_SUFFIX(57896044618658097711785492504343953926634992332820282019728792003956564819967)\n#define MIN_INT256 (-MAX_INT256 - LONGLONG_SUFFIX(1))\n#define MAX_UINT256 ULONGLONG_SUFFIX(115792089237316195423570985008687907853269984665640564039457584007913129639935)\n\n\t/* Need to find the number of bits for each type and\n\t make definitions accordingly.\n\n\t C states that sizeof(char) == 1 by definition\n\n\t So, just using the sizeof keyword won't help.\n\n\t It also looks like Python itself uses sizeof(char) quite a\n\t bit, which by definition should be 1 all the time.\n\n\t Idea: Make Use of CHAR_BIT which should tell us how many\n\t BITS per CHARACTER\n\t*/\n\n\t/* Include platform definitions -- These are in the C89/90 standard */\n#include \n#define MAX_BYTE SCHAR_MAX\n#define MIN_BYTE SCHAR_MIN\n#define MAX_UBYTE UCHAR_MAX\n#define MAX_SHORT SHRT_MAX\n#define MIN_SHORT SHRT_MIN\n#define MAX_USHORT USHRT_MAX\n#define MAX_INT INT_MAX\n#ifndef INT_MIN\n#define INT_MIN (-INT_MAX - 1)\n#endif\n#define MIN_INT INT_MIN\n#define MAX_UINT UINT_MAX\n#define MAX_LONG LONG_MAX\n#define MIN_LONG LONG_MIN\n#define MAX_ULONG ULONG_MAX\n\n#define SIZEOF_LONGDOUBLE SIZEOF_LONG_DOUBLE\n#define SIZEOF_LONGLONG SIZEOF_LONG_LONG\n#define BITSOF_BOOL sizeof(Bool)*CHAR_BIT\n#define BITSOF_CHAR CHAR_BIT\n#define BITSOF_SHORT (SIZEOF_SHORT*CHAR_BIT)\n#define BITSOF_INT (SIZEOF_INT*CHAR_BIT)\n#define BITSOF_LONG (SIZEOF_LONG*CHAR_BIT)\n#define BITSOF_LONGLONG (SIZEOF_LONGLONG*CHAR_BIT)\n#define BITSOF_FLOAT (SIZEOF_FLOAT*CHAR_BIT)\n#define BITSOF_DOUBLE (SIZEOF_DOUBLE*CHAR_BIT)\n#define BITSOF_LONGDOUBLE (SIZEOF_LONGDOUBLE*CHAR_BIT)\n\n\n#if BITSOF_LONG == 8\n#define PyArray_INT8 PyArray_LONG\n#define PyArray_UINT8 PyArray_ULONG\n\ttypedef long Int8;\n\ttypedef unsigned long UInt8;\n#define STRBITSOF_LONG \"8\"\n#elif BITSOF_LONG == 16\n#define PyArray_INT16 PyArray_LONG\n#define PyArray_UINT16 PyArray_ULONG\n\ttypedef long Int16;\n\ttypedef unsigned long UInt16;\n#define STRBITSOF_LONG \"16\"\n#elif BITSOF_LONG == 32\n#define PyArray_INT32 PyArray_LONG\n#define PyArray_UINT32 PyArray_ULONG\n\ttypedef long Int32;\n\ttypedef unsigned long UInt32;\n\ttypedef unsigned long PyArray_UCS4;\n#define STRBITSOF_LONG \"32\"\n#elif BITSOF_LONG == 64\n#define PyArray_INT64 PyArray_LONG\n#define PyArray_UINT64 PyArray_ULONG\n\ttypedef long Int64;\n\ttypedef unsigned long UInt64;\n#define STRBITSOF_LONG \"64\"\n#elif BITSOF_LONG == 128\n#define PyArray_INT128 PyArray_LONG\n#define PyArray_UINT128 PyArray_ULONG\n\ttypedef long Int128;\n\ttypedef unsigned long UInt128;\n#define STRBITSOF_LONG \"128\"\n#endif\n\n#if BITSOF_LONGLONG == 8\n# ifndef PyArray_INT8\n# define PyArray_INT8 PyArray_LONGLONG\n# define PyArray_UINT8 PyArray_ULONGLONG\n\ttypedef longlong Int8;\n\ttypedef ulonglong UInt8;\n# endif\n# define MAX_LONGLONG MAX_INT8\n# define MIN_LONGLONG MIN_INT8\n# define MAX_ULONGLONG MAX_UINT8\n#define STRBITSOF_LONGLONG \"8\"\n#elif BITSOF_LONGLONG == 16\n# ifndef PyArray_INT16\n# define PyArray_INT16 PyArray_LONGLONG\n# define PyArray_UINT16 PyArray_ULONGLONG\n\ttypedef longlong Int16;\n\ttypedef ulonglong UInt16;\n# endif\n# define MAX_LONGLONG MAX_INT16\n# define MIN_LONGLONG MIN_INT16\n# define MAX_ULONGLONG MAX_UINT16\n#define STRBITSOF_LONGLONG \"16\"\n#elif BITSOF_LONGLONG == 32\n# ifndef PyArray_INT32\n# define PyArray_INT32 PyArray_LONGLONG\n# define PyArray_UINT32 PyArray_ULONGLONG\n\ttypedef longlong Int32;\n\ttypedef ulonglong UInt32;\n\ttypedef ulonglong PyArray_UCS4;\n# endif\n# define MAX_LONGLONG MAX_INT32\n# define MIN_LONGLONG MIN_INT32\n# define MAX_ULONGLONG MAX_UINT32\n#define STRBITSOF_LONGLONG \"32\"\n#elif BITSOF_LONGLONG == 64\n# ifndef PyArray_INT64\n# define PyArray_INT64 PyArray_LONGLONG\n# define PyArray_UINT64 PyArray_ULONGLONG\n\ttypedef longlong Int64;\n\ttypedef ulonglong UInt64;\n# endif\n# define MAX_LONGLONG MAX_INT64\n# define MIN_LONGLONG MIN_INT64\n# define MAX_ULONGLONG MAX_UINT64\n#define STRBITSOF_LONGLONG \"64\"\n#elif BITSOF_LONGLONG == 128\n# ifndef PyArray_INT128\n# define PyArray_INT128 PyArray_LONGLONG\n# define PyArray_UINT128 PyArray_ULONGLONG\n\ttypedef longlong Int128;\n\ttypedef ulonglong UInt128;\n# endif\n# define MAX_LONGLONG MAX_INT128\n# define MIN_LONGLONG MIN_INT128\n# define MAX_ULONGLONG MAX_UINT128\n#define STRBITSOF_LONGLONG \"128\"\n#elif BITSOF_LONGLONG == 256\n# define PyArray_INT256 PyArray_LONGLONG\n# define PyArray_UINT256 PyArray_ULONGLONG\n\ttypedef longlong Int256;\n\ttypedef ulonglong UInt256;\n# define MAX_LONGLONG MAX_INT256\n# define MIN_LONGLONG MIN_INT256\n# define MAX_ULONGLONG MAX_UINT256\n#define STRBITSOF_LONGLONG \"256\"\n#endif\n\n#if BITSOF_INT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_INT\n#define PyArray_UINT8 PyArray_UINT\n\ttypedef int Int8;\n\ttypedef unsigned int UInt8;\n#endif\n#define STRBITSOF_INT \"8\"\n#elif BITSOF_INT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_INT\n#define PyArray_UINT16 PyArray_UINT\n\ttypedef int Int16;\n\ttypedef unsigned int UInt16;\n#endif\n#define STRBITSOF_INT \"16\"\n#elif BITSOF_INT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_INT\n#define PyArray_UINT32 PyArray_UINT\n\ttypedef int Int32;\n\ttypedef unsigned int UInt32;\n\ttypedef unsigned int PyArray_UCS4;\n#endif\n#define STRBITSOF_INT \"32\"\n#elif BITSOF_INT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_INT\n#define PyArray_UINT64 PyArray_UINT\n\ttypedef int Int64;\n\ttypedef unsigned int UInt64;\n#endif\n#define STRBITSOF_INT \"64\"\n#elif BITSOF_INT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_INT\n#define PyArray_UINT128 PyArray_UINT\n\ttypedef int Int128;\n\ttypedef unsigned int UInt128;\n#endif\n#define STRBITSOF_INT \"128\"\n#endif\n\n#if BITSOF_SHORT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_SHORT\n#define PyArray_UINT8 PyArray_USHORT\n\ttypedef short Int8;\n\ttypedef unsigned short UInt8;\n#endif\n#define STRBITSOF_SHORT \"8\"\n#elif BITSOF_SHORT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_SHORT\n#define PyArray_UINT16 PyArray_USHORT\n\ttypedef short Int16;\n\ttypedef unsigned short UInt16;\n#endif\n#define STRBITSOF_SHORT \"16\"\n#elif BITSOF_SHORT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_SHORT\n#define PyArray_UINT32 PyArray_USHORT\n\ttypedef short Int32;\n\ttypedef unsigned short UInt32;\n\ttypedef unsigned short PyArray_UCS4;\n#endif\n#define STRBITSOF_SHORT \"32\"\n#elif BITSOF_SHORT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_SHORT\n#define PyArray_UINT64 PyArray_USHORT\n\ttypedef short Int64;\n\ttypedef unsigned short UInt64;\n#endif\n#define STRBITSOF_SHORT \"64\"\n#elif BITSOF_SHORT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_SHORT\n#define PyArray_UINT128 PyArray_USHORT\n\ttypedef short Int128;\n\ttypedef unsigned short UInt128;\n#endif\n#define STRBITSOF_SHORT \"128\"\n#endif\n\n\n#if BITSOF_CHAR == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_BYTE\n#define PyArray_UINT8 PyArray_UBYTE\n\ttypedef signed char Int8;\n\ttypedef unsigned char UInt8;\n#endif\n#define STRBITSOF_CHAR \"8\"\n#elif BITSOF_CHAR == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_BYTE\n#define PyArray_UINT16 PyArray_UBYTE\n\ttypedef signed char Int16;\n\ttypedef unsigned char UInt16;\n#endif\n#define STRBITSOF_CHAR \"16\"\n#elif BITSOF_CHAR == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_BYTE\n#define PyArray_UINT32 PyArray_UBYTE\n\ttypedef signed char Int32;\n\ttypedef unsigned char UInt32;\n\ttypedef unsigned char PyArray_UCS4;\n#endif\n#define STRBITSOF_CHAR \"32\"\n#elif BITSOF_CHAR == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_BYTE\n#define PyArray_UINT64 PyArray_UBYTE\n\ttypedef signed char Int64;\n\ttypedef unsigned char UInt64;\n#endif\n#define STRBITSOF_CHAR \"64\"\n#elif BITSOF_CHAR == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_BYTE\n#define PyArray_UINT128 PyArray_UBYTE\n\ttypedef signed char Int128;\n\ttypedef unsigned char UInt128;\n#endif\n#define STRBITSOF_CHAR \"128\"\n#endif\n\n\n\n#if BITSOF_DOUBLE == 16\n#define STRBITSOF_DOUBLE \"16\"\n#define STRBITSOF_CDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_DOUBLE\n#define PyArray_COMPLEX32 PyArray_CDOUBLE\n\ttypedef double Float16;\n\ttypedef cdouble Complex32;\n#endif\n#elif BITSOF_DOUBLE == 32\n#define STRBITSOF_DOUBLE \"32\"\n#define STRBITSOF_CDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_DOUBLE\n#define PyArray_COMPLEX64 PyArray_CDOUBLE\n\ttypedef double Float32;\n\ttypedef cdouble Complex64;\n#endif\n#elif BITSOF_DOUBLE == 64\n#define STRBITSOF_DOUBLE \"64\"\n#define STRBITSOF_CDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_DOUBLE\n#define PyArray_COMPLEX128 PyArray_CDOUBLE\n\ttypedef double Float64;\n\ttypedef cdouble Complex128;\n#endif\n#elif BITSOF_DOUBLE == 80\n#define STRBITSOF_DOUBLE \"80\"\n#define STRBITSOF_CDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_DOUBLE\n#define PyArray_COMPLEX160 PyArray_CDOUBLE\n\ttypedef double Float80;\n\ttypedef cdouble Complex160;\n#endif\n#elif BITSOF_DOUBLE == 96\n#define STRBITSOF_DOUBLE \"96\"\n#define STRBITSOF_CDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_DOUBLE\n#define PyArray_COMPLEX192 PyArray_CDOUBLE\n\ttypedef double Float96;\n\ttypedef cdouble Complex192;\n#endif\n#elif BITSOF_DOUBLE == 128\n#define STRBITSOF_DOUBLE \"128\"\n#define STRBITSOF_CDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_DOUBLE\n#define PyArray_COMPLEX256 PyArray_CDOUBLE\n\ttypedef double Float128;\n\ttypedef cdouble Complex256;\n#endif\n#endif\n\n\n\n#if BITSOF_FLOAT == 16\n#define STRBITSOF_FLOAT \"16\"\n#define STRBITSOF_CFLOAT \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_FLOAT\n#define PyArray_COMPLEX32 PyArray_CFLOAT\n\ttypedef float Float16;\n\ttypedef cfloat Complex32;\n#endif\n#elif BITSOF_FLOAT == 32\n#define STRBITSOF_FLOAT \"32\"\n#define STRBITSOF_CFLOAT \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_FLOAT\n#define PyArray_COMPLEX64 PyArray_CFLOAT\n\ttypedef float Float32;\n\ttypedef cfloat Complex64;\n#endif\n#elif BITSOF_FLOAT == 64\n#define STRBITSOF_FLOAT \"64\"\n#define STRBITSOF_CFLOAT \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_FLOAT\n#define PyArray_COMPLEX128 PyArray_CFLOAT\n\ttypedef float Float64;\n\ttypedef cfloat Complex128;\n#endif\n#elif BITSOF_FLOAT == 80\n#define STRBITSOF_FLOAT \"80\"\n#define STRBITSOF_CFLOAT \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_FLOAT\n#define PyArray_COMPLEX160 PyArray_CFLOAT\n\ttypedef float Float80;\n\ttypedef cfloat Complex160;\n#endif\n#elif BITSOF_FLOAT == 96\n#define STRBITSOF_FLOAT \"96\"\n#define STRBITSOF_CFLOAT \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_FLOAT\n#define PyArray_COMPLEX192 PyArray_CFLOAT\n\ttypedef float Float96;\n\ttypedef cfloat Complex192;\n#endif\n#elif BITSOF_FLOAT == 128\n#define STRBITSOF_FLOAT \"128\"\n#define STRBITSOF_CFLOAT \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_FLOAT\n#define PyArray_COMPLEX256 PyArray_CFLOAT\n\ttypedef float Float128;\n\ttypedef cfloat Complex256;\n#endif\n#endif\n\n\n#if BITSOF_LONGDOUBLE == 16\n#define STRBITSOF_LONGDOUBLE \"16\"\n#define STRBITSOF_CLONGDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX32 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float16;\n\ttypedef clongdouble Complex32;\n#endif\n#elif BITSOF_LONGDOUBLE == 32\n#define STRBITSOF_LONGDOUBLE \"32\"\n#define STRBITSOF_CLONGDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX64 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float32;\n\ttypedef clongdouble Complex64;\n#endif\n#elif BITSOF_LONGDOUBLE == 64\n#define STRBITSOF_LONGDOUBLE \"64\"\n#define STRBITSOF_CLONGDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX128 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float64;\n\ttypedef clongdouble Complex128;\n#endif\n#elif BITSOF_LONGDOUBLE == 80\n#define STRBITSOF_LONGDOUBLE \"80\"\n#define STRBITSOF_CLONGDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX160 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float80;\n\ttypedef clongdouble Complex160;\n#endif\n#elif BITSOF_LONGDOUBLE == 96\n#define STRBITSOF_LONGDOUBLE \"96\"\n#define STRBITSOF_CLONGDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX192 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float96;\n\ttypedef clongdouble Complex192;\n#endif\n#elif BITSOF_LONGDOUBLE == 128\n#define STRBITSOF_LONGDOUBLE \"128\"\n#define STRBITSOF_CLONGDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX256 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float128;\n\ttypedef clongdouble Complex256;\n#endif\n#elif BITSOF_LONGDOUBLE == 256\n#define STRBITSOF_LONGDOUBLE \"256\"\n#define STRBITSOF_CLONGDOUBLE \"512\"\n#define PyArray_FLOAT256 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX512 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float256;\n\ttypedef clongdouble Complex512;\n#endif\n\n\t/* End of typedefs for numarray style bit-width names */\n\n/* This is to typedef Intp to the appropriate pointer size for this platform.\n * Py_intptr_t, Py_uintptr_t are defined in pyport.h. */\ntypedef Py_intptr_t intp;\ntypedef Py_uintptr_t uintp;\n#define SIZEOF_INTP SIZEOF_PY_INTPTR_T\n#define SIZEOF_UINTP SIZEOF_PY_INTPTR_T\n\n#if PY_VERSION_HEX >= 0x02050000\n#define _int_or_ssize_t Py_ssize_t\n#else\n#define _int_or_ssize_t int\n#endif\n\n#define INTP_FMT \"d\"\n\n#if SIZEOF_PY_INTPTR_T == SIZEOF_INT\n\t#define PyArray_INTP PyArray_INT\n\t#define PyArray_UINTP PyArray_UINT\n #define PyIntpArrType_Type PyIntArrType_Type\n #define PyUIntpArrType_Type PyUIntArrType_Type\n\t#define MAX_INTP MAX_INT\n\t#define MIN_INTP MIN_INT\n\t#define MAX_UINTP MAX_UINT\n#elif SIZEOF_PY_INTPTR_T == SIZEOF_LONG\n\t#define PyArray_INTP PyArray_LONG\n\t#define PyArray_UINTP PyArray_ULONG\n #define PyIntpArrType_Type PyLongArrType_Type\n #define PyUIntpArrType_Type PyULongArrType_Type\n\t#define MAX_INTP MAX_LONG\n\t#define MIN_INTP MIN_LONG\n\t#define MAX_UINTP MAX_ULONG\n #undef INTP_FMT\n #define INTP_FMT \"ld\"\n#elif defined(PY_LONG_LONG) && (SIZEOF_PY_INTPTR_T == SIZEOF_LONG_LONG)\n\t#define PyArray_INTP PyArray_LONGLONG\n\t#define PyArray_UINTP PyArray_ULONGLONG\n #define PyIntpArrType_Type PyLongLongArrType_Type\n #define PyUIntpArrType_Type PyULongLongArrType_Type\n\t#define MAX_INTP MAX_LONGLONG\n\t#define MIN_INTP MIN_LONGLONG\n\t#define MAX_UINTP MAX_ULONGLONG\n #undef INTP_FMT\n #define INTP_FMT \"Ld\"\n#endif\n\n#define ERR(str) fprintf(stderr, #str); fflush(stderr);\n#define ERR2(str) fprintf(stderr, str); fflush(stderr);\n\n /* Macros to define how array, and dimension/strides data is\n allocated.\n */\n\n /* Data buffer */\n#define PyDataMem_NEW(size) ((char *)malloc(size))\n /* #define PyArrayMem_NEW(size) PyMem_NEW(char, size)*/\n#define PyDataMem_FREE(ptr) free(ptr)\n /* #define PyArrayMem_FREE(ptr) PyMem_Free(ptr) */\n#define PyDataMem_RENEW(ptr,size) ((char *)realloc(ptr,size))\n\n#define PyArray_USE_PYMEM 0\n\n#if PyArray_USE_PYMEM == 1\n#define _pya_malloc PyObject_Malloc\n#define _pya_free PyObject_Free\n#define _pya_realloc PyObject_Realloc\n#else\n#define _pya_malloc malloc\n#define _pya_free free\n#define _pya_realloc realloc\n#endif\n\n/* Dimensions and strides */\n#define PyDimMem_NEW(size) ((intp *)_pya_malloc(size*sizeof(intp)))\n#define PyDimMem_FREE(ptr) _pya_free(ptr)\n#define PyDimMem_RENEW(ptr,size) ((intp *)_pya_realloc(ptr,size*sizeof(intp)))\n\n\n /* These must deal with unaligned and swapped data if necessary */\ntypedef PyObject * (PyArray_GetItemFunc) (void *, void *);\ntypedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);\n\ntypedef void (PyArray_CopySwapNFunc)(void *, void *, intp, int, int);\ntypedef void (PyArray_CopySwapFunc)(void *, void *, int, int);\ntypedef Bool (PyArray_NonzeroFunc)(void *, void *);\n\n\n /* These assume aligned and notswapped data -- a buffer will be\n used before or contiguous data will be obtained\n */\ntypedef int (PyArray_CompareFunc)(const void *, const void *, void *);\ntypedef int (PyArray_ArgFunc)(void*, intp, intp*, void *);\ntypedef void (PyArray_DotFunc)(void *, intp, void *, intp, void *, intp,\n\t\t\t void *);\ntypedef void (PyArray_VectorUnaryFunc)(void *, void *, intp, void *, void *);\ntypedef int (PyArray_ScanFunc)(FILE *, void *, void *, void *);\ntypedef int (PyArray_FromStrFunc)(char *, void *, char **, void *);\n\ntypedef int (PyArray_FillFunc)(void *, intp, void *);\n\ntypedef int (PyArray_SortFunc)(void *, intp, void *);\ntypedef int (PyArray_ArgSortFunc)(void *, intp *, intp, void *);\n\ntypedef int (PyArray_FillWithScalarFunc)(void *, intp, void *, void *);\n\ntypedef struct {\n intp *ptr;\n int len;\n} PyArray_Dims;\n\ntypedef struct {\n\t/* Functions to cast to all other standard types*/\n\tPyArray_VectorUnaryFunc *cast[PyArray_NTYPES];\n\n\t/* Functions to get and set items with standard\n\t Python types -- not array scalars */\n\tPyArray_GetItemFunc *getitem;\n\tPyArray_SetItemFunc *setitem;\n\n\t/* Copy and/or swap data. Memory areas may not overlap */\n\t/* Use memmove first if they might */\n\tPyArray_CopySwapNFunc *copyswapn;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Function to compare items */\n\tPyArray_CompareFunc *compare;\n\n\t/* Function to select largest */\n\tPyArray_ArgFunc *argmax;\n\n\t/* Function to compute dot product */\n\tPyArray_DotFunc\t*dotfunc;\n\n\t/* Function to scan an ASCII file and\n\t place a single value plus possible separator */\n\tPyArray_ScanFunc *scanfunc;\n\n\t/* Function to read a single value from a string */\n\t/* and adjust the pointer */\n\tPyArray_FromStrFunc *fromstr;\n\n\t/* Function to determine if data is zero or not */\n\tPyArray_NonzeroFunc *nonzero;\n\n\t/* Used for arange */\n\tPyArray_FillFunc *fill;\n\n\t/* Function to fill arrays with scalar values */\n\tPyArray_FillWithScalarFunc *fillwithscalar;\n\n\t/* Sorting functions */\n\tPyArray_SortFunc *sort[PyArray_NSORTS];\n\tPyArray_ArgSortFunc *argsort[PyArray_NSORTS];\n\n} PyArray_ArrFuncs;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tPyTypeObject *typeobj; /* the type object representing an\n\t\t\t\t intance of this type */\n\tchar kind; /* kind for this type */\n\tchar type; /* unique-character representing this type */\n\tchar byteorder; /* '>' (big), '<' (little), '|'\n\t\t\t\t (not-applicable), or '=' (native). */\n char hasobject; /* non-zero if it has object arrays in fields */\n\tint type_num; /* number representing this type */\n\tint elsize; /* element size for this type */\n\tint alignment; /* alignment needed for this type */\n\tstruct _arr_descr\t\t\t\t\t\\\n\t*subarray; /* Non-NULL if this type is\n\t\t\t\t is an array (C-contiguous)\n\t\t\t\t of some other type\n\t\t\t\t*/\n\tPyObject *fields; /* The fields dictionary for this type */\n\t /* For statically defined descr this\n\t\t\t\t is always Py_None */\n\n\tPyArray_ArrFuncs *f; /* a table of functions specific for each\n\t\t\t\t basic data descriptor */\n} PyArray_Descr;\n\ntypedef struct _arr_descr {\n\tPyArray_Descr *base;\n\tPyObject *shape; /* a tuple */\n} PyArray_ArrayDescr;\n\n\n/*\n The main array object structure. It is recommended to use the macros\n defined below (PyArray_DATA and friends) access fields here, instead\n of the members themselves.\n */\n\ntypedef struct PyArrayObject {\n\tPyObject_HEAD\n\tchar *data; /* pointer to raw data buffer */\n\tint nd; /* number of dimensions, also called ndim */\n\tintp *dimensions; /* size in each dimension */\n intp *strides; /* bytes to jump to get to the\n\t\t\t\t next element in each dimension */\n\tPyObject *base; /* This object should be decref'd\n\t\t\t\t upon deletion of array */\n\t /* For views it points to the original array */\n\t /* For creation from buffer object it points\n\t\t\t\t to an object that shold be decref'd on\n\t\t\t\t deletion */\n\t /* For UPDATEIFCOPY flag this is an array\n\t\t\t\t to-be-updated upon deletion of this one */\n\tPyArray_Descr *descr; /* Pointer to type structure */\n\tint flags; /* Flags describing array -- see below*/\n\tPyObject *weakreflist; /* For weakreferences */\n} PyArrayObject;\n\n\n#define fortran fortran_ /* For some compilers */\n\n/* Mirrors buffer object to ptr */\n\ntypedef struct {\n PyObject_HEAD\n PyObject *base;\n void *ptr;\n intp len;\n int flags;\n} PyArray_Chunk;\n\n/* Array flags */\n\n/* Means c-style contiguous (last index varies the fastest). The\n data elements right after each other. */\n#define CONTIGUOUS 0x0001\n/* set if array is a contiguous Fortran array: the first index\n varies the fastest in memory (strides array is reverse of\n C-contiguous array)*/\n#define FORTRAN 0x0002\n\n/*\n Note: all 0-d arrays are CONTIGUOUS and FORTRAN contiguous. If a\n 1-d array is CONTIGUOUS it is also FORTRAN contiguous\n*/\n\n/* If set, the array owns the data: it will be free'd when the array\n is deleted. */\n#define OWNDATA 0x0004\n#define OWN_DATA OWNDATA\n\n/* An array never has these three set; they're only used as parameter\n flags to the the various FromAny functions */\n/* Cause a cast to occur regardless of whether or not it is safe. */\n#define FORCECAST 0x0010\n/* Always copy the array. Returned arrays are always CONTIGUOUS, ALIGNED,\n and WRITEABLE. */\n#define ENSURECOPY 0x0020\n/* Make sure the returned array is an ndarray or a bigndarray */\n#define ENSUREARRAY 0x0040\n\n/* Array data is aligned on the appropiate memory address for the\n type stored (e.g., an array of doubles (8 bytes each) starts on\n a memory address that's a multiple of 8) */\n#define ALIGNED 0x0100\n/* Array data has the native endianness */\n#define NOTSWAPPED 0x0200\n/* Array data is writeable */\n#define WRITEABLE 0x0400\n/* If this flag is set, then base contains a pointer to an array of\n the same size that should be updated with the current contents of\n this array when this array is deallocated\n*/\n#define UPDATEIFCOPY 0x1000\n\n\n#define BEHAVED_FLAGS ALIGNED | WRITEABLE\n#define BEHAVED_NS_FLAGS ALIGNED | WRITEABLE | NOTSWAPPED\n#define CARRAY_FLAGS CONTIGUOUS | BEHAVED_FLAGS\n#define CARRAY_FLAGS_RO CONTIGUOUS | ALIGNED\n#define FARRAY_FLAGS FORTRAN | BEHAVED_FLAGS\n#define FARRAY_FLAGS_RO FORTRAN | ALIGNED\n#define DEFAULT_FLAGS CARRAY_FLAGS\n\n#define UPDATE_ALL_FLAGS CONTIGUOUS | FORTRAN | ALIGNED\n\n\n/* Size of internal buffers used for alignment */\n#define PyArray_BUFSIZE 10000\n#define PyArray_MIN_BUFSIZE 5\n#define PyArray_MAX_BUFSIZE 100000000\n\n/*\n * C API: consists of Macros and functions. The MACROS are defined here.\n */\n\n\n#define PyArray_CHKFLAGS(m, FLAGS) \\\n\t((((PyArrayObject *)(m))->flags & (FLAGS)) == (FLAGS))\n#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, CONTIGUOUS)\n#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, WRITEABLE)\n#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, ALIGNED)\n\n#ifndef MAX\n#define MAX(a,b) (((a)>(b))?(a):(b))\n#endif\n#ifndef MIN\n#define MIN(a,b) (((a)<(b))?(a):(b))\n#endif\n\n/* Useful if a and b have to be evaluated. */\n\n#define tMAX(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_>_y_ ? _x_ : _y_}\n#define tMIN(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_<_y_ ? _x_ : _y_}\n\n#if defined(ALLOW_THREADS)\n#define BEGIN_THREADS_DEF PyThreadState *_save;\n#define BEGIN_THREADS _save = PyEval_SaveThread();\n#define END_THREADS PyEval_RestoreThread(_save);\n#define ALLOW_C_API_DEF PyGILState_STATE __save__;\n#define ALLOW_C_API __save__ = PyGILState_Ensure();\n#define DISABLE_C_API PyGILState_Release(__save__);\n#else\n#define BEGIN_THREADS_DEF\n#define BEGIN_THREADS\n#define END_THREADS\n#define ALLOW_C_API_DEF\n#define\tALLOW_C_API\n#define\tDISABLE_C_API\n#endif\n\n\n\n\ntypedef struct {\n PyObject_HEAD\n\tint nd_m1; /* number of dimensions - 1 */\n intp\t\t index, size;\n\tintp coordinates[MAX_DIMS];/* N-dimensional loop */\n intp dims_m1[MAX_DIMS]; /* ao->dimensions - 1 */\n\tintp strides[MAX_DIMS]; /* ao->strides or fake */\n\tintp backstrides[MAX_DIMS];/* how far to jump back */\n\tintp factors[MAX_DIMS]; /* shape factors */\n\tPyArrayObject *ao;\n\tchar *dataptr; /* pointer to current item*/\n Bool contiguous;\n} PyArrayIterObject;\n\n\n/* Iterator API */\n#define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type)\n\n#define PyArray_ITER_RESET(it) {\t\t\t\t\t\\\n\tit->index = 0;\t\t\t\t\t\t \\\n\tit->dataptr = it->ao->data;\t\t\t\t\t\\\n\tmemset(it->coordinates, 0, (it->nd_m1+1)*sizeof(intp));\t\t\\\n}\n\n#define _PyArray_ITER_NEXT1(it) {\t\t\\\n\t\tit->dataptr += it->strides[0];\t\\\n\t\tit->coordinates[0]++;\t\t\\\n\t}\n\n#define _PyArray_ITER_NEXT2(it) {\t\t\t\t\t\\\n\t\tif (it->coordinates[1] < it->dims_m1[1]) {\t\t\\\n\t\t\tit->coordinates[1]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->coordinates[1] = 0;\t\t\t\t\\\n\t\t\tit->coordinates[0]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[0] -\t\t\t\\\n\t\t\t\tit->backstrides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_NEXT(it) {\t\t\t\t\t\t\\\n\tit->index++;\t\t\t\t\t\t \\\n if (it->nd_m1 == 0) {\t\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT1(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse if (it->contiguous) it->dataptr += it->ao->descr->elsize; \\\n\telse if (it->nd_m1 == 1) {\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT2(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse {\t\t\t\t\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_ >= 0; _i_--) {\t\t\\\n\t\t\tif (it->coordinates[_i_] <\t\t\t\\\n\t\t\t it->dims_m1[_i_]) {\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_]++;\t\t\t\\\n\t\t\t\tit->dataptr += it->strides[_i_];\t\\\n\t\t\t\tbreak;\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t\telse {\t\t\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_] = 0;\t\t\\\n\t\t\t\tit->dataptr -= it->backstrides[_i_];\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_GOTO(it, destination) {\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tit->index = 0;\t\t\t\t\t\t\\\n\t\tit->dataptr = it->ao->data;\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_>=0; _i_--) {\t\t\t\\\n\t\t\tit->dataptr += destination[_i_] *\t\t\\\n\t\t\t\tit->strides[_i_];\t\t\t\\\n\t\t\tit->coordinates[_i_] = destination[_i_];\t\\\n\t\t\tit->index += destination[_i_] *\t\t\t\\\n\t\t\t\t( _i_==it->nd_m1 ? 1 :\t\t\t\\\n\t\t\t\t it->dims_m1[i+1]+1) ;\t\t \\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_GOTO1D(it, ind) { \\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tintp _lind_ = (intp) (ind);\t\t\t\t\\\n\t\tit->index = _lind_;\t\t\t\t\t\\\n if (it->nd_m1 == 0) { \\\n it->dataptr = it->ao->data + (ind) * \\\n it->strides[0]; \\\n } \\\n else if (it->contiguous) \\\n\t\t\tit->dataptr = it->ao->data + (ind) *\t\t\\\n\t\t\t\tit->ao->descr->elsize;\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->dataptr = it->ao->data;\t\t\t\\\n\t\t\tfor (_i_ = 0; _i_<=it->nd_m1; _i_++) {\t\t\\\n\t\t\t\tit->dataptr += (_lind_ / it->factors[_i_]) \\\n\t\t\t\t\t* it->strides[_i_];\t\t\\\n\t\t\t\t_lind_ %= it->factors[_i_];\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_DATA(it) ((PyArrayIterObject *)it)->dataptr\n\n\n/*\n Any object passed to PyArray_Broadcast must be binary compatible with\n this structure.\n*/\n\ntypedef struct {\n\tPyObject_HEAD\n\n\tint numiter; /* number of iters */\n\tintp size; /* broadcasted size */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* iterators */\n} PyArrayMultiIterObject;\n\n#define PyArray_MultiIter_RESET(multi) {\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index = 0;\t\t\t\t \\\n\t\tfor (_mi_ = 0; _mi_ < _mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_RESET(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_NEXT(multi) {\t\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index += 1;\t\t\t\t \\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_NEXT(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_GOTO(multi, dest) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO(_mul_->iters[_mi_], dest);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_GOTO1D(multi, ind) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO1D(_mul_->iters[_mi_], ind);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_DATA(multi, i) \\\n\t((PyArrayMultiIterObject *)multi)->iters[i]->dataptr\n\n#define PyArray_MultiIter_SIZE(multi) \\\n\t((PyArrayMultiIterObject *)multi)->size;\n\n\n/* Store the information needed for fancy-indexing over an array */\n\ntypedef struct {\n\tPyObject_HEAD\n\t/* Multi-iterator portion --- needs to be present in this order to\n\t work with PyArray_Broadcast */\n\n\tint numiter; /* number of index-array\n\t\t\t\t\t\t\t iterators */\n\tintp size; /* size of broadcasted\n\t\t\t\t\t\t\t result */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* index object\n\t\t\t\t\t\t\t iterators */\n\tPyArrayIterObject *ait; /* flat Iterator for\n\t\t\t\t\t\t\t underlying array */\n\n\t/* flat iterator for subspace (when numiter < nd) */\n\tPyArrayIterObject *subspace;\n\n\t/* if subspace iteration, then this is the array of\n\t axes in the underlying array represented by the\n\t index objects */\n\tint iteraxes[MAX_DIMS];\n\t/* if subspace iteration, the these are the coordinates\n\t to the start of the subspace.\n\t*/\n\tintp bscoord[MAX_DIMS];\n\n\tPyObject *indexobj; /* reference to\n\t\t\t\t\t\t\t creating obj */\n\tint view;\n\tint consec;\n\tchar *dataptr;\n\n} PyArrayMapIterObject;\n\n/* All sorts of useful ways to look into a PyArrayObject.\n These are the recommended over casting to PyArrayObject and accessing\n the members directly.\n */\n\n#define PyArray_NDIM(obj) (((PyArrayObject *)(obj))->nd)\n#define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || PyArray_CHKFLAGS(m, CONTIGUOUS) || \\\n\t\t\t\t PyArray_CHKFLAGS(m, FORTRAN))\n#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, FORTRAN) && (PyArray_NDIM(m) > 1))\n#define FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, FORTRAN) ? FORTRAN : 0))\n#define PyArray_DATA(obj) ((void *)(((PyArrayObject *)(obj))->data))\n#define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data)\n#define PyArray_DIMS(obj) (((PyArrayObject *)(obj))->dimensions)\n#define PyArray_STRIDES(obj) (((PyArrayObject *)(obj))->strides)\n#define PyArray_DIM(obj,n) (((PyArrayObject *)(obj))->dimensions[n])\n#define PyArray_STRIDE(obj,n) (((PyArrayObject *)(obj))->strides[n])\n#define PyArray_BASE(obj) (((PyArrayObject *)(obj))->base)\n#define PyArray_DESCR(obj) (((PyArrayObject *)(obj))->descr)\n#define PyArray_FLAGS(obj) (((PyArrayObject *)(obj))->flags)\n#define PyArray_ITEMSIZE(obj) (((PyArrayObject *)(obj))->descr->elsize)\n#define PyArray_TYPE(obj) (((PyArrayObject *)(obj))->descr->type_num)\n#define PyArray_GETITEM(obj,itemptr)\t\t\t\\\n\t((PyArrayObject *)(obj))->descr->f->getitem((char *)itemptr,\t\\\n\t\t\t\t\t\t (PyArrayObject *)obj);\n#define PyArray_SETITEM(obj,itemptr,v)\t\t\t\t\t\\\n\t(obj)->descr->f->setitem((PyObject *)v,(char *)(itemptr),\t\t\\\n\t\t\t (PyArrayObject *)(obj));\n\n\n#define PyTypeNum_ISBOOL(type) (type == PyArray_BOOL)\n#define PyTypeNum_ISUNSIGNED(type) ((type == PyArray_UBYTE) || \\\n\t\t\t\t (type == PyArray_USHORT) || \\\n\t\t\t\t (type == PyArray_UINT) ||\t\\\n\t\t\t\t (type == PyArray_ULONG) || \\\n\t\t\t\t (type == PyArray_ULONGLONG))\n\n#define PyTypeNum_ISSIGNED(type) ((type == PyArray_BYTE) ||\t\\\n\t\t\t (type == PyArray_SHORT) ||\t\\\n\t\t\t (type == PyArray_INT) ||\t\\\n\t\t\t (type == PyArray_LONG) ||\t\\\n\t\t\t (type == PyArray_LONGLONG))\n\n#define PyTypeNum_ISINTEGER(type) ((type >= PyArray_BYTE) &&\t\\\n\t\t\t\t(type <= PyArray_ULONGLONG))\n\n#define PyTypeNum_ISFLOAT(type) ((type >= PyArray_FLOAT) && \\\n\t\t\t (type <= PyArray_LONGDOUBLE))\n\n#define PyTypeNum_ISNUMBER(type) (type <= PyArray_CLONGDOUBLE)\n\n#define PyTypeNum_ISSTRING(type) ((type == PyArray_UCHAR) || \\\n\t\t\t (type == PyArray_UNICODE))\n\n#define PyTypeNum_ISCOMPLEX(type) ((type >= PyArray_CFLOAT) && \\\n\t\t\t\t(type <= PyArray_CLONGDOUBLE))\n\n#define PyTypeNum_ISPYTHON(type) ((type == PyArray_LONG) || \\\n\t\t\t\t (type == PyArray_DOUBLE) ||\t\\\n\t\t\t\t (type == PyArray_CDOUBLE) ||\t\\\n\t\t (type == PyArray_BOOL) || \\\n\t\t\t\t (type == PyArray_OBJECT ))\n\n#define PyTypeNum_ISFLEXIBLE(type) ((type>=PyArray_STRING) && \\\n\t\t\t\t (type<=PyArray_VOID))\n\n#define PyTypeNum_ISUSERDEF(type) ((type >= PyArray_USERDEF) && \\\n\t\t\t\t (type < PyArray_USERDEF+\\\n\t\t\t\t PyArray_NUMUSERTYPES))\n\n#define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \\\n PyTypeNum_ISUSERDEF(type))\n\n#define PyTypeNum_ISOBJECT(type) ((type) == PyArray_OBJECT)\n\n#define _PyADt(o) ((PyArray_Descr *)o)->type_num\n#define PyDescr_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj))\n#define PyDescr_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(_PyADt(obj))\n#define PyDescr_ISSIGNED(obj) PyTypeNum_ISSIGNED(_PyADt(obj))\n#define PyDescr_ISINTEGER(obj) PyTypeNum_ISINTEGER(_PyADt(obj))\n#define PyDescr_ISFLOAT(obj) PyTypeNum_ISFLOAT(_PyADt(obj))\n#define PyDescr_ISNUMBER(obj) PyTypeNum_ISNUMBER(_PyADt(obj))\n#define PyDescr_ISSTRING(obj) PyTypeNum_ISSTRING(_PyADt(obj))\n#define PyDescr_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(_PyADt(obj))\n#define PyDescr_ISPYTHON(obj) PyTypeNum_ISPYTHON(_PyADt(obj))\n#define PyDescr_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(_PyADt(obj))\n#define PyDescr_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(_PyADt(obj))\n#define PyDescr_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(_PyADt(obj))\n#define PyDescr_ISOBJECT(obj) PyTypeNum_ISOBJECT(_PyADt(obj))\n#undef _PyAD\n\n#define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))\n#define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))\n#define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))\n#define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))\n#define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))\n#define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))\n#define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj))\n#define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))\n#define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))\n#define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))\n#define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))\n\n#define PyArray_LITTLE '<'\n#define PyArray_BIG '>'\n#define PyArray_NATIVE '='\n#define PyArray_SWAP 's'\n#define PyArray_IGNORE '|'\n\n#ifdef WORDS_BIGENDIAN\n#define PyArray_NATBYTE PyArray_BIG\n#define PyArray_OPPBYTE PyArray_LITTLE\n#else\n#define PyArray_NATBYTE PyArray_LITTLE\n#define PyArray_OPPBYTE PyArray_BIG\n#endif\n\n#define PyArray_ISNBO(arg) ((arg) != PyArray_OPPBYTE)\n#define PyArray_IsNativeByteOrder PyArray_ISNBO\n#define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)\n\n#define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) &&\t\\\n\t\t\t\t PyArray_ISNOTSWAPPED(m))\n#define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS)\n#define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS_RO)\n#define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS)\n#define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS_RO)\n#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, BEHAVED_FLAGS)\n#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, ALIGNED)\n\n\n\n/* This is the form of the struct that's returned pointed by the\n PyCObject attribute of an array __array_struct__. See\n http://numeric.scipy.org/array_interface.html for the full\n documentation. */\ntypedef struct {\n int version; /* contains the integer 2 as a sanity check */\n int nd; /* number of dimensions */\n char typekind; /* kind in array --- character code of typestr */\n int itemsize; /* size of each element */\n int flags; /* how should be data interpreted. Valid\n flags are CONTIGUOUS (1), FORTRAN (2),\n ALIGNED (0x100), NOTSWAPPED (0x200), and\n WRITEABLE (0x400)*/\n intp *shape; /* A length-nd array of shape information */\n intp *strides; /* A length-nd array of stride information */\n void *data; /* A pointer to the first element of the array */\n} PyArrayInterface;\n\n/* Includes the \"function\" C-API -- these are all stored in a\n list of pointers --- one for each file\n The two lists are concatenated into one in multiarray.\n\n They are available as import_array()\n*/\n\n\n#include \"__multiarray_api.h\"\n\n\n/* C-API that requries previous API to be defined */\n\n#define PyArray_DescrCheck(op) ((op)->ob_type == &PyArrayDescr_Type)\n\n#define PyArray_Check(op) ((op)->ob_type == &PyArray_Type ||\t\t\\\n\t\t\t PyObject_TypeCheck((op), &PyArray_Type))\n#define PyArray_CheckExact(op) ((op)->ob_type == &PyArray_Type)\n\n#define PyArray_IsZeroDim(op) (PyArray_Check(op) && (PyArray_NDIM(op) == 0))\n#define PyArray_IsScalar(obj, cls)\t\t\t\t\\\n\t(PyObject_TypeCheck((obj), &Py##cls##ArrType_Type))\n#define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \\\n PyArray_IsZeroDim(m))\n#define PyArray_IsPythonScalar(obj) \\\n\t(PyInt_Check(obj) || PyFloat_Check(obj) || PyComplex_Check(obj) || \\\n\t PyLong_Check(obj) || PyBool_Check(obj) || PyString_Check(obj) || \\\n\t PyUnicode_Check(obj))\n#define PyArray_IsAnyScalar(obj)\t\t\t\t\t\\\n\t(PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))\n#define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \\\n\t\t\t\t PyArray_CheckScalar(obj))\n\n#define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? Py_INCREF(m), m : \\\n (PyArrayObject *)(PyArray_Copy(m)))\n\n#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))\n#define PyArray_NBYTES(m) (PyArray_ITEMSIZE(m) * PyArray_SIZE(m))\n#define PyArray_FROM_O(m) PyArray_FromAny(m, NULL, 0, 0, 0, NULL)\n#define PyArray_FROM_OF(m,flags) PyArray_CheckFromAny(m, NULL, 0, 0, flags, NULL)\n#define PyArray_FROM_OT(m,type) PyArray_FromAny(m, PyArray_DescrFromType(type), \\\n 0, 0, 0, NULL);\n#define PyArray_FROM_OTF(m, type, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \\\n (((flags) & ENSURECOPY) ? \\\n ((flags) | DEFAULT_FLAGS) : (flags)), NULL)\n#define PyArray_FROMANY(m, type, min, max, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \\\n (((flags) & ENSURECOPY) ? \\\n (flags) | DEFAULT_FLAGS : (flags)), NULL)\n\n#define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), (val), PyArray_NBYTES(obj))\n\n#define REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)\n#define MAX_ELSIZE 2*SIZEOF_LONGDOUBLE\n\n#define PyArray_ContiguousFromAny(op, type, min_depth, max_depth) \\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, DEFAULT_FLAGS, NULL)\n\n#define PyArray_EquivArrTypes(a1, a2)\t\t\t\t\t\\\n\tPyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))\n#define PyArray_EquivTypenums(typenum1, typenum2)\t\t\\\n\tPyArray_EquivTypes(PyArray_DescrFromType(typenum1),\t\\\n\t\t\t PyArray_DescrFromType(typenum2))\n\n#define PyArray_EquivByteorders(b1, b2) \\\n\t((b1 == b2) || (PyArray_ISNBO(b1) == PyArray_ISNBO(b2)))\n\n#define PyArray_SimpleNew(nd, dims, typenum) \\\n\tPyArray_New(&PyArray_Type, nd, dims, typenum, NULL, NULL, 0, 0, NULL)\n#define PyArray_SimpleNewFromData(nd, dims, typenum, data) \\\n PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, data, 0, CARRAY_FLAGS, NULL)\n#define PyArray_SimpleNewFromDescr(nd, dims, descr) \\\n\tPyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, NULL, NULL, 0, NULL)\n#define PyArray_EnsureAnyArray(obj) \\\n\t(PyArray_Check(obj) ? obj : PyArray_EnsureArray(obj))\n\n\n/* These might be faster without the dereferencing of obj\n going on inside -- of course an optimizing compiler should\n inline the constants inside a for loop making it a moot point\n*/\n\n#define PyArray_GETPTR1(obj, i) (void *)(PyArray_BYTES(obj) +\t\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0))\n\n#define PyArray_GETPTR2(obj, i, j) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1))\n\n#define PyArray_GETPTR3(obj, i, j, k) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\\n\t\t\t\t\t k*PyArray_STRIDE(obj, 2)) \\\n\n#define PyArray_GETPTR4(obj, i, j, k, l) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\\n\t\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\\n\t\t\t\t\t\t k*PyArray_STRIDE(obj, 2) + \\\n\t\t\t\t\t\t l*PyArray_STRIDE(obj, 3))\n\n#define PyArray_DESCR_REPLACE(descr) do {\t\\\n\t\tPyArray_Descr *_new_;\t\t\t\\\n\t\t_new_ = PyArray_DescrNew(descr);\t\\\n\t\tPy_XDECREF(descr);\t\t\t\\\n\t\tdescr = _new_;\t\t\t\t\\\n\t} while(0)\n\n/* Copy should always return contiguous array */\n#define PyArray_Copy(obj) PyArray_NewCopy(obj, 0)\n\n#define PyArray_FromObject(op, type, min_depth, max_depth)\t\t\\\n\tPyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, BEHAVED_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_ContiguousFromObject(op, type, min_depth, max_depth)\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_CopyFromObject(op, type, min_depth, max_depth)\t\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, ENSURECOPY | DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_Cast(mp, type_num) \\\n\tPyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)\n\n/* Compatibility with old Numeric stuff -- don't use in new code */\n\n#define PyArray_FromDimsAndData(nd, d, type, data) \\\n\tPyArray_FromDimsAndDataAndDescr(nd, d, PyArray_DescrFromType(type), \\\n\t\t\t\t\tdata)\n\n#define PyArray_UNSIGNED_TYPES\n#define PyArray_SBYTE PyArray_BYTE\n#define PyArray_CHAR PyArray_BYTE\n#define PyArray_CopyArray PyArray_CopyInto\n#define _PyArray_multiply_list PyArray_MultiplyIntList\n#define PyArray_ISSPACESAVER(m) FALSE\n#define PyScalarArray_Check PyArray_CheckScalar\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# undef CAT\n# undef CAT2\n# undef NS\n# undef longlong\n# undef ulonglong\n# undef Bool\n# undef longdouble\n# undef byte\n# undef ubyte\n# undef ushort\n# undef uint\n# undef ulong\n# undef cfloat\n# undef cdouble\n# undef clongdouble\n# undef Int8\n# undef UInt8\n# undef Int16\n# undef UInt16\n# undef Int32\n# undef UInt32\n# undef Int64\n# undef UInt64\n# undef Int128\n# undef UInt128\n# undef Int256\n# undef UInt256\n# undef Float16\n# undef Complex32\n# undef Float32\n# undef Complex64\n# undef Float64\n# undef Complex128\n# undef Float80\n# undef Complex160\n# undef Float96\n# undef Complex192\n# undef Float128\n# undef Complex256\n# undef intp\n# undef uintp\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* !Py_ARRAYOBJECT_H */\n", + "source_code_before": "\n/* This expects the following variables to be defined (besides\n the usual ones from pyconfig.h\n\n SIZEOF_LONG_DOUBLE -- sizeof(long double) or sizeof(double) if no\n long double is present on platform.\n CHAR_BIT -- number of bits in a char (usually 8)\n (should be in limits.h)\n*/\n\n#ifndef Py_ARRAYOBJECT_H\n#define Py_ARRAYOBJECT_H\n#ifdef __cplusplus\n#define CONFUSE_EMACS {\n#define CONFUSE_EMACS2 }\nextern \"C\" CONFUSE_EMACS\n#undef CONFUSE_EMACS\n#undef CONFUSE_EMACS2\n/* ... otherwise a semi-smart idententer (like emacs) tries to indent\n everything when you're typing */\n#endif\n#include \"config.h\"\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# define CAT2(x,y) x ## y\n# define CAT(x,y) CAT2(x,y)\n# define NS(name) CAT(PY_ARRAY_TYPES_PREFIX, name)\n# define longlong NS(longlong)\n# define ulonglong NS(ulonglong)\n# define Bool NS(Bool)\n# define longdouble NS(longdouble)\n# define byte NS(byte)\n# define ubyte NS(ubyte)\n# define ushort NS(ushort)\n# define uint NS(uint)\n# define ulong NS(ulong)\n# define cfloat NS(cfloat)\n# define cdouble NS(cdouble)\n# define clongdouble NS(clongdouble)\n# define Int8 NS(Int8)\n# define UInt8 NS(UInt8)\n# define Int16 NS(Int16)\n# define UInt16 NS(UInt16)\n# define Int32 NS(Int32)\n# define UInt32 NS(UInt32)\n# define Int64 NS(Int64)\n# define UInt64 NS(UInt64)\n# define Int128 NS(Int128)\n# define UInt128 NS(UInt128)\n# define Int256 NS(Int256)\n# define UInt256 NS(UInt256)\n# define Float16 NS(Float16)\n# define Complex32 NS(Complex32)\n# define Float32 NS(Float32)\n# define Complex64 NS(Complex64)\n# define Float64 NS(Float64)\n# define Complex128 NS(Complex128)\n# define Float80 NS(Float80)\n# define Complex160 NS(Complex160)\n# define Float96 NS(Float96)\n# define Complex192 NS(Complex192)\n# define Float128 NS(Float128)\n# define Complex256 NS(Complex256)\n# define intp NS(intp)\n# define uintp NS(uintp)\n#endif\n\n/* There are several places in the code where an array of dimensions is */\n/* allocated statically. This is the size of that static allocation. */\n/* The array creation itself could have arbitrary dimensions but\n * all the places where static allocation is used would need to\n * be changed to dynamic (including inside of structures)\n */\n\n#define MAX_DIMS 32\n\n/* Used for Converter Functions \"O&\" code in ParseTuple */\n#define PY_FAIL 0\n#define PY_SUCCEED 1\n\n /* Helpful to distinguish what is installed */\n#define NDARRAY_VERSION 0x00090702\n\n\t/* Some platforms don't define bool, long long, or long double.\n\t Handle that here.\n\t */\n\n#ifdef PY_LONG_LONG\ntypedef PY_LONG_LONG longlong;\ntypedef unsigned PY_LONG_LONG ulonglong;\n# ifdef _MSC_VER\n# define LONGLONG_FMT \"I64d\"\n# define ULONGLONG_FMT \"I64u\"\n# define LONGLONG_SUFFIX(x) (x##i64)\n# define ULONGLONG_SUFFIX(x) (x##Ui64)\n# else\n\t/* #define LONGLONG_FMT \"lld\" Another possible variant\n #define ULONGLONG_FMT \"llu\"\n\n\t #define LONGLONG_FMT \"qd\" -- BSD perhaps?\n\t #define ULONGLONG_FMT \"qu\"\n\t*/\n# define LONGLONG_FMT \"Ld\"\n# define ULONGLONG_FMT \"Lu\"\n# define LONGLONG_SUFFIX(x) (x##LL)\n# define ULONGLONG_SUFFIX(x) (x##ULL)\n# endif\n#else\ntypedef long longlong;\ntypedef unsigned long ulonglong;\n# define LONGLONG_SUFFIX(x) (x##L)\n# define ULONGLONG_SUFFIX(x) (x##UL)\n#endif\n\ntypedef unsigned char Bool;\n#ifndef FALSE\n#define FALSE 0\n#endif\n#ifndef TRUE\n#define TRUE 1\n#endif\n\n#if SIZEOF_LONG_DOUBLE==SIZEOF_DOUBLE\n\ttypedef double longdouble;\n #define LONGDOUBLE_FMT \"g\"\n#else\n\ttypedef long double longdouble;\n #define LONGDOUBLE_FMT \"Lg\"\n#endif\n\n#ifndef Py_USING_UNICODE\n#error Must use Python with unicode enabled. \n#endif\n\n\ntypedef signed char byte;\ntypedef unsigned char ubyte;\n#ifndef _BSD_SOURCE\ntypedef unsigned short ushort;\ntypedef unsigned int uint;\ntypedef unsigned long ulong;\n#endif\n\ntypedef struct { float real, imag; } cfloat;\ntypedef struct { double real, imag; } cdouble;\ntypedef struct {longdouble real, imag;} clongdouble;\n\nenum PyArray_TYPES { PyArray_BOOL=0,\n PyArray_BYTE, PyArray_UBYTE,\n\t\t PyArray_SHORT, PyArray_USHORT,\n\t\t PyArray_INT, PyArray_UINT,\n\t\t\tPyArray_LONG, PyArray_ULONG,\n PyArray_LONGLONG, PyArray_ULONGLONG,\n\t\t\tPyArray_FLOAT, PyArray_DOUBLE, PyArray_LONGDOUBLE,\n\t\t\tPyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CLONGDOUBLE,\n\t\t\tPyArray_OBJECT=17,\n PyArray_STRING, PyArray_UNICODE,\n\t\t\tPyArray_VOID,\n\t\t\tPyArray_NTYPES,\n\t\t\tPyArray_NOTYPE,\n\t\t\tPyArray_USERDEF=256 /* leave room for characters */\n};\n\n\t/* basetype array priority */\n#define PyArray_PRIORITY 0.0\n#define PyArray_BIG_PRIORITY 0.1\n\t/* default subtype priority */\n#define PyArray_SUBTYPE_PRIORITY 1.0\n\n\t/* How many floating point types are there */\n#define PyArray_NUM_FLOATTYPE 3\n\n\n\t/* We need to match intp to a signed integer of the same size as\n\t a pointer variable. uintp to the equivalent unsigned integer\n\t*/\n\n\n\t/* These characters correspond to the array type and the\n\t struct module */\n\n\t/* except 'p' -- signed integer for pointer type */\n\nenum PyArray_TYPECHAR { PyArray_BOOLLTR = '?',\n\t\t\tPyArray_BYTELTR = 'b',\n\t\t\tPyArray_UBYTELTR = 'B',\n\t\t\tPyArray_SHORTLTR = 'h',\n\t\t\tPyArray_USHORTLTR = 'H',\n\t\t\tPyArray_INTLTR = 'i',\n\t\t\tPyArray_UINTLTR = 'I',\n\t\t\tPyArray_LONGLTR = 'l',\n\t\t\tPyArray_ULONGLTR = 'L',\n\t\t\tPyArray_LONGLONGLTR = 'q',\n\t\t\tPyArray_ULONGLONGLTR = 'Q',\n\t\t\tPyArray_FLOATLTR = 'f',\n\t\t\tPyArray_DOUBLELTR = 'd',\n\t\t\tPyArray_LONGDOUBLELTR = 'g',\n\t\t\tPyArray_CFLOATLTR = 'F',\n\t\t\tPyArray_CDOUBLELTR = 'D',\n\t\t\tPyArray_CLONGDOUBLELTR = 'G',\n\t\t\tPyArray_OBJECTLTR = 'O',\n\t\t\tPyArray_STRINGLTR = 'S',\n\t\t\tPyArray_STRINGLTR2 = 'a',\n\t\t\tPyArray_UNICODELTR = 'U',\n\t\t PyArray_VOIDLTR = 'V',\n\n\t\t\t/* No Descriptor, just a define -- this let's\n\t\t\t Python users specify an array of integers\n\t\t\t large enough to hold a pointer on the platform*/\n\t\t\tPyArray_INTPLTR = 'p',\n\t\t\tPyArray_UINTPLTR = 'P',\n\n\t\t\tPyArray_GENBOOLLTR ='b',\n\t\t\tPyArray_SIGNEDLTR = 'i',\n\t\t\tPyArray_UNSIGNEDLTR = 'u',\n\t\t\tPyArray_FLOATINGLTR = 'f',\n\t\t\tPyArray_COMPLEXLTR = 'c'\n};\n\ntypedef enum {\n\tPyArray_QUICKSORT=0,\n\tPyArray_HEAPSORT=1,\n\tPyArray_MERGESORT=2,\n\tPyArray_TIMSORT=3 /* the sort Python uses -- specialized */\n} PyArray_SORTKIND;\n#define PyArray_NSORTS PyArray_TIMSORT + 1\n\n\ntypedef enum {\n\tPyArray_NOSCALAR=0,\n\tPyArray_BOOL_SCALAR=1,\n\tPyArray_INTPOS_SCALAR=2,\n\tPyArray_INTNEG_SCALAR=3,\n\tPyArray_FLOAT_SCALAR=4,\n\tPyArray_COMPLEX_SCALAR=5,\n\tPyArray_OBJECT_SCALAR=6,\n} PyArray_SCALARKIND;\n\n\t/* Define bit-width array types and typedefs */\n\n#define MAX_INT8 127\n#define MIN_INT8 -128\n#define MAX_UINT8 255\n#define MAX_INT16 32767\n#define MIN_INT16 -32768\n#define MAX_UINT16 65535\n#define MAX_INT32 2147483647\n#define MIN_INT32 (-MAX_INT32 - 1)\n#define MAX_UINT32 4294967295U\n#define MAX_INT64 LONGLONG_SUFFIX(9223372036854775807)\n#define MIN_INT64 (-MAX_INT64 - LONGLONG_SUFFIX(1))\n#define MAX_UINT64 ULONGLONG_SUFFIX(18446744073709551615)\n#define MAX_INT128 LONGLONG_SUFFIX(85070591730234615865843651857942052864)\n#define MIN_INT128 (-MAX_INT128 - LONGLONG_SUFFIX(1))\n#define MAX_UINT128 ULONGLONG_SUFFIX(170141183460469231731687303715884105728)\n#define MAX_INT256 LONGLONG_SUFFIX(57896044618658097711785492504343953926634992332820282019728792003956564819967)\n#define MIN_INT256 (-MAX_INT256 - LONGLONG_SUFFIX(1))\n#define MAX_UINT256 ULONGLONG_SUFFIX(115792089237316195423570985008687907853269984665640564039457584007913129639935)\n\n\t/* Need to find the number of bits for each type and\n\t make definitions accordingly.\n\n\t C states that sizeof(char) == 1 by definition\n\n\t So, just using the sizeof keyword won't help.\n\n\t It also looks like Python itself uses sizeof(char) quite a\n\t bit, which by definition should be 1 all the time.\n\n\t Idea: Make Use of CHAR_BIT which should tell us how many\n\t BITS per CHARACTER\n\t*/\n\n\t/* Include platform definitions -- These are in the C89/90 standard */\n#include \n#define MAX_BYTE SCHAR_MAX\n#define MIN_BYTE SCHAR_MIN\n#define MAX_UBYTE UCHAR_MAX\n#define MAX_SHORT SHRT_MAX\n#define MIN_SHORT SHRT_MIN\n#define MAX_USHORT USHRT_MAX\n#define MAX_INT INT_MAX\n#ifndef INT_MIN\n#define INT_MIN (-INT_MAX - 1)\n#endif\n#define MIN_INT INT_MIN\n#define MAX_UINT UINT_MAX\n#define MAX_LONG LONG_MAX\n#define MIN_LONG LONG_MIN\n#define MAX_ULONG ULONG_MAX\n\n#define SIZEOF_LONGDOUBLE SIZEOF_LONG_DOUBLE\n#define SIZEOF_LONGLONG SIZEOF_LONG_LONG\n#define BITSOF_BOOL sizeof(Bool)*CHAR_BIT\n#define BITSOF_CHAR CHAR_BIT\n#define BITSOF_SHORT (SIZEOF_SHORT*CHAR_BIT)\n#define BITSOF_INT (SIZEOF_INT*CHAR_BIT)\n#define BITSOF_LONG (SIZEOF_LONG*CHAR_BIT)\n#define BITSOF_LONGLONG (SIZEOF_LONGLONG*CHAR_BIT)\n#define BITSOF_FLOAT (SIZEOF_FLOAT*CHAR_BIT)\n#define BITSOF_DOUBLE (SIZEOF_DOUBLE*CHAR_BIT)\n#define BITSOF_LONGDOUBLE (SIZEOF_LONGDOUBLE*CHAR_BIT)\n\n\n#if BITSOF_LONG == 8\n#define PyArray_INT8 PyArray_LONG\n#define PyArray_UINT8 PyArray_ULONG\n\ttypedef long Int8;\n\ttypedef unsigned long UInt8;\n#define STRBITSOF_LONG \"8\"\n#elif BITSOF_LONG == 16\n#define PyArray_INT16 PyArray_LONG\n#define PyArray_UINT16 PyArray_ULONG\n\ttypedef long Int16;\n\ttypedef unsigned long UInt16;\n#define STRBITSOF_LONG \"16\"\n#elif BITSOF_LONG == 32\n#define PyArray_INT32 PyArray_LONG\n#define PyArray_UINT32 PyArray_ULONG\n\ttypedef long Int32;\n\ttypedef unsigned long UInt32;\n\ttypedef unsigned long PyArray_UCS4;\n#define STRBITSOF_LONG \"32\"\n#elif BITSOF_LONG == 64\n#define PyArray_INT64 PyArray_LONG\n#define PyArray_UINT64 PyArray_ULONG\n\ttypedef long Int64;\n\ttypedef unsigned long UInt64;\n#define STRBITSOF_LONG \"64\"\n#elif BITSOF_LONG == 128\n#define PyArray_INT128 PyArray_LONG\n#define PyArray_UINT128 PyArray_ULONG\n\ttypedef long Int128;\n\ttypedef unsigned long UInt128;\n#define STRBITSOF_LONG \"128\"\n#endif\n\n#if BITSOF_LONGLONG == 8\n# ifndef PyArray_INT8\n# define PyArray_INT8 PyArray_LONGLONG\n# define PyArray_UINT8 PyArray_ULONGLONG\n\ttypedef longlong Int8;\n\ttypedef ulonglong UInt8;\n# endif\n# define MAX_LONGLONG MAX_INT8\n# define MIN_LONGLONG MIN_INT8\n# define MAX_ULONGLONG MAX_UINT8\n#define STRBITSOF_LONGLONG \"8\"\n#elif BITSOF_LONGLONG == 16\n# ifndef PyArray_INT16\n# define PyArray_INT16 PyArray_LONGLONG\n# define PyArray_UINT16 PyArray_ULONGLONG\n\ttypedef longlong Int16;\n\ttypedef ulonglong UInt16;\n# endif\n# define MAX_LONGLONG MAX_INT16\n# define MIN_LONGLONG MIN_INT16\n# define MAX_ULONGLONG MAX_UINT16\n#define STRBITSOF_LONGLONG \"16\"\n#elif BITSOF_LONGLONG == 32\n# ifndef PyArray_INT32\n# define PyArray_INT32 PyArray_LONGLONG\n# define PyArray_UINT32 PyArray_ULONGLONG\n\ttypedef longlong Int32;\n\ttypedef ulonglong UInt32;\n\ttypedef ulonglong PyArray_UCS4;\n# endif\n# define MAX_LONGLONG MAX_INT32\n# define MIN_LONGLONG MIN_INT32\n# define MAX_ULONGLONG MAX_UINT32\n#define STRBITSOF_LONGLONG \"32\"\n#elif BITSOF_LONGLONG == 64\n# ifndef PyArray_INT64\n# define PyArray_INT64 PyArray_LONGLONG\n# define PyArray_UINT64 PyArray_ULONGLONG\n\ttypedef longlong Int64;\n\ttypedef ulonglong UInt64;\n# endif\n# define MAX_LONGLONG MAX_INT64\n# define MIN_LONGLONG MIN_INT64\n# define MAX_ULONGLONG MAX_UINT64\n#define STRBITSOF_LONGLONG \"64\"\n#elif BITSOF_LONGLONG == 128\n# ifndef PyArray_INT128\n# define PyArray_INT128 PyArray_LONGLONG\n# define PyArray_UINT128 PyArray_ULONGLONG\n\ttypedef longlong Int128;\n\ttypedef ulonglong UInt128;\n# endif\n# define MAX_LONGLONG MAX_INT128\n# define MIN_LONGLONG MIN_INT128\n# define MAX_ULONGLONG MAX_UINT128\n#define STRBITSOF_LONGLONG \"128\"\n#elif BITSOF_LONGLONG == 256\n# define PyArray_INT256 PyArray_LONGLONG\n# define PyArray_UINT256 PyArray_ULONGLONG\n\ttypedef longlong Int256;\n\ttypedef ulonglong UInt256;\n# define MAX_LONGLONG MAX_INT256\n# define MIN_LONGLONG MIN_INT256\n# define MAX_ULONGLONG MAX_UINT256\n#define STRBITSOF_LONGLONG \"256\"\n#endif\n\n#if BITSOF_INT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_INT\n#define PyArray_UINT8 PyArray_UINT\n\ttypedef int Int8;\n\ttypedef unsigned int UInt8;\n#endif\n#define STRBITSOF_INT \"8\"\n#elif BITSOF_INT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_INT\n#define PyArray_UINT16 PyArray_UINT\n\ttypedef int Int16;\n\ttypedef unsigned int UInt16;\n#endif\n#define STRBITSOF_INT \"16\"\n#elif BITSOF_INT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_INT\n#define PyArray_UINT32 PyArray_UINT\n\ttypedef int Int32;\n\ttypedef unsigned int UInt32;\n\ttypedef unsigned int PyArray_UCS4;\n#endif\n#define STRBITSOF_INT \"32\"\n#elif BITSOF_INT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_INT\n#define PyArray_UINT64 PyArray_UINT\n\ttypedef int Int64;\n\ttypedef unsigned int UInt64;\n#endif\n#define STRBITSOF_INT \"64\"\n#elif BITSOF_INT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_INT\n#define PyArray_UINT128 PyArray_UINT\n\ttypedef int Int128;\n\ttypedef unsigned int UInt128;\n#endif\n#define STRBITSOF_INT \"128\"\n#endif\n\n#if BITSOF_SHORT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_SHORT\n#define PyArray_UINT8 PyArray_USHORT\n\ttypedef short Int8;\n\ttypedef unsigned short UInt8;\n#endif\n#define STRBITSOF_SHORT \"8\"\n#elif BITSOF_SHORT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_SHORT\n#define PyArray_UINT16 PyArray_USHORT\n\ttypedef short Int16;\n\ttypedef unsigned short UInt16;\n#endif\n#define STRBITSOF_SHORT \"16\"\n#elif BITSOF_SHORT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_SHORT\n#define PyArray_UINT32 PyArray_USHORT\n\ttypedef short Int32;\n\ttypedef unsigned short UInt32;\n\ttypedef unsigned short PyArray_UCS4;\n#endif\n#define STRBITSOF_SHORT \"32\"\n#elif BITSOF_SHORT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_SHORT\n#define PyArray_UINT64 PyArray_USHORT\n\ttypedef short Int64;\n\ttypedef unsigned short UInt64;\n#endif\n#define STRBITSOF_SHORT \"64\"\n#elif BITSOF_SHORT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_SHORT\n#define PyArray_UINT128 PyArray_USHORT\n\ttypedef short Int128;\n\ttypedef unsigned short UInt128;\n#endif\n#define STRBITSOF_SHORT \"128\"\n#endif\n\n\n#if BITSOF_CHAR == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_BYTE\n#define PyArray_UINT8 PyArray_UBYTE\n\ttypedef signed char Int8;\n\ttypedef unsigned char UInt8;\n#endif\n#define STRBITSOF_CHAR \"8\"\n#elif BITSOF_CHAR == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_BYTE\n#define PyArray_UINT16 PyArray_UBYTE\n\ttypedef signed char Int16;\n\ttypedef unsigned char UInt16;\n#endif\n#define STRBITSOF_CHAR \"16\"\n#elif BITSOF_CHAR == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_BYTE\n#define PyArray_UINT32 PyArray_UBYTE\n\ttypedef signed char Int32;\n\ttypedef unsigned char UInt32;\n\ttypedef unsigned char PyArray_UCS4;\n#endif\n#define STRBITSOF_CHAR \"32\"\n#elif BITSOF_CHAR == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_BYTE\n#define PyArray_UINT64 PyArray_UBYTE\n\ttypedef signed char Int64;\n\ttypedef unsigned char UInt64;\n#endif\n#define STRBITSOF_CHAR \"64\"\n#elif BITSOF_CHAR == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_BYTE\n#define PyArray_UINT128 PyArray_UBYTE\n\ttypedef signed char Int128;\n\ttypedef unsigned char UInt128;\n#endif\n#define STRBITSOF_CHAR \"128\"\n#endif\n\n\n\n#if BITSOF_DOUBLE == 16\n#define STRBITSOF_DOUBLE \"16\"\n#define STRBITSOF_CDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_DOUBLE\n#define PyArray_COMPLEX32 PyArray_CDOUBLE\n\ttypedef double Float16;\n\ttypedef cdouble Complex32;\n#endif\n#elif BITSOF_DOUBLE == 32\n#define STRBITSOF_DOUBLE \"32\"\n#define STRBITSOF_CDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_DOUBLE\n#define PyArray_COMPLEX64 PyArray_CDOUBLE\n\ttypedef double Float32;\n\ttypedef cdouble Complex64;\n#endif\n#elif BITSOF_DOUBLE == 64\n#define STRBITSOF_DOUBLE \"64\"\n#define STRBITSOF_CDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_DOUBLE\n#define PyArray_COMPLEX128 PyArray_CDOUBLE\n\ttypedef double Float64;\n\ttypedef cdouble Complex128;\n#endif\n#elif BITSOF_DOUBLE == 80\n#define STRBITSOF_DOUBLE \"80\"\n#define STRBITSOF_CDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_DOUBLE\n#define PyArray_COMPLEX160 PyArray_CDOUBLE\n\ttypedef double Float80;\n\ttypedef cdouble Complex160;\n#endif\n#elif BITSOF_DOUBLE == 96\n#define STRBITSOF_DOUBLE \"96\"\n#define STRBITSOF_CDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_DOUBLE\n#define PyArray_COMPLEX192 PyArray_CDOUBLE\n\ttypedef double Float96;\n\ttypedef cdouble Complex192;\n#endif\n#elif BITSOF_DOUBLE == 128\n#define STRBITSOF_DOUBLE \"128\"\n#define STRBITSOF_CDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_DOUBLE\n#define PyArray_COMPLEX256 PyArray_CDOUBLE\n\ttypedef double Float128;\n\ttypedef cdouble Complex256;\n#endif\n#endif\n\n\n\n#if BITSOF_FLOAT == 16\n#define STRBITSOF_FLOAT \"16\"\n#define STRBITSOF_CFLOAT \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_FLOAT\n#define PyArray_COMPLEX32 PyArray_CFLOAT\n\ttypedef float Float16;\n\ttypedef cfloat Complex32;\n#endif\n#elif BITSOF_FLOAT == 32\n#define STRBITSOF_FLOAT \"32\"\n#define STRBITSOF_CFLOAT \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_FLOAT\n#define PyArray_COMPLEX64 PyArray_CFLOAT\n\ttypedef float Float32;\n\ttypedef cfloat Complex64;\n#endif\n#elif BITSOF_FLOAT == 64\n#define STRBITSOF_FLOAT \"64\"\n#define STRBITSOF_CFLOAT \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_FLOAT\n#define PyArray_COMPLEX128 PyArray_CFLOAT\n\ttypedef float Float64;\n\ttypedef cfloat Complex128;\n#endif\n#elif BITSOF_FLOAT == 80\n#define STRBITSOF_FLOAT \"80\"\n#define STRBITSOF_CFLOAT \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_FLOAT\n#define PyArray_COMPLEX160 PyArray_CFLOAT\n\ttypedef float Float80;\n\ttypedef cfloat Complex160;\n#endif\n#elif BITSOF_FLOAT == 96\n#define STRBITSOF_FLOAT \"96\"\n#define STRBITSOF_CFLOAT \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_FLOAT\n#define PyArray_COMPLEX192 PyArray_CFLOAT\n\ttypedef float Float96;\n\ttypedef cfloat Complex192;\n#endif\n#elif BITSOF_FLOAT == 128\n#define STRBITSOF_FLOAT \"128\"\n#define STRBITSOF_CFLOAT \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_FLOAT\n#define PyArray_COMPLEX256 PyArray_CFLOAT\n\ttypedef float Float128;\n\ttypedef cfloat Complex256;\n#endif\n#endif\n\n\n#if BITSOF_LONGDOUBLE == 16\n#define STRBITSOF_LONGDOUBLE \"16\"\n#define STRBITSOF_CLONGDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX32 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float16;\n\ttypedef clongdouble Complex32;\n#endif\n#elif BITSOF_LONGDOUBLE == 32\n#define STRBITSOF_LONGDOUBLE \"32\"\n#define STRBITSOF_CLONGDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX64 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float32;\n\ttypedef clongdouble Complex64;\n#endif\n#elif BITSOF_LONGDOUBLE == 64\n#define STRBITSOF_LONGDOUBLE \"64\"\n#define STRBITSOF_CLONGDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX128 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float64;\n\ttypedef clongdouble Complex128;\n#endif\n#elif BITSOF_LONGDOUBLE == 80\n#define STRBITSOF_LONGDOUBLE \"80\"\n#define STRBITSOF_CLONGDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX160 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float80;\n\ttypedef clongdouble Complex160;\n#endif\n#elif BITSOF_LONGDOUBLE == 96\n#define STRBITSOF_LONGDOUBLE \"96\"\n#define STRBITSOF_CLONGDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX192 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float96;\n\ttypedef clongdouble Complex192;\n#endif\n#elif BITSOF_LONGDOUBLE == 128\n#define STRBITSOF_LONGDOUBLE \"128\"\n#define STRBITSOF_CLONGDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX256 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float128;\n\ttypedef clongdouble Complex256;\n#endif\n#elif BITSOF_LONGDOUBLE == 256\n#define STRBITSOF_LONGDOUBLE \"256\"\n#define STRBITSOF_CLONGDOUBLE \"512\"\n#define PyArray_FLOAT256 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX512 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float256;\n\ttypedef clongdouble Complex512;\n#endif\n\n\t/* End of typedefs for numarray style bit-width names */\n\n/* This is to typedef Intp to the appropriate pointer size for this platform.\n * Py_intptr_t, Py_uintptr_t are defined in pyport.h. */\ntypedef Py_intptr_t intp;\ntypedef Py_uintptr_t uintp;\n#define SIZEOF_INTP SIZEOF_PY_INTPTR_T\n#define SIZEOF_UINTP SIZEOF_PY_INTPTR_T\n\n#if PY_VERSION_HEX >= 0x02050000\n#define _int_or_ssize_t Py_ssize_t\n#else\n#define _int_or_ssize_t int\n#endif\n\n#define INTP_FMT \"d\"\n\n#if SIZEOF_PY_INTPTR_T == SIZEOF_INT\n\t#define PyArray_INTP PyArray_INT\n\t#define PyArray_UINTP PyArray_UINT\n #define PyIntpArrType_Type PyIntArrType_Type\n #define PyUIntpArrType_Type PyUIntArrType_Type\n\t#define MAX_INTP MAX_INT\n\t#define MIN_INTP MIN_INT\n\t#define MAX_UINTP MAX_UINT\n#elif SIZEOF_PY_INTPTR_T == SIZEOF_LONG\n\t#define PyArray_INTP PyArray_LONG\n\t#define PyArray_UINTP PyArray_ULONG\n #define PyIntpArrType_Type PyLongArrType_Type\n #define PyUIntpArrType_Type PyULongArrType_Type\n\t#define MAX_INTP MAX_LONG\n\t#define MIN_INTP MIN_LONG\n\t#define MAX_UINTP MAX_ULONG\n #undef INTP_FMT\n #define INTP_FMT \"ld\"\n#elif defined(PY_LONG_LONG) && (SIZEOF_PY_INTPTR_T == SIZEOF_LONG_LONG)\n\t#define PyArray_INTP PyArray_LONGLONG\n\t#define PyArray_UINTP PyArray_ULONGLONG\n #define PyIntpArrType_Type PyLongLongArrType_Type\n #define PyUIntpArrType_Type PyULongLongArrType_Type\n\t#define MAX_INTP MAX_LONGLONG\n\t#define MIN_INTP MIN_LONGLONG\n\t#define MAX_UINTP MAX_ULONGLONG\n #undef INTP_FMT\n #define INTP_FMT \"Ld\"\n#endif\n\n#define ERR(str) fprintf(stderr, #str); fflush(stderr);\n#define ERR2(str) fprintf(stderr, str); fflush(stderr);\n\n /* Macros to define how array, and dimension/strides data is\n allocated.\n */\n\n /* Data buffer */\n#define PyDataMem_NEW(size) ((char *)malloc(size))\n /* #define PyArrayMem_NEW(size) PyMem_NEW(char, size)*/\n#define PyDataMem_FREE(ptr) free(ptr)\n /* #define PyArrayMem_FREE(ptr) PyMem_Free(ptr) */\n#define PyDataMem_RENEW(ptr,size) ((char *)realloc(ptr,size))\n\n#define PyArray_USE_PYMEM 0\n\n#if PyArray_USE_PYMEM == 1\n#define _pya_malloc PyObject_Malloc\n#define _pya_free PyObject_Free\n#define _pya_realloc PyObject_Realloc\n#else\n#define _pya_malloc malloc\n#define _pya_free free\n#define _pya_realloc realloc\n#endif\n\n/* Dimensions and strides */\n#define PyDimMem_NEW(size) ((intp *)_pya_malloc(size*sizeof(intp)))\n#define PyDimMem_FREE(ptr) _pya_free(ptr)\n#define PyDimMem_RENEW(ptr,size) ((intp *)_pya_realloc(ptr,size*sizeof(intp)))\n\n\n /* These must deal with unaligned and swapped data if necessary */\ntypedef PyObject * (PyArray_GetItemFunc) (void *, void *);\ntypedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);\n\ntypedef void (PyArray_CopySwapNFunc)(void *, void *, intp, int, int);\ntypedef void (PyArray_CopySwapFunc)(void *, void *, int, int);\ntypedef Bool (PyArray_NonzeroFunc)(void *, void *);\n\n\n /* These assume aligned and notswapped data -- a buffer will be\n used before or contiguous data will be obtained\n */\ntypedef int (PyArray_CompareFunc)(const void *, const void *, void *);\ntypedef int (PyArray_ArgFunc)(void*, intp, intp*, void *);\ntypedef void (PyArray_DotFunc)(void *, intp, void *, intp, void *, intp,\n\t\t\t void *);\ntypedef void (PyArray_VectorUnaryFunc)(void *, void *, intp, void *, void *);\ntypedef int (PyArray_ScanFunc)(FILE *, void *, void *, void *);\ntypedef int (PyArray_FromStrFunc)(char *, void *, char **, void *);\n\ntypedef int (PyArray_FillFunc)(void *, intp, void *);\n\ntypedef int (PyArray_SortFunc)(void *, intp, void *);\ntypedef int (PyArray_ArgSortFunc)(void *, intp *, intp, void *);\n\ntypedef int (PyArray_FillWithScalarFunc)(void *, intp, void *, void *);\n\ntypedef struct {\n intp *ptr;\n int len;\n} PyArray_Dims;\n\ntypedef struct {\n\t/* Functions to cast to all other standard types*/\n\tPyArray_VectorUnaryFunc *cast[PyArray_NTYPES];\n\n\t/* Functions to get and set items with standard\n\t Python types -- not array scalars */\n\tPyArray_GetItemFunc *getitem;\n\tPyArray_SetItemFunc *setitem;\n\n\t/* Copy and/or swap data. Memory areas may not overlap */\n\t/* Use memmove first if they might */\n\tPyArray_CopySwapNFunc *copyswapn;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Function to compare items */\n\tPyArray_CompareFunc *compare;\n\n\t/* Function to select largest */\n\tPyArray_ArgFunc *argmax;\n\n\t/* Function to compute dot product */\n\tPyArray_DotFunc\t*dotfunc;\n\n\t/* Function to scan an ASCII file and\n\t place a single value plus possible separator */\n\tPyArray_ScanFunc *scanfunc;\n\n\t/* Function to read a single value from a string */\n\t/* and adjust the pointer */\n\tPyArray_FromStrFunc *fromstr;\n\n\t/* Function to determine if data is zero or not */\n\tPyArray_NonzeroFunc *nonzero;\n\n\t/* Used for arange */\n\tPyArray_FillFunc *fill;\n\n\t/* Function to fill arrays with scalar values */\n\tPyArray_FillWithScalarFunc *fillwithscalar;\n\n\t/* Sorting functions */\n\tPyArray_SortFunc *sort[PyArray_NSORTS];\n\tPyArray_ArgSortFunc *argsort[PyArray_NSORTS];\n\n} PyArray_ArrFuncs;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tPyTypeObject *typeobj; /* the type object representing an\n\t\t\t\t intance of this type */\n\tchar kind; /* kind for this type */\n\tchar type; /* unique-character representing this type */\n\tchar byteorder; /* '>' (big), '<' (little), '|'\n\t\t\t\t (not-applicable), or '=' (native). */\n char hasobject; /* non-zero if it has object arrays in fields */\n\tint type_num; /* number representing this type */\n\tint elsize; /* element size for this type */\n\tint alignment; /* alignment needed for this type */\n\tstruct _arr_descr\t\t\t\t\t\\\n\t*subarray; /* Non-NULL if this type is\n\t\t\t\t is an array (C-contiguous)\n\t\t\t\t of some other type\n\t\t\t\t*/\n\tPyObject *fields; /* The fields dictionary for this type */\n\t /* For statically defined descr this\n\t\t\t\t is always Py_None */\n\n\tPyArray_ArrFuncs *f; /* a table of functions specific for each\n\t\t\t\t basic data descriptor */\n} PyArray_Descr;\n\ntypedef struct _arr_descr {\n\tPyArray_Descr *base;\n\tPyObject *shape; /* a tuple */\n} PyArray_ArrayDescr;\n\n\n/*\n The main array object structure. It is recommended to use the macros\n defined below (PyArray_DATA and friends) access fields here, instead\n of the members themselves.\n */\n\ntypedef struct PyArrayObject {\n\tPyObject_HEAD\n\tchar *data; /* pointer to raw data buffer */\n\tint nd; /* number of dimensions, also called ndim */\n\tintp *dimensions; /* size in each dimension */\n intp *strides; /* bytes to jump to get to the\n\t\t\t\t next element in each dimension */\n\tPyObject *base; /* This object should be decref'd\n\t\t\t\t upon deletion of array */\n\t /* For views it points to the original array */\n\t /* For creation from buffer object it points\n\t\t\t\t to an object that shold be decref'd on\n\t\t\t\t deletion */\n\t /* For UPDATEIFCOPY flag this is an array\n\t\t\t\t to-be-updated upon deletion of this one */\n\tPyArray_Descr *descr; /* Pointer to type structure */\n\tint flags; /* Flags describing array -- see below*/\n\tPyObject *weakreflist; /* For weakreferences */\n} PyArrayObject;\n\n\n#define fortran fortran_ /* For some compilers */\n\n/* Mirrors buffer object to ptr */\n\ntypedef struct {\n PyObject_HEAD\n PyObject *base;\n void *ptr;\n intp len;\n int flags;\n} PyArray_Chunk;\n\n/* Array flags */\n\n/* Means c-style contiguous (last index varies the fastest). The\n data elements right after each other. */\n#define CONTIGUOUS 0x0001\n/* set if array is a contiguous Fortran array: the first index\n varies the fastest in memory (strides array is reverse of\n C-contiguous array)*/\n#define FORTRAN 0x0002\n\n/*\n Note: all 0-d arrays are CONTIGUOUS and FORTRAN contiguous. If a\n 1-d array is CONTIGUOUS it is also FORTRAN contiguous\n*/\n\n/* If set, the array owns the data: it will be free'd when the array\n is deleted. */\n#define OWNDATA 0x0004\n#define OWN_DATA OWNDATA\n\n/* An array never has these three set; they're only used as parameter\n flags to the the various FromAny functions */\n/* Cause a cast to occur regardless of whether or not it is safe. */\n#define FORCECAST 0x0010\n/* Always copy the array. Returned arrays are always CONTIGUOUS, ALIGNED,\n and WRITEABLE. */\n#define ENSURECOPY 0x0020\n/* Make sure the returned array is an ndarray or a bigndarray */\n#define ENSUREARRAY 0x0040\n\n/* Array data is aligned on the appropiate memory address for the\n type stored (e.g., an array of doubles (8 bytes each) starts on\n a memory address that's a multiple of 8) */\n#define ALIGNED 0x0100\n/* Array data has the native endianness */\n#define NOTSWAPPED 0x0200\n/* Array data is writeable */\n#define WRITEABLE 0x0400\n/* If this flag is set, then base contains a pointer to an array of\n the same size that should be updated with the current contents of\n this array when this array is deallocated\n*/\n#define UPDATEIFCOPY 0x1000\n\n\n#define BEHAVED_FLAGS ALIGNED | WRITEABLE\n#define BEHAVED_NS_FLAGS ALIGNED | WRITEABLE | NOTSWAPPED\n#define CARRAY_FLAGS CONTIGUOUS | BEHAVED_FLAGS\n#define CARRAY_FLAGS_RO CONTIGUOUS | ALIGNED\n#define FARRAY_FLAGS FORTRAN | BEHAVED_FLAGS\n#define FARRAY_FLAGS_RO FORTRAN | ALIGNED\n#define DEFAULT_FLAGS CARRAY_FLAGS\n\n#define UPDATE_ALL_FLAGS CONTIGUOUS | FORTRAN | ALIGNED\n\n\n/* Size of internal buffers used for alignment */\n#define PyArray_BUFSIZE 10000\n#define PyArray_MIN_BUFSIZE 5\n#define PyArray_MAX_BUFSIZE 100000000\n\n/*\n * C API: consists of Macros and functions. The MACROS are defined here.\n */\n\n\n#define PyArray_CHKFLAGS(m, FLAGS) \\\n\t((((PyArrayObject *)(m))->flags & (FLAGS)) == (FLAGS))\n#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, CONTIGUOUS)\n#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, WRITEABLE)\n#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, ALIGNED)\n\n#ifndef MAX\n#define MAX(a,b) (((a)>(b))?(a):(b))\n#endif\n#ifndef MIN\n#define MIN(a,b) (((a)<(b))?(a):(b))\n#endif\n\n/* Useful if a and b have to be evaluated. */\n\n#define tMAX(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_>_y_ ? _x_ : _y_}\n#define tMIN(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_<_y_ ? _x_ : _y_}\n\n#if defined(ALLOW_THREADS)\n#define BEGIN_THREADS_DEF PyThreadState *_save;\n#define BEGIN_THREADS _save = PyEval_SaveThread();\n#define END_THREADS PyEval_RestoreThread(_save);\n#define ALLOW_C_API_DEF PyGILState_STATE __save__;\n#define ALLOW_C_API __save__ = PyGILState_Ensure();\n#define DISABLE_C_API PyGILState_Release(__save__);\n#else\n#define BEGIN_THREADS_DEF\n#define BEGIN_THREADS\n#define END_THREADS\n#define ALLOW_C_API_DEF\n#define\tALLOW_C_API\n#define\tDISABLE_C_API\n#endif\n\n\n\n\ntypedef struct {\n PyObject_HEAD\n\tint nd_m1; /* number of dimensions - 1 */\n intp\t\t index, size;\n\tintp coordinates[MAX_DIMS];/* N-dimensional loop */\n intp dims_m1[MAX_DIMS]; /* ao->dimensions - 1 */\n\tintp strides[MAX_DIMS]; /* ao->strides or fake */\n\tintp backstrides[MAX_DIMS];/* how far to jump back */\n\tintp factors[MAX_DIMS]; /* shape factors */\n\tPyArrayObject *ao;\n\tchar *dataptr; /* pointer to current item*/\n Bool contiguous;\n} PyArrayIterObject;\n\n\n/* Iterator API */\n#define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type)\n\n#define PyArray_ITER_RESET(it) {\t\t\t\t\t\\\n\tit->index = 0;\t\t\t\t\t\t \\\n\tit->dataptr = it->ao->data;\t\t\t\t\t\\\n\tmemset(it->coordinates, 0, (it->nd_m1+1)*sizeof(intp));\t\t\\\n}\n\n#define _PyArray_ITER_NEXT1(it) {\t\t\\\n\t\tit->dataptr += it->strides[0];\t\\\n\t\tit->coordinates[0]++;\t\t\\\n\t}\n\n#define _PyArray_ITER_NEXT2(it) {\t\t\t\t\t\\\n\t\tif (it->coordinates[1] < it->dims_m1[1]) {\t\t\\\n\t\t\tit->coordinates[1]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->coordinates[1] = 0;\t\t\t\t\\\n\t\t\tit->coordinates[0]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[0] -\t\t\t\\\n\t\t\t\tit->backstrides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_NEXT(it) {\t\t\t\t\t\t\\\n\tit->index++;\t\t\t\t\t\t \\\n if (it->nd_m1 == 0) {\t\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT1(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse if (it->contiguous) it->dataptr += it->ao->descr->elsize; \\\n\telse if (it->nd_m1 == 1) {\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT2(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse {\t\t\t\t\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_ >= 0; _i_--) {\t\t\\\n\t\t\tif (it->coordinates[_i_] <\t\t\t\\\n\t\t\t it->dims_m1[_i_]) {\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_]++;\t\t\t\\\n\t\t\t\tit->dataptr += it->strides[_i_];\t\\\n\t\t\t\tbreak;\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t\telse {\t\t\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_] = 0;\t\t\\\n\t\t\t\tit->dataptr -= it->backstrides[_i_];\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_GOTO(it, destination) {\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tit->index = 0;\t\t\t\t\t\t\\\n\t\tit->dataptr = it->ao->data;\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_>=0; _i_--) {\t\t\t\\\n\t\t\tit->dataptr += destination[_i_] *\t\t\\\n\t\t\t\tit->strides[_i_];\t\t\t\\\n\t\t\tit->coordinates[_i_] = destination[_i_];\t\\\n\t\t\tit->index += destination[_i_] *\t\t\t\\\n\t\t\t\t( _i_==it->nd_m1 ? 1 :\t\t\t\\\n\t\t\t\t it->dims_m1[i+1]+1) ;\t\t \\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_GOTO1D(it, ind) { \\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tintp _lind_ = (intp) (ind);\t\t\t\t\\\n\t\tit->index = _lind_;\t\t\t\t\t\\\n if (it->nd_m1 == 0) { \\\n it->dataptr = it->ao->data + (ind) * \\\n it->strides[0]; \\\n } \\\n else if (it->contiguous) \\\n\t\t\tit->dataptr = it->ao->data + (ind) *\t\t\\\n\t\t\t\tit->ao->descr->elsize;\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->dataptr = it->ao->data;\t\t\t\\\n\t\t\tfor (_i_ = 0; _i_<=it->nd_m1; _i_++) {\t\t\\\n\t\t\t\tit->dataptr += (_lind_ / it->factors[_i_]) \\\n\t\t\t\t\t* it->strides[_i_];\t\t\\\n\t\t\t\t_lind_ %= it->factors[_i_];\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_DATA(it) ((PyArrayIterObject *)it)->dataptr\n\n\n/*\n Any object passed to PyArray_Broadcast must be binary compatible with\n this structure.\n*/\n\ntypedef struct {\n\tPyObject_HEAD\n\n\tint numiter; /* number of iters */\n\tintp size; /* broadcasted size */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* iterators */\n} PyArrayMultiIterObject;\n\n#define PyArray_MultiIter_RESET(multi) {\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index = 0;\t\t\t\t \\\n\t\tfor (_mi_ = 0; _mi_ < _mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_RESET(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_NEXT(multi) {\t\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index += 1;\t\t\t\t \\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_NEXT(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_GOTO(multi, dest) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO(_mul_->iters[_mi_], dest);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_GOTO1D(multi, ind) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO1D(_mul_->iters[_mi_], ind);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_DATA(multi, i) \\\n\t((PyArrayMultiIterObject *)multi)->iters[i]->dataptr\n\n#define PyArray_MultiIter_SIZE(multi) \\\n\t((PyArrayMultiIterObject *)multi)->size;\n\n\n/* Store the information needed for fancy-indexing over an array */\n\ntypedef struct {\n\tPyObject_HEAD\n\t/* Multi-iterator portion --- needs to be present in this order to\n\t work with PyArray_Broadcast */\n\n\tint numiter; /* number of index-array\n\t\t\t\t\t\t\t iterators */\n\tintp size; /* size of broadcasted\n\t\t\t\t\t\t\t result */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* index object\n\t\t\t\t\t\t\t iterators */\n\tPyArrayIterObject *ait; /* flat Iterator for\n\t\t\t\t\t\t\t underlying array */\n\n\t/* flat iterator for subspace (when numiter < nd) */\n\tPyArrayIterObject *subspace;\n\n\t/* if subspace iteration, then this is the array of\n\t axes in the underlying array represented by the\n\t index objects */\n\tint iteraxes[MAX_DIMS];\n\t/* if subspace iteration, the these are the coordinates\n\t to the start of the subspace.\n\t*/\n\tintp bscoord[MAX_DIMS];\n\n\tPyObject *indexobj; /* reference to\n\t\t\t\t\t\t\t creating obj */\n\tint view;\n\tint consec;\n\tchar *dataptr;\n\n} PyArrayMapIterObject;\n\n/* All sorts of useful ways to look into a PyArrayObject.\n These are the recommended over casting to PyArrayObject and accessing\n the members directly.\n */\n\n#define PyArray_NDIM(obj) (((PyArrayObject *)(obj))->nd)\n#define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || PyArray_CHKFLAGS(m, CONTIGUOUS) || \\\n\t\t\t\t PyArray_CHKFLAGS(m, FORTRAN))\n#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, FORTRAN) && (PyArray_NDIM(m) > 1))\n#define FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, FORTRAN) ? FORTRAN : 0))\n#define PyArray_DATA(obj) ((void *)(((PyArrayObject *)(obj))->data))\n#define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data)\n#define PyArray_DIMS(obj) (((PyArrayObject *)(obj))->dimensions)\n#define PyArray_STRIDES(obj) (((PyArrayObject *)(obj))->strides)\n#define PyArray_DIM(obj,n) (((PyArrayObject *)(obj))->dimensions[n])\n#define PyArray_STRIDE(obj,n) (((PyArrayObject *)(obj))->strides[n])\n#define PyArray_BASE(obj) (((PyArrayObject *)(obj))->base)\n#define PyArray_DESCR(obj) (((PyArrayObject *)(obj))->descr)\n#define PyArray_FLAGS(obj) (((PyArrayObject *)(obj))->flags)\n#define PyArray_ITEMSIZE(obj) (((PyArrayObject *)(obj))->descr->elsize)\n#define PyArray_TYPE(obj) (((PyArrayObject *)(obj))->descr->type_num)\n#define PyArray_GETITEM(obj,itemptr)\t\t\t\\\n\t((PyArrayObject *)(obj))->descr->f->getitem((char *)itemptr,\t\\\n\t\t\t\t\t\t (PyArrayObject *)obj);\n#define PyArray_SETITEM(obj,itemptr,v)\t\t\t\t\t\\\n\t(obj)->descr->f->setitem((PyObject *)v,(char *)(itemptr),\t\t\\\n\t\t\t (PyArrayObject *)(obj));\n\n\n#define PyTypeNum_ISBOOL(type) (type == PyArray_BOOL)\n#define PyTypeNum_ISUNSIGNED(type) ((type == PyArray_UBYTE) || \\\n\t\t\t\t (type == PyArray_USHORT) || \\\n\t\t\t\t (type == PyArray_UINT) ||\t\\\n\t\t\t\t (type == PyArray_ULONG) || \\\n\t\t\t\t (type == PyArray_ULONGLONG))\n\n#define PyTypeNum_ISSIGNED(type) ((type == PyArray_BYTE) ||\t\\\n\t\t\t (type == PyArray_SHORT) ||\t\\\n\t\t\t (type == PyArray_INT) ||\t\\\n\t\t\t (type == PyArray_LONG) ||\t\\\n\t\t\t (type == PyArray_LONGLONG))\n\n#define PyTypeNum_ISINTEGER(type) ((type >= PyArray_BYTE) &&\t\\\n\t\t\t\t(type <= PyArray_ULONGLONG))\n\n#define PyTypeNum_ISFLOAT(type) ((type >= PyArray_FLOAT) && \\\n\t\t\t (type <= PyArray_LONGDOUBLE))\n\n#define PyTypeNum_ISNUMBER(type) (type <= PyArray_CLONGDOUBLE)\n\n#define PyTypeNum_ISSTRING(type) ((type == PyArray_UCHAR) || \\\n\t\t\t (type == PyArray_UNICODE))\n\n#define PyTypeNum_ISCOMPLEX(type) ((type >= PyArray_CFLOAT) && \\\n\t\t\t\t(type <= PyArray_CLONGDOUBLE))\n\n#define PyTypeNum_ISPYTHON(type) ((type == PyArray_LONG) || \\\n\t\t\t\t (type == PyArray_DOUBLE) ||\t\\\n\t\t\t\t (type == PyArray_CDOUBLE) ||\t\\\n\t\t (type == PyArray_BOOL) || \\\n\t\t\t\t (type == PyArray_OBJECT ))\n\n#define PyTypeNum_ISFLEXIBLE(type) ((type>=PyArray_STRING) && \\\n\t\t\t\t (type<=PyArray_VOID))\n\n#define PyTypeNum_ISUSERDEF(type) ((type >= PyArray_USERDEF) && \\\n\t\t\t\t (type < PyArray_USERDEF+\\\n\t\t\t\t PyArray_NUMUSERTYPES))\n\n#define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \\\n PyTypeNum_ISUSERDEF(type))\n\n#define PyTypeNum_ISOBJECT(type) ((type) == PyArray_OBJECT)\n\n#define _PyADt(o) ((PyArray_Descr *)o)->type_num\n#define PyDescr_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj))\n#define PyDescr_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(_PyADt(obj))\n#define PyDescr_ISSIGNED(obj) PyTypeNum_ISSIGNED(_PyADt(obj))\n#define PyDescr_ISINTEGER(obj) PyTypeNum_ISINTEGER(_PyADt(obj))\n#define PyDescr_ISFLOAT(obj) PyTypeNum_ISFLOAT(_PyADt(obj))\n#define PyDescr_ISNUMBER(obj) PyTypeNum_ISNUMBER(_PyADt(obj))\n#define PyDescr_ISSTRING(obj) PyTypeNum_ISSTRING(_PyADt(obj))\n#define PyDescr_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(_PyADt(obj))\n#define PyDescr_ISPYTHON(obj) PyTypeNum_ISPYTHON(_PyADt(obj))\n#define PyDescr_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(_PyADt(obj))\n#define PyDescr_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(_PyADt(obj))\n#define PyDescr_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(_PyADt(obj))\n#define PyDescr_ISOBJECT(obj) PyTypeNum_ISOBJECT(_PyADt(obj))\n#undef _PyAD\n\n#define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))\n#define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))\n#define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))\n#define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))\n#define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))\n#define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))\n#define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj))\n#define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))\n#define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))\n#define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))\n#define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))\n\n#define PyArray_LITTLE '<'\n#define PyArray_BIG '>'\n#define PyArray_NATIVE '='\n#define PyArray_SWAP 's'\n#define PyArray_IGNORE '|'\n\n#ifdef WORDS_BIGENDIAN\n#define PyArray_NATBYTE PyArray_BIG\n#define PyArray_OPPBYTE PyArray_LITTLE\n#else\n#define PyArray_NATBYTE PyArray_LITTLE\n#define PyArray_OPPBYTE PyArray_BIG\n#endif\n\n#define PyArray_ISNBO(arg) ((arg) != PyArray_OPPBYTE)\n#define PyArray_IsNativeByteOrder PyArray_ISNBO\n#define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)\n\n#define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) &&\t\\\n\t\t\t\t PyArray_ISNOTSWAPPED(m))\n#define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS)\n#define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS_RO)\n#define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS)\n#define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS_RO)\n#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, BEHAVED_FLAGS)\n#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, ALIGNED)\n\n\n\n/* This is the form of the struct that's returned pointed by the\n PyCObject attribute of an array __array_struct__. See\n http://numeric.scipy.org/array_interface.html for the full\n documentation. */\ntypedef struct {\n int version; /* contains the integer 2 as a sanity check */\n int nd; /* number of dimensions */\n char typekind; /* kind in array --- character code of typestr */\n int itemsize; /* size of each element */\n int flags; /* how should be data interpreted. Valid\n flags are CONTIGUOUS (1), FORTRAN (2),\n ALIGNED (0x100), NOTSWAPPED (0x200), and\n WRITEABLE (0x400)*/\n intp *shape; /* A length-nd array of shape information */\n intp *strides; /* A length-nd array of stride information */\n void *data; /* A pointer to the first element of the array */\n} PyArrayInterface;\n\n/* Includes the \"function\" C-API -- these are all stored in a\n list of pointers --- one for each file\n The two lists are concatenated into one in multiarray.\n\n They are available as import_array()\n*/\n\n\n#include \"__multiarray_api.h\"\n\n\n/* C-API that requries previous API to be defined */\n\n#define PyArray_DescrCheck(op) ((op)->ob_type == &PyArrayDescr_Type)\n\n#define PyArray_Check(op) ((op)->ob_type == &PyArray_Type ||\t\t\\\n\t\t\t PyObject_TypeCheck((op), &PyArray_Type))\n#define PyArray_CheckExact(op) ((op)->ob_type == &PyArray_Type)\n\n#define PyArray_IsZeroDim(op) (PyArray_Check(op) && (PyArray_NDIM(op) == 0))\n#define PyArray_IsScalar(obj, cls)\t\t\t\t\\\n\t(PyObject_TypeCheck((obj), &Py##cls##ArrType_Type))\n#define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \\\n PyArray_IsZeroDim(m))\n#define PyArray_IsPythonScalar(obj) \\\n\t(PyInt_Check(obj) || PyFloat_Check(obj) || PyComplex_Check(obj) || \\\n\t PyLong_Check(obj) || PyBool_Check(obj) || PyString_Check(obj) || \\\n\t PyUnicode_Check(obj))\n#define PyArray_IsAnyScalar(obj)\t\t\t\t\t\\\n\t(PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))\n#define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \\\n\t\t\t\t PyArray_CheckScalar(obj))\n\n#define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? Py_INCREF(m), m : \\\n (PyArrayObject *)(PyArray_Copy(m)))\n\n#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))\n#define PyArray_NBYTES(m) (PyArray_ITEMSIZE(m) * PyArray_SIZE(m))\n#define PyArray_FROM_O(m) PyArray_FromAny(m, NULL, 0, 0, 0, NULL)\n#define PyArray_FROM_OF(m,flags) PyArray_CheckFromAny(m, NULL, 0, 0, flags, NULL)\n#define PyArray_FROM_OT(m,type) PyArray_FromAny(m, PyArray_DescrFromType(type), \\\n 0, 0, 0, NULL);\n#define PyArray_FROM_OTF(m, type, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \\\n (((flags) & ENSURECOPY) ? \\\n ((flags) | DEFAULT_FLAGS) : (flags)), NULL)\n#define PyArray_FROMANY(m, type, min, max, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \\\n (((flags) & ENSURECOPY) ? \\\n (flags) | DEFAULT_FLAGS : (flags)), NULL)\n\n#define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), (val), PyArray_NBYTES(obj))\n\n#define REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)\n#define MAX_ELSIZE 2*SIZEOF_LONGDOUBLE\n\n#define PyArray_ContiguousFromAny(op, type, min_depth, max_depth) \\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, DEFAULT_FLAGS, NULL)\n\n#define PyArray_EquivArrTypes(a1, a2)\t\t\t\t\t\\\n\tPyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))\n#define PyArray_EquivTypenums(typenum1, typenum2)\t\t\\\n\tPyArray_EquivTypes(PyArray_DescrFromType(typenum1),\t\\\n\t\t\t PyArray_DescrFromType(typenum2))\n\n#define PyArray_EquivByteorders(b1, b2) \\\n\t((b1 == b2) || (PyArray_ISNBO(b1) == PyArray_ISNBO(b2)))\n\n#define PyArray_SimpleNew(nd, dims, typenum) \\\n\tPyArray_New(&PyArray_Type, nd, dims, typenum, NULL, NULL, 0, 0, NULL)\n#define PyArray_SimpleNewFromData(nd, dims, typenum, data) \\\n PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, data, 0, CARRAY_FLAGS, NULL)\n#define PyArray_SimpleNewFromDescr(nd, dims, descr) \\\n\tPyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, NULL, NULL, 0, NULL)\n#define PyArray_EnsureAnyArray(obj) \\\n\t(PyArray_Check(obj) ? obj : PyArray_EnsureArray(obj))\n\n\n/* These might be faster without the dereferencing of obj\n going on inside -- of course an optimizing compiler should\n inline the constants inside a for loop making it a moot point\n*/\n\n#define PyArray_GETPTR1(obj, i) (void *)(PyArray_BYTES(obj) +\t\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0))\n\n#define PyArray_GETPTR2(obj, i, j) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1))\n\n#define PyArray_GETPTR3(obj, i, j, k) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\\n\t\t\t\t\t k*PyArray_STRIDE(obj, 2)) \\\n\n#define PyArray_GETPTR4(obj, i, j, k, l) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\\n\t\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\\n\t\t\t\t\t\t k*PyArray_STRIDE(obj, 2) + \\\n\t\t\t\t\t\t l*PyArray_STRIDE(obj, 3))\n\n#define PyArray_DESCR_REPLACE(descr) do {\t\\\n\t\tPyArray_Descr *_new_;\t\t\t\\\n\t\t_new_ = PyArray_DescrNew(descr);\t\\\n\t\tPy_XDECREF(descr);\t\t\t\\\n\t\tdescr = _new_;\t\t\t\t\\\n\t} while(0)\n\n/* Copy should always return contiguous array */\n#define PyArray_Copy(obj) PyArray_NewCopy(obj, 0)\n\n#define PyArray_FromObject(op, type, min_depth, max_depth)\t\t\\\n\tPyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, BEHAVED_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_ContiguousFromObject(op, type, min_depth, max_depth)\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_CopyFromObject(op, type, min_depth, max_depth)\t\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, ENSURECOPY | DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_Cast(mp, type_num) \\\n\tPyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)\n\n/* Compatibility with old Numeric stuff -- don't use in new code */\n\n#define PyArray_FromDimsAndData(nd, d, type, data) \\\n\tPyArray_FromDimsAndDataAndDescr(nd, d, PyArray_DescrFromType(type), \\\n\t\t\t\t\tdata)\n\n#define PyArray_UNSIGNED_TYPES\n#define PyArray_SBYTE PyArray_BYTE\n#define PyArray_CHAR PyArray_BYTE\n#define PyArray_CopyArray PyArray_CopyInto\n#define _PyArray_multiply_list PyArray_MultiplyIntList\n#define PyArray_ISSPACESAVER(m) FALSE\n#define PyScalarArray_Check PyArray_CheckScalar\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# undef CAT\n# undef CAT2\n# undef NS\n# undef longlong\n# undef ulonglong\n# undef Bool\n# undef longdouble\n# undef byte\n# undef ubyte\n# undef ushort\n# undef uint\n# undef ulong\n# undef cfloat\n# undef cdouble\n# undef clongdouble\n# undef Int8\n# undef UInt8\n# undef Int16\n# undef UInt16\n# undef Int32\n# undef UInt32\n# undef Int64\n# undef UInt64\n# undef Int128\n# undef UInt128\n# undef Int256\n# undef UInt256\n# undef Float16\n# undef Complex32\n# undef Float32\n# undef Complex64\n# undef Float64\n# undef Complex128\n# undef Float80\n# undef Complex160\n# undef Float96\n# undef Complex192\n# undef Float128\n# undef Complex256\n# undef intp\n# undef uintp\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* !Py_ARRAYOBJECT_H */\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": 305, + "complexity": 0, + "token_count": 1429, + "diff_parsed": { + "added": [ + "#define NDARRAY_VERSION 0x00090703", + "typedef enum {", + "\tPyArray_DONTCARE=-1,", + "\tPyArray_FALSE=0,", + "\tPyArray_TRUE=1,", + "} PyArray_CONDITION;", + "" + ], + "deleted": [ + "#define NDARRAY_VERSION 0x00090702" + ] + } + }, + { + "old_path": "numpy/core/numeric.py", + "new_path": "numpy/core/numeric.py", + "filename": "numeric.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -107,20 +107,20 @@ def extend_all(module):\n lexsort = multiarray.lexsort\n \n \n-def asarray(a, dtype=None, fortran=False, ndmin=0):\n+def asarray(a, dtype=None, fortran=None, ndmin=0):\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, ndmin=ndmin)\n \n-def asanyarray(a, dtype=None, copy=False, fortran=False, ndmin=0):\n+def asanyarray(a, dtype=None, copy=False, fortran=None, ndmin=0):\n \"\"\"will pass subclasses through...\n \"\"\"\n return array(a, dtype, copy=copy, fortran=fortran, subok=1, ndmin=ndmin)\n \n def isfortran(a):\n- return a.flags['FNC']\n+ return a.flags.fnc\n \n _mode_from_name_dict = {'v': 0,\n 's' : 1,\n", + "added_lines": 3, + "deleted_lines": 3, + "source_code": "__all__ = ['newaxis', 'ndarray', 'flatiter', 'ufunc',\n 'arange', 'array', 'zeros', 'empty', 'broadcast', 'dtype',\n 'fromstring', 'fromfile', 'frombuffer','newbuffer',\n 'getbuffer',\n 'where', 'concatenate', 'fastCopyAndTranspose', 'lexsort',\n 'register_dtype', 'set_numeric_ops', 'can_cast',\n 'asarray', 'asanyarray', 'isfortran', 'empty_like', 'zeros_like',\n 'correlate', 'convolve', 'inner', 'dot', 'outer', 'vdot',\n 'alterdot', 'restoredot', 'cross',\n 'array2string', 'get_printoptions', 'set_printoptions',\n 'array_repr', 'array_str', 'set_string_function',\n 'little_endian',\n 'indices', 'fromfunction',\n 'load', 'loads', 'isscalar', 'binary_repr', 'base_repr',\n 'ones', 'identity', 'allclose',\n 'seterr', 'geterr', 'setbufsize', 'getbufsize',\n 'seterrcall', 'geterrcall',\n 'Inf', 'inf', 'infty', 'Infinity',\n 'nan', 'NaN', 'False_', 'True_']\n\nimport sys\nimport multiarray\nimport umath\nfrom umath import *\nimport numerictypes\nfrom numerictypes import *\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 try:\n return zeros(a.shape, a.dtype, a.flags.fnc)\n except AttributeError:\n try:\n wrap = a.__array_wrap__\n except AttributeError:\n wrap = None\n a = asarray(a)\n res = zeros(a.shape, a.dtype)\n if wrap:\n res = wrap(res)\n return res\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 try:\n return empty(a.shape, a.dtype, a.flags.fnc)\n except AttributeError:\n try:\n wrap = a.__array_wrap__\n except AttributeError:\n wrap = None\n a = asarray(a)\n res = empty(a.shape, a.dtype)\n if wrap:\n res = wrap(res)\n return res\n\n# end Fernando's utilities\n\ndef extend_all(module):\n adict = {}\n for a in __all__:\n adict[a] = 1\n try:\n mall = getattr(module, '__all__')\n except AttributeError:\n mall = [k for k in module.__dict__.keys() if not k.startswith('_')]\n for a in mall:\n if a not in adict:\n __all__.append(a)\n\nextend_all(umath)\nextend_all(numerictypes)\n\nnewaxis = None\n\nndarray = multiarray.ndarray\nflatiter = multiarray.flatiter\nbroadcast = multiarray.broadcast\ndtype = multiarray.dtype\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\nnewbuffer = multiarray.newbuffer\ngetbuffer = multiarray.getbuffer\nwhere = multiarray.where\nconcatenate = multiarray.concatenate\nfastCopyAndTranspose = multiarray._fastCopyAndTranspose\nregister_dtype = multiarray.register_dtype\nset_numeric_ops = multiarray.set_numeric_ops\ncan_cast = multiarray.can_cast\nlexsort = multiarray.lexsort\n\n\ndef asarray(a, dtype=None, fortran=None, ndmin=0):\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, ndmin=ndmin)\n\ndef asanyarray(a, dtype=None, copy=False, fortran=None, ndmin=0):\n \"\"\"will pass subclasses through...\n \"\"\"\n return array(a, dtype, copy=copy, fortran=fortran, subok=1, ndmin=ndmin)\n\ndef isfortran(a):\n return a.flags.fnc\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 multiarray.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 _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, axis=None):\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 if axis is not None:\n axisa,axisb,axisc=(axis,)*3\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.type 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.type.__name__[:-6]\n lf = ''\n if issubclass(arr.dtype.type, flexible):\n typename = str(arr.dtype)\n lf = '\\n'+' '*len(\"array(\")\n return cName + \"(%s, %sdtype=%s)\" % (lst, lf, 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, ' ', \"\", str)\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\ndef isscalar(num):\n if isinstance(num, generic):\n return True\n else:\n return type(num) in ScalarType\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 import math\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\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# 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 a = empty(shape, dtype, fortran)\n a.fill(1)\n # Above is faster now after addition of fast loops.\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 d.ravel().all()\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 umath.update_use_defaults()\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_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\",\n 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 umath.update_use_defaults()\n\n# set the default values\n_setdef()\n\nInf = inf = infty = Infinity = PINF\nnan = NaN = NAN\nFalse_ = bool_(False)\nTrue_ = bool_(True)\n\nimport oldnumeric\nfrom oldnumeric import *\nextend_all(oldnumeric)\n", + "source_code_before": "__all__ = ['newaxis', 'ndarray', 'flatiter', 'ufunc',\n 'arange', 'array', 'zeros', 'empty', 'broadcast', 'dtype',\n 'fromstring', 'fromfile', 'frombuffer','newbuffer',\n 'getbuffer',\n 'where', 'concatenate', 'fastCopyAndTranspose', 'lexsort',\n 'register_dtype', 'set_numeric_ops', 'can_cast',\n 'asarray', 'asanyarray', 'isfortran', 'empty_like', 'zeros_like',\n 'correlate', 'convolve', 'inner', 'dot', 'outer', 'vdot',\n 'alterdot', 'restoredot', 'cross',\n 'array2string', 'get_printoptions', 'set_printoptions',\n 'array_repr', 'array_str', 'set_string_function',\n 'little_endian',\n 'indices', 'fromfunction',\n 'load', 'loads', 'isscalar', 'binary_repr', 'base_repr',\n 'ones', 'identity', 'allclose',\n 'seterr', 'geterr', 'setbufsize', 'getbufsize',\n 'seterrcall', 'geterrcall',\n 'Inf', 'inf', 'infty', 'Infinity',\n 'nan', 'NaN', 'False_', 'True_']\n\nimport sys\nimport multiarray\nimport umath\nfrom umath import *\nimport numerictypes\nfrom numerictypes import *\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 try:\n return zeros(a.shape, a.dtype, a.flags.fnc)\n except AttributeError:\n try:\n wrap = a.__array_wrap__\n except AttributeError:\n wrap = None\n a = asarray(a)\n res = zeros(a.shape, a.dtype)\n if wrap:\n res = wrap(res)\n return res\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 try:\n return empty(a.shape, a.dtype, a.flags.fnc)\n except AttributeError:\n try:\n wrap = a.__array_wrap__\n except AttributeError:\n wrap = None\n a = asarray(a)\n res = empty(a.shape, a.dtype)\n if wrap:\n res = wrap(res)\n return res\n\n# end Fernando's utilities\n\ndef extend_all(module):\n adict = {}\n for a in __all__:\n adict[a] = 1\n try:\n mall = getattr(module, '__all__')\n except AttributeError:\n mall = [k for k in module.__dict__.keys() if not k.startswith('_')]\n for a in mall:\n if a not in adict:\n __all__.append(a)\n\nextend_all(umath)\nextend_all(numerictypes)\n\nnewaxis = None\n\nndarray = multiarray.ndarray\nflatiter = multiarray.flatiter\nbroadcast = multiarray.broadcast\ndtype = multiarray.dtype\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\nnewbuffer = multiarray.newbuffer\ngetbuffer = multiarray.getbuffer\nwhere = multiarray.where\nconcatenate = multiarray.concatenate\nfastCopyAndTranspose = multiarray._fastCopyAndTranspose\nregister_dtype = multiarray.register_dtype\nset_numeric_ops = multiarray.set_numeric_ops\ncan_cast = multiarray.can_cast\nlexsort = multiarray.lexsort\n\n\ndef asarray(a, dtype=None, fortran=False, ndmin=0):\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, ndmin=ndmin)\n\ndef asanyarray(a, dtype=None, copy=False, fortran=False, ndmin=0):\n \"\"\"will pass subclasses through...\n \"\"\"\n return array(a, dtype, copy=copy, fortran=fortran, subok=1, ndmin=ndmin)\n\ndef isfortran(a):\n return a.flags['FNC']\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 multiarray.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 _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, axis=None):\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 if axis is not None:\n axisa,axisb,axisc=(axis,)*3\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.type 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.type.__name__[:-6]\n lf = ''\n if issubclass(arr.dtype.type, flexible):\n typename = str(arr.dtype)\n lf = '\\n'+' '*len(\"array(\")\n return cName + \"(%s, %sdtype=%s)\" % (lst, lf, 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, ' ', \"\", str)\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\ndef isscalar(num):\n if isinstance(num, generic):\n return True\n else:\n return type(num) in ScalarType\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 import math\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\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# 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 a = empty(shape, dtype, fortran)\n a.fill(1)\n # Above is faster now after addition of fast loops.\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 d.ravel().all()\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 umath.update_use_defaults()\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_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\",\n 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 umath.update_use_defaults()\n\n# set the default values\n_setdef()\n\nInf = inf = infty = Infinity = PINF\nnan = NaN = NAN\nFalse_ = bool_(False)\nTrue_ = bool_(True)\n\nimport oldnumeric\nfrom oldnumeric import *\nextend_all(oldnumeric)\n", + "methods": [ + { + "name": "zeros_like", + "long_name": "zeros_like( a )", + "filename": "numeric.py", + "nloc": 13, + "complexity": 4, + "token_count": 70, + "parameters": [ + "a" + ], + "start_line": 29, + "end_line": 45, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "empty_like", + "long_name": "empty_like( a )", + "filename": "numeric.py", + "nloc": 13, + "complexity": 4, + "token_count": 70, + "parameters": [ + "a" + ], + "start_line": 47, + "end_line": 65, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "extend_all", + "long_name": "extend_all( module )", + "filename": "numeric.py", + "nloc": 11, + "complexity": 7, + "token_count": 73, + "parameters": [ + "module" + ], + "start_line": 69, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( a , dtype = None , fortran = None , ndmin = 0 )", + "filename": "numeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 37, + "parameters": [ + "a", + "dtype", + "fortran", + "ndmin" + ], + "start_line": 110, + "end_line": 115, + "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 = None , ndmin = 0 )", + "filename": "numeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 45, + "parameters": [ + "a", + "dtype", + "copy", + "fortran", + "ndmin" + ], + "start_line": 117, + "end_line": 120, + "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": 11, + "parameters": [ + "a" + ], + "start_line": 122, + "end_line": 123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "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": 129, + "end_line": 132, + "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": 134, + "end_line": 136, + "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": 57, + "parameters": [ + "a", + "v", + "mode" + ], + "start_line": 139, + "end_line": 147, + "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": 153, + "end_line": 160, + "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": 162, + "end_line": 166, + "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": 174, + "end_line": 175, + "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": 176, + "end_line": 177, + "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": 180, + "end_line": 187, + "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 , axis = None )", + "filename": "numeric.py", + "nloc": 34, + "complexity": 10, + "token_count": 382, + "parameters": [ + "a", + "b", + "axisa", + "axisb", + "axisc", + "axis" + ], + "start_line": 189, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "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": 20, + "complexity": 7, + "token_count": 167, + "parameters": [ + "arr", + "max_line_width", + "precision", + "suppress_small" + ], + "start_line": 242, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "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": 34, + "parameters": [ + "a", + "max_line_width", + "precision", + "suppress_small" + ], + "start_line": 264, + "end_line": 265, + "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": 274, + "end_line": 282, + "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": 284, + "end_line": 294, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "isscalar", + "long_name": "isscalar( num )", + "filename": "numeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "num" + ], + "start_line": 296, + "end_line": 300, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "binary_repr", + "long_name": "binary_repr( num )", + "filename": "numeric.py", + "nloc": 9, + "complexity": 3, + "token_count": 50, + "parameters": [ + "num" + ], + "start_line": 312, + "end_line": 325, + "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": "numeric.py", + "nloc": 15, + "complexity": 3, + "token_count": 99, + "parameters": [ + "number", + "base", + "padding" + ], + "start_line": 327, + "end_line": 344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "load", + "long_name": "load( file )", + "filename": "numeric.py", + "nloc": 4, + "complexity": 2, + "token_count": 29, + "parameters": [ + "file" + ], + "start_line": 350, + "end_line": 353, + "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": 32, + "parameters": [ + "shape", + "dtype", + "fortran" + ], + "start_line": 358, + "end_line": 367, + "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": 369, + "end_line": 375, + "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": 74, + "parameters": [ + "a", + "b", + "rtol", + "atol" + ], + "start_line": 377, + "end_line": 388, + "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": 15, + "complexity": 10, + "token_count": 112, + "parameters": [ + "lst", + "frame", + "where" + ], + "start_line": 390, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_getpyvals", + "long_name": "_getpyvals( frame )", + "filename": "numeric.py", + "nloc": 11, + "complexity": 4, + "token_count": 49, + "parameters": [ + "frame" + ], + "start_line": 409, + "end_line": 419, + "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": 10, + "complexity": 1, + "token_count": 95, + "parameters": [ + "divide", + "over", + "under", + "invalid", + "where" + ], + "start_line": 431, + "end_line": 441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "geterr", + "long_name": "geterr( )", + "filename": "numeric.py", + "nloc": 14, + "complexity": 1, + "token_count": 107, + "parameters": [], + "start_line": 443, + "end_line": 457, + "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": 459, + "end_line": 466, + "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": 468, + "end_line": 470, + "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": 472, + "end_line": 478, + "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": 480, + "end_line": 482, + "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": 6, + "complexity": 1, + "token_count": 41, + "parameters": [], + "start_line": 484, + "end_line": 489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "zeros_like", + "long_name": "zeros_like( a )", + "filename": "numeric.py", + "nloc": 13, + "complexity": 4, + "token_count": 70, + "parameters": [ + "a" + ], + "start_line": 29, + "end_line": 45, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "empty_like", + "long_name": "empty_like( a )", + "filename": "numeric.py", + "nloc": 13, + "complexity": 4, + "token_count": 70, + "parameters": [ + "a" + ], + "start_line": 47, + "end_line": 65, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "extend_all", + "long_name": "extend_all( module )", + "filename": "numeric.py", + "nloc": 11, + "complexity": 7, + "token_count": 73, + "parameters": [ + "module" + ], + "start_line": 69, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( a , dtype = None , fortran = False , ndmin = 0 )", + "filename": "numeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 37, + "parameters": [ + "a", + "dtype", + "fortran", + "ndmin" + ], + "start_line": 110, + "end_line": 115, + "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 , ndmin = 0 )", + "filename": "numeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 45, + "parameters": [ + "a", + "dtype", + "copy", + "fortran", + "ndmin" + ], + "start_line": 117, + "end_line": 120, + "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": 122, + "end_line": 123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "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": 129, + "end_line": 132, + "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": 134, + "end_line": 136, + "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": 57, + "parameters": [ + "a", + "v", + "mode" + ], + "start_line": 139, + "end_line": 147, + "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": 153, + "end_line": 160, + "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": 162, + "end_line": 166, + "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": 174, + "end_line": 175, + "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": 176, + "end_line": 177, + "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": 180, + "end_line": 187, + "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 , axis = None )", + "filename": "numeric.py", + "nloc": 34, + "complexity": 10, + "token_count": 382, + "parameters": [ + "a", + "b", + "axisa", + "axisb", + "axisc", + "axis" + ], + "start_line": 189, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "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": 20, + "complexity": 7, + "token_count": 167, + "parameters": [ + "arr", + "max_line_width", + "precision", + "suppress_small" + ], + "start_line": 242, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "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": 34, + "parameters": [ + "a", + "max_line_width", + "precision", + "suppress_small" + ], + "start_line": 264, + "end_line": 265, + "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": 274, + "end_line": 282, + "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": 284, + "end_line": 294, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "isscalar", + "long_name": "isscalar( num )", + "filename": "numeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "num" + ], + "start_line": 296, + "end_line": 300, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "binary_repr", + "long_name": "binary_repr( num )", + "filename": "numeric.py", + "nloc": 9, + "complexity": 3, + "token_count": 50, + "parameters": [ + "num" + ], + "start_line": 312, + "end_line": 325, + "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": "numeric.py", + "nloc": 15, + "complexity": 3, + "token_count": 99, + "parameters": [ + "number", + "base", + "padding" + ], + "start_line": 327, + "end_line": 344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "load", + "long_name": "load( file )", + "filename": "numeric.py", + "nloc": 4, + "complexity": 2, + "token_count": 29, + "parameters": [ + "file" + ], + "start_line": 350, + "end_line": 353, + "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": 32, + "parameters": [ + "shape", + "dtype", + "fortran" + ], + "start_line": 358, + "end_line": 367, + "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": 369, + "end_line": 375, + "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": 74, + "parameters": [ + "a", + "b", + "rtol", + "atol" + ], + "start_line": 377, + "end_line": 388, + "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": 15, + "complexity": 10, + "token_count": 112, + "parameters": [ + "lst", + "frame", + "where" + ], + "start_line": 390, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_getpyvals", + "long_name": "_getpyvals( frame )", + "filename": "numeric.py", + "nloc": 11, + "complexity": 4, + "token_count": 49, + "parameters": [ + "frame" + ], + "start_line": 409, + "end_line": 419, + "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": 10, + "complexity": 1, + "token_count": 95, + "parameters": [ + "divide", + "over", + "under", + "invalid", + "where" + ], + "start_line": 431, + "end_line": 441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "geterr", + "long_name": "geterr( )", + "filename": "numeric.py", + "nloc": 14, + "complexity": 1, + "token_count": 107, + "parameters": [], + "start_line": 443, + "end_line": 457, + "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": 459, + "end_line": 466, + "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": 468, + "end_line": 470, + "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": 472, + "end_line": 478, + "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": 480, + "end_line": 482, + "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": 6, + "complexity": 1, + "token_count": 41, + "parameters": [], + "start_line": 484, + "end_line": 489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "isfortran", + "long_name": "isfortran( a )", + "filename": "numeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "a" + ], + "start_line": 122, + "end_line": 123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "asanyarray", + "long_name": "asanyarray( a , dtype = None , copy = False , fortran = False , ndmin = 0 )", + "filename": "numeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 45, + "parameters": [ + "a", + "dtype", + "copy", + "fortran", + "ndmin" + ], + "start_line": 117, + "end_line": 120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "asanyarray", + "long_name": "asanyarray( a , dtype = None , copy = False , fortran = None , ndmin = 0 )", + "filename": "numeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 45, + "parameters": [ + "a", + "dtype", + "copy", + "fortran", + "ndmin" + ], + "start_line": 117, + "end_line": 120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( a , dtype = None , fortran = False , ndmin = 0 )", + "filename": "numeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 37, + "parameters": [ + "a", + "dtype", + "fortran", + "ndmin" + ], + "start_line": 110, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( a , dtype = None , fortran = None , ndmin = 0 )", + "filename": "numeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 37, + "parameters": [ + "a", + "dtype", + "fortran", + "ndmin" + ], + "start_line": 110, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + } + ], + "nloc": 356, + "complexity": 87, + "token_count": 2679, + "diff_parsed": { + "added": [ + "def asarray(a, dtype=None, fortran=None, ndmin=0):", + "def asanyarray(a, dtype=None, copy=False, fortran=None, ndmin=0):", + " return a.flags.fnc" + ], + "deleted": [ + "def asarray(a, dtype=None, fortran=False, ndmin=0):", + "def asanyarray(a, dtype=None, copy=False, fortran=False, ndmin=0):", + " return a.flags['FNC']" + ] + } + }, + { + "old_path": "numpy/core/oldnumeric.py", + "new_path": "numpy/core/oldnumeric.py", + "filename": "oldnumeric.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -177,13 +177,13 @@ def take(a, indices, axis=0):\n result = _wrapit(a, 'take', indices, axis)\n return result\n \n-def reshape(a, newshape):\n+def reshape(a, newshape, fortran=False):\n \"\"\"Change the shape of a to newshape. Return a new view object.\n \"\"\"\n try:\n- result = a.reshape(newshape)\n+ result = a.reshape(newshape, fortran=fortran)\n except AttributeError:\n- result = _wrapit(a, 'reshape', newshape)\n+ result = _wrapit(a, 'reshape', newshape, fortran=fortran)\n return result\n \n def choose(a, choices):\n", + "added_lines": 3, + "deleted_lines": 3, + "source_code": "# Compatibility module containing deprecated names\n\n__all__ = ['asarray', 'array', 'concatenate',\n 'NewAxis',\n 'UFuncType', 'UfuncType', 'ArrayType', 'arraytype',\n 'LittleEndian', 'Bool',\n 'Character', 'UnsignedInt8', 'UnsignedInt16', 'UnsignedInt',\n 'UInt8','UInt16','UInt32', 'UnsignedInt32', 'UnsignedInteger',\n # UnsignedInt64 and Unsigned128 added below if possible\n # same for Int64 and Int128, Float128, and Complex128\n 'Int8', 'Int16', 'Int32',\n 'Int0', 'Int', 'Float0', 'Float', 'Complex0', 'Complex',\n 'PyObject', 'Float32', 'Float64', 'Float16', 'Float8',\n 'Complex32', 'Complex64', 'Complex8', 'Complex16',\n 'typecodes', 'sarray', 'arrayrange', 'cross_correlate',\n 'matrixmultiply', 'outerproduct', 'innerproduct',\n # from cPickle\n 'dump', 'dumps',\n # functions that are now methods\n 'take', 'reshape', 'choose', 'repeat', 'put', 'putmask',\n 'swapaxes', 'transpose', 'sort', 'argsort', 'argmax', 'argmin',\n 'searchsorted', 'alen',\n 'resize', 'diagonal', 'trace', 'ravel', 'nonzero', 'shape',\n 'compress', 'clip', 'sum', 'product', 'prod', 'sometrue', 'alltrue',\n 'any', 'all', 'cumsum', 'cumproduct', 'cumprod', 'ptp', 'ndim',\n 'rank', 'size', 'around', 'round_', 'mean', 'std', 'var', 'squeeze',\n 'amax', 'amin',\n ]\n\nimport multiarray as mu\nimport umath as um\nimport numerictypes as nt\nfrom numeric import asarray, array, asanyarray, correlate, outer, concatenate\nfrom umath import sign, absolute, multiply\nimport numeric as _nx\nimport sys\n_dt_ = nt.sctype2char\n\nimport types\n\ntry:\n _gentype = types.GeneratorType\nexcept AttributeError:\n _gentype = types.NoneType\n#Use this to add a new axis to an array\n#compatibility only\nNewAxis = None\n\n#deprecated\nUFuncType = type(um.sin)\nUfuncType = type(um.sin)\nArrayType = mu.ndarray\narraytype = mu.ndarray\n\nLittleEndian = (sys.byteorder == 'little')\n\n# save away Python sum\n_sum_ = sum\n\n# backward compatible names from old Precision.py\n\nCharacter = 'S1'\nUnsignedInt8 = _dt_(nt.uint8)\nUInt8 = UnsignedInt8\nUnsignedInt16 = _dt_(nt.uint16)\nUInt16 = UnsignedInt16\nUnsignedInt32 = _dt_(nt.uint32)\nUInt32 = UnsignedInt32\nUnsignedInt = _dt_(nt.uint)\n\ntry:\n UnsignedInt64 = _dt_(nt.uint64)\nexcept AttributeError:\n pass\nelse:\n UInt64 = UnsignedInt64\n __all__ += ['UnsignedInt64', 'UInt64']\ntry:\n UnsignedInt128 = _dt_(nt.uint128)\nexcept AttributeError:\n pass\nelse:\n UInt128 = UnsignedInt128\n __all__ += ['UnsignedInt128','UInt128']\n\nInt8 = _dt_(nt.int8)\nInt16 = _dt_(nt.int16)\nInt32 = _dt_(nt.int32)\n\ntry:\n Int64 = _dt_(nt.int64)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int64']\n\ntry:\n Int128 = _dt_(nt.int128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int128']\n\nBool = _dt_(bool)\nInt0 = _dt_(int)\nInt = _dt_(int)\nFloat0 = _dt_(float)\nFloat = _dt_(float)\nComplex0 = _dt_(complex)\nComplex = _dt_(complex)\nPyObject = _dt_(nt.object_)\nFloat32 = _dt_(nt.float32)\nFloat64 = _dt_(nt.float64)\n\nFloat16='f'\nFloat8='f'\nUnsignedInteger='L'\nComplex8='F'\nComplex16='F'\n\ntry:\n Float128 = _dt_(nt.float128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Float128']\n\nComplex32 = _dt_(nt.complex64)\nComplex64 = _dt_(nt.complex128)\n\ntry:\n Complex128 = _dt_(nt.complex256)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Complex128']\n\ntypecodes = {'Character':'S1',\n 'Integer':'bhilqp',\n 'UnsignedInteger':'BHILQP',\n 'Float':'fdg',\n 'Complex':'FDG',\n 'AllInteger':'bBhHiIlLqQpP',\n 'AllFloat':'fdgFDG',\n 'All':'?bhilqpBHILQPfdgFDGSUVO'}\n\ndef sarray(a, dtype=None, copy=False):\n return array(a, dtype, copy)\n\n# backward compatibility\narrayrange = mu.arange\ncross_correlate = correlate\n\n# deprecated names\nmatrixmultiply = mu.dot\nouterproduct = outer\ninnerproduct = mu.inner\n\nfrom cPickle import dump, dumps\n\n# functions that are now methods\n\ndef _wrapit(obj, method, *args, **kwds):\n try:\n wrap = obj.__array_wrap__\n except AttributeError:\n wrap = None\n result = getattr(asarray(obj),method)(*args, **kwds)\n if wrap:\n result = wrap(result)\n return result\n\ndef take(a, indices, axis=0):\n try:\n result = a.take(indices, axis)\n except AttributeError:\n result = _wrapit(a, 'take', indices, axis)\n return result\n\ndef reshape(a, newshape, fortran=False):\n \"\"\"Change the shape of a to newshape. Return a new view object.\n \"\"\"\n try:\n result = a.reshape(newshape, fortran=fortran)\n except AttributeError:\n result = _wrapit(a, 'reshape', newshape, fortran=fortran)\n return result\n\ndef choose(a, choices):\n try:\n result = a.choose(choices)\n except AttributeError:\n result = _wrapit(a, 'choose', choices)\n return result\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n 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 try:\n result = a.repeat(repeats, axis)\n except AttributeError:\n result = _wrapit(a, 'repeat', repeats, axis)\n return result\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.dtype)\n for i in ind: a.flat[i] = v[i]\n a must be a contiguous numpy array.\n \"\"\"\n return a.put(v,ind)\n\ndef putmask (a, mask, v):\n \"\"\"putmask(a, mask, v) results in a = v for all places mask is true.\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n \"\"\"\n return a.putmask(v, mask)\n\ndef swapaxes(a, axis1, axis2):\n \"\"\"swapaxes(a, axis1, axis2) returns array a with axis1 and axis2\n interchanged.\n \"\"\"\n try:\n result = a.swapaxes(axis1, axis2)\n except AttributeError:\n result = _wrapit(a, 'swapaxes', axis1, axis2)\n return result\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 try:\n result = a.transpose(axes)\n except AttributeError:\n result = _wrapit(a, 'transpose', axes)\n return result\n\ndef sort(a, axis=-1):\n \"\"\"sort(a,axis=-1) returns array with elements sorted along given axis.\n \"\"\"\n a = asanyarray(a, copy=True)\n a.sort(axis)\n return a\n\ndef argsort(a, axis=-1):\n \"\"\"argsort(a,axis=-1) return the indices into a of the sorted array\n along the given axis, so that take(a,result,axis) is the sorted array.\n \"\"\"\n try:\n result = a.argsort(axis)\n except AttributeError:\n result = _wrapit(a, 'argsort', axis)\n return result\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 try:\n result = a.argmax(axis)\n except AttributeError:\n result = _wrapit(a, 'argmax', axis)\n return result\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 try:\n result = a.argmin(axis)\n except AttributeError:\n result = _wrapit(a, 'argmin', axis)\n return result\n \ndef searchsorted(a, v):\n \"\"\"searchsorted(a, v)\n \"\"\"\n try:\n result = a.searchsorted(v)\n except AttributeError:\n result = _wrapit(a, 'searchsorted', v)\n return result\n\ndef resize(a, new_shape):\n \"\"\"resize(a,new_shape) returns a new array with the specified shape.\n The original array's total size can be any size. It\n fills the new array with repeated copies of a.\n\n Note that a.resize(new_shape) will fill array with 0's\n beyond current definition of a.\n \"\"\"\n\n if isinstance(new_shape, (int, nt.integer)):\n new_shape = (new_shape,)\n a = ravel(a)\n Na = len(a)\n if not Na: return mu.zeros(new_shape, a.dtype.char)\n total_size = um.multiply.reduce(new_shape)\n n_copies = int(total_size / Na)\n extra = total_size % Na\n\n if total_size == 0:\n return a[:0]\n\n if extra != 0:\n n_copies = n_copies+1\n extra = Na-extra\n\n a = concatenate( (a,)*n_copies)\n if extra > 0:\n a = a[:-extra]\n\n return reshape(a, new_shape)\n\ndef squeeze(a):\n \"Returns a with any ones from the shape of a removed\"\n try:\n result = a.squeeze()\n except AttributeError:\n result = _wrapit(a, 'squeeze')\n return result\n\ndef diagonal(a, offset=0, axis1=0, axis2=1):\n \"\"\"diagonal(a, offset=0, axis1=0, axis2=1) returns the given diagonals\n defined by the last two dimensions of the array.\n \"\"\"\n return asarray(a).diagonal(offset, axis1, axis2)\n\ndef trace(a, offset=0, axis1=0, axis2=1, dtype=None):\n \"\"\"trace(a,offset=0, axis1=0, axis2=1) returns the sum along diagonals\n (defined by the last two dimenions) of the array.\n \"\"\"\n return asarray(a).trace(offset, axis1, axis2, dtype)\n\ndef ravel(m):\n \"\"\"ravel(m) returns a 1d array corresponding to all the elements of it's\n argument.\n \"\"\"\n return asarray(m).ravel()\n\ndef nonzero(a):\n \"\"\"nonzero(a) returns the indices of the elements of a which are not zero,\n a must be 1d\n \"\"\"\n try:\n result = a.nonzero()\n except AttributeError:\n result = _wrapit(a, 'nonzero')\n return result\n\ndef shape(a):\n \"\"\"shape(a) returns the shape of a (as a function call which\n also works on nested sequences).\n \"\"\"\n try:\n result = a.shape\n except AttributeError:\n result = asarray(a).shape\n return result\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 try:\n result = m.compress(condition, axis)\n except AttributeError:\n result = _wrapit(m, 'compress', condition, axis)\n return result\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 try:\n result = m.clip(m_min, m_max)\n except AttributeError:\n result = _wrapit(m, 'clip', m_min, m_max)\n return result\n\ndef sum(x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis. The optional dtype argument\n is the data type for intermediate calculations.\n\n The default is to upcast (promote) smaller integer types to the\n platform-dependent Int. For example, on 32-bit platforms:\n\n x.dtype default sum() dtype\n ---------------------------------------------------\n bool, Int8, Int16, Int32 Int32\n\n Examples:\n >>> sum([0.5, 1.5])\n 2.0\n >>> sum([0.5, 1.5], dtype=Int32)\n 1\n >>> sum([[0, 1], [0, 5]])\n array([0, 6])\n >>> sum([[0, 1], [0, 5]], axis=1)\n array([1, 5])\n \"\"\"\n if isinstance(x, _gentype):\n return _sum_(x)\n try:\n result = x.sum(axis, dtype)\n except AttributeError:\n result = _wrapit(x, 'sum', axis, dtype)\n return result\n\ndef product (x, axis=0, dtype=None):\n \"\"\"Product of the array elements over the given axis.\"\"\"\n try:\n result = x.prod(axis, dtype)\n except AttributeError:\n result = _wrapit(x, 'prod', axis, dtype)\n return result\n\ndef sometrue (x, axis=0):\n \"\"\"Perform a logical_or over the given axis.\"\"\"\n try:\n result = x.any(axis)\n except AttributeError:\n result = _wrapit(x, 'any', axis)\n return result\n\ndef alltrue (x, axis=0):\n \"\"\"Perform a logical_and over the given axis.\"\"\"\n try:\n result = x.all(axis)\n except AttributeError:\n result = _wrapit(x, 'all', axis)\n return result\n\ndef any(x,axis=None):\n \"\"\"Return true if any elements of x are true: \n \"\"\"\n try:\n result = x.any(axis)\n except AttributeError:\n result = _wrapit(x, 'any', axis)\n return result\n\ndef all(x,axis=None):\n \"\"\"Return true if all elements of x are true: \n \"\"\"\n try:\n result = x.all(axis)\n except AttributeError:\n result = _wrapit(x, 'all', axis)\n return result\n\ndef cumsum (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n try:\n result = x.cumsum(axis, dtype)\n except AttributeError:\n result = _wrapit(x, 'cumsum', axis, dtype)\n return result\n\ndef cumproduct (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n try:\n result = x.cumprod(axis, dtype)\n except AttributeError:\n result = _wrapit(x, 'cumprod', axis, dtype)\n return result\n\ndef ptp(a, axis=0):\n \"\"\"Return maximum - minimum along the the given dimension\n \"\"\"\n try:\n result = a.ptp(axis)\n except AttributeError:\n result = _wrapit(a, 'ptp', axis)\n return result\n\ndef amax(a, axis=0):\n \"\"\"Return the maximum of 'a' along dimension axis.\n \"\"\"\n try:\n result = a.max(axis)\n except AttributeError:\n result = _wrapit(a, 'max', axis)\n return result\n\ndef amin(a, axis=0):\n \"\"\"Return the minimum of a along dimension axis.\n \"\"\"\n try:\n result = a.min(axis)\n except AttributeError:\n result = _wrapit(a, 'min', axis)\n return result\n\ndef alen(a):\n \"\"\"Return the length of a Python object interpreted as an array\n of at least 1 dimension.\n \"\"\"\n try:\n return len(a)\n except TypeError:\n return len(array(a,ndmin=1))\n\ndef prod(a, axis=0, dtype=None):\n \"\"\"Return the product of the elements along the given axis\n \"\"\"\n try:\n result = a.prod(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'prod', axis, dtype)\n return result\n\ndef cumprod(a, axis=0, dtype=None):\n \"\"\"Return the cumulative product of the elments along the given axis\n \"\"\"\n try:\n result = a.cumprod(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'cumprod', axis, dtype)\n return result\n\ndef ndim(a):\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef rank(a):\n \"\"\"Get the rank of sequence a (the number of dimensions, not a matrix rank)\n The rank of a scalar is zero.\n \"\"\"\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef size (a, axis=None):\n \"Get the number of elements in sequence a, or along a certain axis.\"\n if axis is None:\n try:\n return a.size\n except AttributeError:\n return asarray(a).size\n else:\n try:\n return a.shape[axis]\n except AttributeError:\n return asarray(a).shape[axis]\n\ndef round_(a, decimals=0):\n \"\"\"Round 'a' to the given number of decimal places. Rounding\n behaviour is equivalent to Python.\n\n Return 'a' if the array is not floating point. Round both the real\n and imaginary parts separately if the array is complex.\n \"\"\"\n try:\n result = a.round(decimals)\n except AttributeError:\n result = _wrapit(a, 'round', decimals)\n return result\n\naround = round_\n\ndef mean(a, axis=0, dtype=None):\n try:\n result = a.mean(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'mean', axis, dtype)\n return result \n\ndef std(a, axis=0, dtype=None):\n try:\n result = a.std(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'std', axis, dtype)\n return result\n\ndef var(a, axis=0, dtype=None):\n try:\n result = a.std(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'var', axis, dtype)\n return result\n", + "source_code_before": "# Compatibility module containing deprecated names\n\n__all__ = ['asarray', 'array', 'concatenate',\n 'NewAxis',\n 'UFuncType', 'UfuncType', 'ArrayType', 'arraytype',\n 'LittleEndian', 'Bool',\n 'Character', 'UnsignedInt8', 'UnsignedInt16', 'UnsignedInt',\n 'UInt8','UInt16','UInt32', 'UnsignedInt32', 'UnsignedInteger',\n # UnsignedInt64 and Unsigned128 added below if possible\n # same for Int64 and Int128, Float128, and Complex128\n 'Int8', 'Int16', 'Int32',\n 'Int0', 'Int', 'Float0', 'Float', 'Complex0', 'Complex',\n 'PyObject', 'Float32', 'Float64', 'Float16', 'Float8',\n 'Complex32', 'Complex64', 'Complex8', 'Complex16',\n 'typecodes', 'sarray', 'arrayrange', 'cross_correlate',\n 'matrixmultiply', 'outerproduct', 'innerproduct',\n # from cPickle\n 'dump', 'dumps',\n # functions that are now methods\n 'take', 'reshape', 'choose', 'repeat', 'put', 'putmask',\n 'swapaxes', 'transpose', 'sort', 'argsort', 'argmax', 'argmin',\n 'searchsorted', 'alen',\n 'resize', 'diagonal', 'trace', 'ravel', 'nonzero', 'shape',\n 'compress', 'clip', 'sum', 'product', 'prod', 'sometrue', 'alltrue',\n 'any', 'all', 'cumsum', 'cumproduct', 'cumprod', 'ptp', 'ndim',\n 'rank', 'size', 'around', 'round_', 'mean', 'std', 'var', 'squeeze',\n 'amax', 'amin',\n ]\n\nimport multiarray as mu\nimport umath as um\nimport numerictypes as nt\nfrom numeric import asarray, array, asanyarray, correlate, outer, concatenate\nfrom umath import sign, absolute, multiply\nimport numeric as _nx\nimport sys\n_dt_ = nt.sctype2char\n\nimport types\n\ntry:\n _gentype = types.GeneratorType\nexcept AttributeError:\n _gentype = types.NoneType\n#Use this to add a new axis to an array\n#compatibility only\nNewAxis = None\n\n#deprecated\nUFuncType = type(um.sin)\nUfuncType = type(um.sin)\nArrayType = mu.ndarray\narraytype = mu.ndarray\n\nLittleEndian = (sys.byteorder == 'little')\n\n# save away Python sum\n_sum_ = sum\n\n# backward compatible names from old Precision.py\n\nCharacter = 'S1'\nUnsignedInt8 = _dt_(nt.uint8)\nUInt8 = UnsignedInt8\nUnsignedInt16 = _dt_(nt.uint16)\nUInt16 = UnsignedInt16\nUnsignedInt32 = _dt_(nt.uint32)\nUInt32 = UnsignedInt32\nUnsignedInt = _dt_(nt.uint)\n\ntry:\n UnsignedInt64 = _dt_(nt.uint64)\nexcept AttributeError:\n pass\nelse:\n UInt64 = UnsignedInt64\n __all__ += ['UnsignedInt64', 'UInt64']\ntry:\n UnsignedInt128 = _dt_(nt.uint128)\nexcept AttributeError:\n pass\nelse:\n UInt128 = UnsignedInt128\n __all__ += ['UnsignedInt128','UInt128']\n\nInt8 = _dt_(nt.int8)\nInt16 = _dt_(nt.int16)\nInt32 = _dt_(nt.int32)\n\ntry:\n Int64 = _dt_(nt.int64)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int64']\n\ntry:\n Int128 = _dt_(nt.int128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int128']\n\nBool = _dt_(bool)\nInt0 = _dt_(int)\nInt = _dt_(int)\nFloat0 = _dt_(float)\nFloat = _dt_(float)\nComplex0 = _dt_(complex)\nComplex = _dt_(complex)\nPyObject = _dt_(nt.object_)\nFloat32 = _dt_(nt.float32)\nFloat64 = _dt_(nt.float64)\n\nFloat16='f'\nFloat8='f'\nUnsignedInteger='L'\nComplex8='F'\nComplex16='F'\n\ntry:\n Float128 = _dt_(nt.float128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Float128']\n\nComplex32 = _dt_(nt.complex64)\nComplex64 = _dt_(nt.complex128)\n\ntry:\n Complex128 = _dt_(nt.complex256)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Complex128']\n\ntypecodes = {'Character':'S1',\n 'Integer':'bhilqp',\n 'UnsignedInteger':'BHILQP',\n 'Float':'fdg',\n 'Complex':'FDG',\n 'AllInteger':'bBhHiIlLqQpP',\n 'AllFloat':'fdgFDG',\n 'All':'?bhilqpBHILQPfdgFDGSUVO'}\n\ndef sarray(a, dtype=None, copy=False):\n return array(a, dtype, copy)\n\n# backward compatibility\narrayrange = mu.arange\ncross_correlate = correlate\n\n# deprecated names\nmatrixmultiply = mu.dot\nouterproduct = outer\ninnerproduct = mu.inner\n\nfrom cPickle import dump, dumps\n\n# functions that are now methods\n\ndef _wrapit(obj, method, *args, **kwds):\n try:\n wrap = obj.__array_wrap__\n except AttributeError:\n wrap = None\n result = getattr(asarray(obj),method)(*args, **kwds)\n if wrap:\n result = wrap(result)\n return result\n\ndef take(a, indices, axis=0):\n try:\n result = a.take(indices, axis)\n except AttributeError:\n result = _wrapit(a, 'take', indices, axis)\n return result\n\ndef reshape(a, newshape):\n \"\"\"Change the shape of a to newshape. Return a new view object.\n \"\"\"\n try:\n result = a.reshape(newshape)\n except AttributeError:\n result = _wrapit(a, 'reshape', newshape)\n return result\n\ndef choose(a, choices):\n try:\n result = a.choose(choices)\n except AttributeError:\n result = _wrapit(a, 'choose', choices)\n return result\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n 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 try:\n result = a.repeat(repeats, axis)\n except AttributeError:\n result = _wrapit(a, 'repeat', repeats, axis)\n return result\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.dtype)\n for i in ind: a.flat[i] = v[i]\n a must be a contiguous numpy array.\n \"\"\"\n return a.put(v,ind)\n\ndef putmask (a, mask, v):\n \"\"\"putmask(a, mask, v) results in a = v for all places mask is true.\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n \"\"\"\n return a.putmask(v, mask)\n\ndef swapaxes(a, axis1, axis2):\n \"\"\"swapaxes(a, axis1, axis2) returns array a with axis1 and axis2\n interchanged.\n \"\"\"\n try:\n result = a.swapaxes(axis1, axis2)\n except AttributeError:\n result = _wrapit(a, 'swapaxes', axis1, axis2)\n return result\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 try:\n result = a.transpose(axes)\n except AttributeError:\n result = _wrapit(a, 'transpose', axes)\n return result\n\ndef sort(a, axis=-1):\n \"\"\"sort(a,axis=-1) returns array with elements sorted along given axis.\n \"\"\"\n a = asanyarray(a, copy=True)\n a.sort(axis)\n return a\n\ndef argsort(a, axis=-1):\n \"\"\"argsort(a,axis=-1) return the indices into a of the sorted array\n along the given axis, so that take(a,result,axis) is the sorted array.\n \"\"\"\n try:\n result = a.argsort(axis)\n except AttributeError:\n result = _wrapit(a, 'argsort', axis)\n return result\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 try:\n result = a.argmax(axis)\n except AttributeError:\n result = _wrapit(a, 'argmax', axis)\n return result\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 try:\n result = a.argmin(axis)\n except AttributeError:\n result = _wrapit(a, 'argmin', axis)\n return result\n \ndef searchsorted(a, v):\n \"\"\"searchsorted(a, v)\n \"\"\"\n try:\n result = a.searchsorted(v)\n except AttributeError:\n result = _wrapit(a, 'searchsorted', v)\n return result\n\ndef resize(a, new_shape):\n \"\"\"resize(a,new_shape) returns a new array with the specified shape.\n The original array's total size can be any size. It\n fills the new array with repeated copies of a.\n\n Note that a.resize(new_shape) will fill array with 0's\n beyond current definition of a.\n \"\"\"\n\n if isinstance(new_shape, (int, nt.integer)):\n new_shape = (new_shape,)\n a = ravel(a)\n Na = len(a)\n if not Na: return mu.zeros(new_shape, a.dtype.char)\n total_size = um.multiply.reduce(new_shape)\n n_copies = int(total_size / Na)\n extra = total_size % Na\n\n if total_size == 0:\n return a[:0]\n\n if extra != 0:\n n_copies = n_copies+1\n extra = Na-extra\n\n a = concatenate( (a,)*n_copies)\n if extra > 0:\n a = a[:-extra]\n\n return reshape(a, new_shape)\n\ndef squeeze(a):\n \"Returns a with any ones from the shape of a removed\"\n try:\n result = a.squeeze()\n except AttributeError:\n result = _wrapit(a, 'squeeze')\n return result\n\ndef diagonal(a, offset=0, axis1=0, axis2=1):\n \"\"\"diagonal(a, offset=0, axis1=0, axis2=1) returns the given diagonals\n defined by the last two dimensions of the array.\n \"\"\"\n return asarray(a).diagonal(offset, axis1, axis2)\n\ndef trace(a, offset=0, axis1=0, axis2=1, dtype=None):\n \"\"\"trace(a,offset=0, axis1=0, axis2=1) returns the sum along diagonals\n (defined by the last two dimenions) of the array.\n \"\"\"\n return asarray(a).trace(offset, axis1, axis2, dtype)\n\ndef ravel(m):\n \"\"\"ravel(m) returns a 1d array corresponding to all the elements of it's\n argument.\n \"\"\"\n return asarray(m).ravel()\n\ndef nonzero(a):\n \"\"\"nonzero(a) returns the indices of the elements of a which are not zero,\n a must be 1d\n \"\"\"\n try:\n result = a.nonzero()\n except AttributeError:\n result = _wrapit(a, 'nonzero')\n return result\n\ndef shape(a):\n \"\"\"shape(a) returns the shape of a (as a function call which\n also works on nested sequences).\n \"\"\"\n try:\n result = a.shape\n except AttributeError:\n result = asarray(a).shape\n return result\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 try:\n result = m.compress(condition, axis)\n except AttributeError:\n result = _wrapit(m, 'compress', condition, axis)\n return result\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 try:\n result = m.clip(m_min, m_max)\n except AttributeError:\n result = _wrapit(m, 'clip', m_min, m_max)\n return result\n\ndef sum(x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis. The optional dtype argument\n is the data type for intermediate calculations.\n\n The default is to upcast (promote) smaller integer types to the\n platform-dependent Int. For example, on 32-bit platforms:\n\n x.dtype default sum() dtype\n ---------------------------------------------------\n bool, Int8, Int16, Int32 Int32\n\n Examples:\n >>> sum([0.5, 1.5])\n 2.0\n >>> sum([0.5, 1.5], dtype=Int32)\n 1\n >>> sum([[0, 1], [0, 5]])\n array([0, 6])\n >>> sum([[0, 1], [0, 5]], axis=1)\n array([1, 5])\n \"\"\"\n if isinstance(x, _gentype):\n return _sum_(x)\n try:\n result = x.sum(axis, dtype)\n except AttributeError:\n result = _wrapit(x, 'sum', axis, dtype)\n return result\n\ndef product (x, axis=0, dtype=None):\n \"\"\"Product of the array elements over the given axis.\"\"\"\n try:\n result = x.prod(axis, dtype)\n except AttributeError:\n result = _wrapit(x, 'prod', axis, dtype)\n return result\n\ndef sometrue (x, axis=0):\n \"\"\"Perform a logical_or over the given axis.\"\"\"\n try:\n result = x.any(axis)\n except AttributeError:\n result = _wrapit(x, 'any', axis)\n return result\n\ndef alltrue (x, axis=0):\n \"\"\"Perform a logical_and over the given axis.\"\"\"\n try:\n result = x.all(axis)\n except AttributeError:\n result = _wrapit(x, 'all', axis)\n return result\n\ndef any(x,axis=None):\n \"\"\"Return true if any elements of x are true: \n \"\"\"\n try:\n result = x.any(axis)\n except AttributeError:\n result = _wrapit(x, 'any', axis)\n return result\n\ndef all(x,axis=None):\n \"\"\"Return true if all elements of x are true: \n \"\"\"\n try:\n result = x.all(axis)\n except AttributeError:\n result = _wrapit(x, 'all', axis)\n return result\n\ndef cumsum (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n try:\n result = x.cumsum(axis, dtype)\n except AttributeError:\n result = _wrapit(x, 'cumsum', axis, dtype)\n return result\n\ndef cumproduct (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n try:\n result = x.cumprod(axis, dtype)\n except AttributeError:\n result = _wrapit(x, 'cumprod', axis, dtype)\n return result\n\ndef ptp(a, axis=0):\n \"\"\"Return maximum - minimum along the the given dimension\n \"\"\"\n try:\n result = a.ptp(axis)\n except AttributeError:\n result = _wrapit(a, 'ptp', axis)\n return result\n\ndef amax(a, axis=0):\n \"\"\"Return the maximum of 'a' along dimension axis.\n \"\"\"\n try:\n result = a.max(axis)\n except AttributeError:\n result = _wrapit(a, 'max', axis)\n return result\n\ndef amin(a, axis=0):\n \"\"\"Return the minimum of a along dimension axis.\n \"\"\"\n try:\n result = a.min(axis)\n except AttributeError:\n result = _wrapit(a, 'min', axis)\n return result\n\ndef alen(a):\n \"\"\"Return the length of a Python object interpreted as an array\n of at least 1 dimension.\n \"\"\"\n try:\n return len(a)\n except TypeError:\n return len(array(a,ndmin=1))\n\ndef prod(a, axis=0, dtype=None):\n \"\"\"Return the product of the elements along the given axis\n \"\"\"\n try:\n result = a.prod(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'prod', axis, dtype)\n return result\n\ndef cumprod(a, axis=0, dtype=None):\n \"\"\"Return the cumulative product of the elments along the given axis\n \"\"\"\n try:\n result = a.cumprod(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'cumprod', axis, dtype)\n return result\n\ndef ndim(a):\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef rank(a):\n \"\"\"Get the rank of sequence a (the number of dimensions, not a matrix rank)\n The rank of a scalar is zero.\n \"\"\"\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef size (a, axis=None):\n \"Get the number of elements in sequence a, or along a certain axis.\"\n if axis is None:\n try:\n return a.size\n except AttributeError:\n return asarray(a).size\n else:\n try:\n return a.shape[axis]\n except AttributeError:\n return asarray(a).shape[axis]\n\ndef round_(a, decimals=0):\n \"\"\"Round 'a' to the given number of decimal places. Rounding\n behaviour is equivalent to Python.\n\n Return 'a' if the array is not floating point. Round both the real\n and imaginary parts separately if the array is complex.\n \"\"\"\n try:\n result = a.round(decimals)\n except AttributeError:\n result = _wrapit(a, 'round', decimals)\n return result\n\naround = round_\n\ndef mean(a, axis=0, dtype=None):\n try:\n result = a.mean(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'mean', axis, dtype)\n return result \n\ndef std(a, axis=0, dtype=None):\n try:\n result = a.std(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'std', axis, dtype)\n return result\n\ndef var(a, axis=0, dtype=None):\n try:\n result = a.std(axis, dtype)\n except AttributeError:\n result = _wrapit(a, 'var', axis, dtype)\n return result\n", + "methods": [ + { + "name": "sarray", + "long_name": "sarray( a , dtype = None , copy = False )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "dtype", + "copy" + ], + "start_line": 147, + "end_line": 148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_wrapit", + "long_name": "_wrapit( obj , method , * args , ** kwds )", + "filename": "oldnumeric.py", + "nloc": 9, + "complexity": 3, + "token_count": 55, + "parameters": [ + "obj", + "method", + "args", + "kwds" + ], + "start_line": 163, + "end_line": 171, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 40, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 173, + "end_line": 178, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , newshape , fortran = False )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 45, + "parameters": [ + "a", + "newshape", + "fortran" + ], + "start_line": 180, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "choose", + "long_name": "choose( a , choices )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 32, + "parameters": [ + "a", + "choices" + ], + "start_line": 189, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 196, + "end_line": 208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , ind , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "ind", + "v" + ], + "start_line": 210, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "mask", + "v" + ], + "start_line": 224, + "end_line": 229, + "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": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "a", + "axis1", + "axis2" + ], + "start_line": 231, + "end_line": 239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "axes" + ], + "start_line": 241, + "end_line": 250, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "sort", + "long_name": "sort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis" + ], + "start_line": 252, + "end_line": 257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "a", + "axis" + ], + "start_line": 259, + "end_line": 267, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "a", + "axis" + ], + "start_line": 269, + "end_line": 277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "a", + "axis" + ], + "start_line": 279, + "end_line": 287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "searchsorted", + "long_name": "searchsorted( a , v )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 33, + "parameters": [ + "a", + "v" + ], + "start_line": 289, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "oldnumeric.py", + "nloc": 18, + "complexity": 6, + "token_count": 137, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 298, + "end_line": 327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "squeeze", + "long_name": "squeeze( a )", + "filename": "oldnumeric.py", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "a" + ], + "start_line": 329, + "end_line": 335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "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": 337, + "end_line": 341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "trace", + "long_name": "trace( a , offset = 0 , axis1 = 0 , axis2 = 1 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 38, + "parameters": [ + "a", + "offset", + "axis1", + "axis2", + "dtype" + ], + "start_line": 343, + "end_line": 347, + "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": 349, + "end_line": 353, + "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": 6, + "complexity": 2, + "token_count": 28, + "parameters": [ + "a" + ], + "start_line": 355, + "end_line": 363, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( a )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 26, + "parameters": [ + "a" + ], + "start_line": 365, + "end_line": 373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , m , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "condition", + "m", + "axis" + ], + "start_line": 375, + "end_line": 383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "clip", + "long_name": "clip( m , m_min , m_max )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "m", + "m_min", + "m_max" + ], + "start_line": 385, + "end_line": 394, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "sum", + "long_name": "sum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 8, + "complexity": 3, + "token_count": 56, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 396, + "end_line": 423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "product", + "long_name": "product( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 425, + "end_line": 431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "sometrue", + "long_name": "sometrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "x", + "axis" + ], + "start_line": 433, + "end_line": 439, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "alltrue", + "long_name": "alltrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "x", + "axis" + ], + "start_line": 441, + "end_line": 447, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "any", + "long_name": "any( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "x", + "axis" + ], + "start_line": 449, + "end_line": 456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "all", + "long_name": "all( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "x", + "axis" + ], + "start_line": 458, + "end_line": 465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "cumsum", + "long_name": "cumsum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 467, + "end_line": 473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "cumproduct", + "long_name": "cumproduct( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 475, + "end_line": 481, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "ptp", + "long_name": "ptp( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "axis" + ], + "start_line": 483, + "end_line": 490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "amax", + "long_name": "amax( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "axis" + ], + "start_line": 492, + "end_line": 499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "amin", + "long_name": "amin( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "axis" + ], + "start_line": 501, + "end_line": 508, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "alen", + "long_name": "alen( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 28, + "parameters": [ + "a" + ], + "start_line": 510, + "end_line": 517, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "prod", + "long_name": "prod( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 519, + "end_line": 526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "cumprod", + "long_name": "cumprod( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 528, + "end_line": 535, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ndim", + "long_name": "ndim( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 21, + "parameters": [ + "a" + ], + "start_line": 537, + "end_line": 541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rank", + "long_name": "rank( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "a" + ], + "start_line": 543, + "end_line": 550, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( a , axis = None )", + "filename": "oldnumeric.py", + "nloc": 12, + "complexity": 4, + "token_count": 55, + "parameters": [ + "a", + "axis" + ], + "start_line": 552, + "end_line": 563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "round_", + "long_name": "round_( a , decimals = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "decimals" + ], + "start_line": 565, + "end_line": 576, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "mean", + "long_name": "mean( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 580, + "end_line": 585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "std", + "long_name": "std( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 587, + "end_line": 592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "var", + "long_name": "var( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 594, + "end_line": 599, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "sarray", + "long_name": "sarray( a , dtype = None , copy = False )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "dtype", + "copy" + ], + "start_line": 147, + "end_line": 148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_wrapit", + "long_name": "_wrapit( obj , method , * args , ** kwds )", + "filename": "oldnumeric.py", + "nloc": 9, + "complexity": 3, + "token_count": 55, + "parameters": [ + "obj", + "method", + "args", + "kwds" + ], + "start_line": 163, + "end_line": 171, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 40, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 173, + "end_line": 178, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , newshape )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 33, + "parameters": [ + "a", + "newshape" + ], + "start_line": 180, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "choose", + "long_name": "choose( a , choices )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 32, + "parameters": [ + "a", + "choices" + ], + "start_line": 189, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 196, + "end_line": 208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , ind , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "ind", + "v" + ], + "start_line": 210, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "mask", + "v" + ], + "start_line": 224, + "end_line": 229, + "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": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "a", + "axis1", + "axis2" + ], + "start_line": 231, + "end_line": 239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "axes" + ], + "start_line": 241, + "end_line": 250, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "sort", + "long_name": "sort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis" + ], + "start_line": 252, + "end_line": 257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "a", + "axis" + ], + "start_line": 259, + "end_line": 267, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "a", + "axis" + ], + "start_line": 269, + "end_line": 277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "a", + "axis" + ], + "start_line": 279, + "end_line": 287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "searchsorted", + "long_name": "searchsorted( a , v )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 33, + "parameters": [ + "a", + "v" + ], + "start_line": 289, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "oldnumeric.py", + "nloc": 18, + "complexity": 6, + "token_count": 137, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 298, + "end_line": 327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "squeeze", + "long_name": "squeeze( a )", + "filename": "oldnumeric.py", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "a" + ], + "start_line": 329, + "end_line": 335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "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": 337, + "end_line": 341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "trace", + "long_name": "trace( a , offset = 0 , axis1 = 0 , axis2 = 1 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 38, + "parameters": [ + "a", + "offset", + "axis1", + "axis2", + "dtype" + ], + "start_line": 343, + "end_line": 347, + "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": 349, + "end_line": 353, + "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": 6, + "complexity": 2, + "token_count": 28, + "parameters": [ + "a" + ], + "start_line": 355, + "end_line": 363, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( a )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 26, + "parameters": [ + "a" + ], + "start_line": 365, + "end_line": 373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , m , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "condition", + "m", + "axis" + ], + "start_line": 375, + "end_line": 383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "clip", + "long_name": "clip( m , m_min , m_max )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "m", + "m_min", + "m_max" + ], + "start_line": 385, + "end_line": 394, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "sum", + "long_name": "sum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 8, + "complexity": 3, + "token_count": 56, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 396, + "end_line": 423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "product", + "long_name": "product( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 425, + "end_line": 431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "sometrue", + "long_name": "sometrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "x", + "axis" + ], + "start_line": 433, + "end_line": 439, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "alltrue", + "long_name": "alltrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "x", + "axis" + ], + "start_line": 441, + "end_line": 447, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "any", + "long_name": "any( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "x", + "axis" + ], + "start_line": 449, + "end_line": 456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "all", + "long_name": "all( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "x", + "axis" + ], + "start_line": 458, + "end_line": 465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "cumsum", + "long_name": "cumsum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 467, + "end_line": 473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "cumproduct", + "long_name": "cumproduct( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 475, + "end_line": 481, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "ptp", + "long_name": "ptp( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "axis" + ], + "start_line": 483, + "end_line": 490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "amax", + "long_name": "amax( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "axis" + ], + "start_line": 492, + "end_line": 499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "amin", + "long_name": "amin( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "axis" + ], + "start_line": 501, + "end_line": 508, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "alen", + "long_name": "alen( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 28, + "parameters": [ + "a" + ], + "start_line": 510, + "end_line": 517, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "prod", + "long_name": "prod( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 519, + "end_line": 526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "cumprod", + "long_name": "cumprod( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 528, + "end_line": 535, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ndim", + "long_name": "ndim( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 21, + "parameters": [ + "a" + ], + "start_line": 537, + "end_line": 541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rank", + "long_name": "rank( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "a" + ], + "start_line": 543, + "end_line": 550, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( a , axis = None )", + "filename": "oldnumeric.py", + "nloc": 12, + "complexity": 4, + "token_count": 55, + "parameters": [ + "a", + "axis" + ], + "start_line": 552, + "end_line": 563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "round_", + "long_name": "round_( a , decimals = 0 )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "a", + "decimals" + ], + "start_line": 565, + "end_line": 576, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "mean", + "long_name": "mean( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 580, + "end_line": 585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "std", + "long_name": "std( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 587, + "end_line": 592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "var", + "long_name": "var( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 594, + "end_line": 599, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "reshape", + "long_name": "reshape( a , newshape , fortran = False )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 45, + "parameters": [ + "a", + "newshape", + "fortran" + ], + "start_line": 180, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , newshape )", + "filename": "oldnumeric.py", + "nloc": 6, + "complexity": 2, + "token_count": 33, + "parameters": [ + "a", + "newshape" + ], + "start_line": 180, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "nloc": 388, + "complexity": 91, + "token_count": 2403, + "diff_parsed": { + "added": [ + "def reshape(a, newshape, fortran=False):", + " result = a.reshape(newshape, fortran=fortran)", + " result = _wrapit(a, 'reshape', newshape, fortran=fortran)" + ], + "deleted": [ + "def reshape(a, newshape):", + " result = a.reshape(newshape)", + " result = _wrapit(a, 'reshape', newshape)" + ] + } + }, + { + "old_path": "numpy/core/src/arraymethods.c", + "new_path": "numpy/core/src/arraymethods.c", + "filename": "arraymethods.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -67,36 +67,28 @@ array_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds)\n \treturn PyArray_PutMask(self, values, mask);\n }\n \n-/* Used to reshape a Fortran Array */\n-static 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 0 then the result has fortran data order. \\n\"\\\n-\t\"If fortran < 0 then the result has fortran data order only if m\\n\"\n+\t\"If fortran is false then the result is contiguous (default). \\n\"\\\n+\t\"If fortran is true then the result has fortran data order. \\n\"\\\n+\t\"If fortran is None then the result has fortran data order only if m\\n\"\n \t\" is already in fortran order.\";\n \n static PyObject *\n array_copy(PyArrayObject *self, PyObject *args) \n {\n-\tint fortran=0;\n- if (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n+\tPyArray_CONDITION fortran=PyArray_FALSE;\n+ if (!PyArg_ParseTuple(args, \"|O&\", PyArray_ConditionConverter,\n+\t\t\t &fortran)) return NULL;\n \t\n return PyArray_NewCopy(self, fortran);\n }\n \n-static char doc_resize[] = \"self.resize(new_shape, refcheck=True). \"\\\n+static char doc_resize[] = \"self.resize(new_shape, refcheck=True, fortran=False). \"\\\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@@ -668,6 +642,7 @@ array_resize(PyArrayObject *self, PyObject *args, PyObject *kwds)\n PyObject *ret;\n \tint n;\n \tint refcheck = 1;\n+\tPyArray_CONDITION fortran=PyArray_DONTCARE;\n \t\n \tif (kwds != NULL) {\n \t\tPyObject *ref;\n@@ -678,6 +653,10 @@ array_resize(PyArrayObject *self, PyObject *args, PyObject *kwds)\n \t\t\t\treturn NULL;\n \t\t\t}\n \t\t}\n+\t\tref = PyDict_GetItemString(kwds, \"fortran\");\n+\t\tif (ref != NULL || \n+\t\t (PyArray_ConditionConverter(ref, &fortran) == PY_FAIL))\n+\t\t\treturn NULL;\n \t}\n \tn = PyTuple_Size(args);\n \tif (n <= 1) {\n@@ -692,9 +671,8 @@ array_resize(PyArrayObject *self, PyObject *args, PyObject *kwds)\n \t\t\t} \n \t\t\treturn NULL;\t\t\t\n \t\t}\n-\t}\n-\t\n-\tret = PyArray_Resize(self, &newshape, refcheck);\n+\t}\t\n+\tret = PyArray_Resize(self, &newshape, refcheck, fortran);\n PyDimMem_FREE(newshape.ptr);\n if (ret == NULL) return NULL;\n \tPy_DECREF(ret);\n@@ -1465,11 +1443,12 @@ static char doc_flatten[] = \"a.flatten([fortran]) return a 1-d array (always cop\n static PyObject *\n array_flatten(PyArrayObject *self, PyObject *args)\n {\n-\tint fortran=0;\n+\tPyArray_CONDITION fortran=PyArray_FALSE;\n \n-\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n+\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ConditionConverter, \n+\t\t\t &fortran)) return NULL;\n \n-\treturn PyArray_Flatten(self, (int) fortran);\n+\treturn PyArray_Flatten(self, fortran);\n }\n \n static char doc_ravel[] = \"a.ravel([fortran]) return a 1-d array (copy only if needed)\";\n@@ -1477,9 +1456,10 @@ static char doc_ravel[] = \"a.ravel([fortran]) return a 1-d array (copy only if n\n static PyObject *\n array_ravel(PyArrayObject *self, PyObject *args)\n {\n-\tint fortran=0;\n-\n-\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n+\tPyArray_CONDITION fortran=PyArray_FALSE;\n+\t\n+\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ConditionConverter, \n+\t\t\t &fortran)) return NULL;\n \n \treturn PyArray_Ravel(self, fortran);\n }\n@@ -1642,7 +1622,7 @@ static PyMethodDef array_methods[] = {\n \t{\"argmin\", (PyCFunction)array_argmin,\n \t METH_VARARGS|METH_KEYWORDS, doc_argmin},\n \t{\"reshape\",\t(PyCFunction)array_reshape, \n-\t METH_VARARGS, doc_reshape},\n+\t METH_VARARGS|METH_KEYWORDS, doc_reshape},\n \t{\"squeeze\",\t(PyCFunction)array_squeeze,\n \t METH_VARARGS, doc_squeeze},\n \t{\"view\", (PyCFunction)array_view, \n", + "added_lines": 40, + "deleted_lines": 60, + "source_code": "\n/* Should only be used if x is known to be an nd-array */\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_take[] = \"a.take(indices, axis=None). Selects the elements \"\\\n\t\"in indices from array a along the given axis.\";\n\nstatic PyObject *\narray_take(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint dimension=MAX_DIMS;\n\tPyObject *indices;\n\tstatic char *kwlist[] = {\"indices\", \"axis\", NULL};\n\t\n\tdimension=0;\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &indices, PyArray_AxisConverter,\n\t\t\t\t\t &dimension))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Take(self, indices, dimension));\n}\n\nstatic char doc_fill[] = \"a.fill(value) places the scalar value at every \"\\\n\t\"position in the array.\";\n\nstatic PyObject *\narray_fill(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *obj;\n\tif (!PyArg_ParseTuple(args, \"O\", &obj))\n\t\treturn NULL;\n\tif (PyArray_FillWithScalar(self, obj) < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_put[] = \"a.put(values, indices) sets a.flat[n] = v[n] \"\\\n\t\"for each n in indices. v can be scalar or shorter than indices, \"\\\n\t\"will repeat.\";\n\nstatic PyObject *\narray_put(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *indices, *values;\n\tstatic char *kwlist[] = {\"values\", \"indices\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &values, &indices))\n\t\treturn NULL;\n\treturn PyArray_Put(self, values, indices);\n}\n\nstatic char doc_putmask[] = \"a.putmask(values, mask) sets a.flat[n] = v[n] \"\\\n\t\"for each n where mask.flat[n] is TRUE. v can be scalar.\";\n\nstatic PyObject *\narray_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *mask, *values;\n\n\tstatic char *kwlist[] = {\"values\", \"mask\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &values, &mask))\n\t\treturn NULL;\n\treturn PyArray_PutMask(self, values, mask);\n}\n\nstatic char doc_reshape[] = \\\n\t\"self.reshape(d1, d2, ..., dn, fortran=False) \\n\"\t\\\n\t\"Return a new array from this one. \\n\"\t\t\t\t\\\n\t\"\\n The new array must have the same number of elements as self. \" \\\n\t\"Also\\n a copy of the data only occurs if necessary.\";\n\nstatic PyObject *\narray_reshape(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n PyArray_Dims newshape;\n PyObject *ret;\n\tPyArray_CONDITION fortran=PyArray_FALSE;\n\tint n;\n\t\n\tif (kwds != NULL) {\n\t\tPyObject *ref;\n\t\tref = PyDict_GetItemString(kwds, \"fortran\");\n\t\tif (ref == NULL || \\\n\t\t (PyArray_ConditionConverter(ref, &fortran) == PY_FAIL))\n\t\t\treturn NULL;\n\t}\n\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\tgoto fail;\n\t\t}\n\t}\n\n\tif (newshape.len == 1) {\n\t\tPyDimMem_FREE(newshape.ptr);\n\t\treturn PyArray_Ravel(self, 0);\n\t}\n\t\n\tret = PyArray_Newshape(self, &newshape, fortran);\n\n\tPyDimMem_FREE(newshape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(newshape.ptr);\n\treturn NULL;\n}\n\nstatic char doc_squeeze[] = \"m.squeeze() eliminate all length-1 dimensions\";\n\nstatic PyObject *\narray_squeeze(PyArrayObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n return _ARET(PyArray_Squeeze(self));\n}\n\nstatic char doc_view[] = \"a.view() return a new view of array with same data. type can be either a new sub-type object or a data-descriptor object\";\n\nstatic PyObject *\narray_view(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *otype=NULL;\n PyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTuple(args, \"|O\", &otype)) return NULL;\n\n\tif (otype) {\n\t\tif (PyType_Check(otype) &&\t\t\t\\\n\t\t PyType_IsSubtype((PyTypeObject *)otype, \n\t\t\t\t &PyArray_Type)) {\n\t\t\treturn PyArray_View(self, NULL, \n (PyTypeObject *)otype);\n }\n\t\telse {\n\t\t\tif (PyArray_DescrConverter(otype, &type) == PY_FAIL) \n\t\t\t\treturn NULL;\n\t\t}\n\t}\n\treturn PyArray_View(self, type, NULL);\n}\n\nstatic char doc_argmax[] = \"a.argmax(axis=None)\";\n\nstatic PyObject *\narray_argmax(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\n\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\n\t\n\treturn PyArray_Min(self, axis);\n}\n\nstatic char doc_swapaxes[] = \"a.swapaxes(axis1, axis2) returns new view with axes swapped.\";\n\nstatic PyObject *\narray_swapaxes(PyArrayObject *self, PyObject *args)\n{\n\tint axis1, axis2;\n\n\tif (!PyArg_ParseTuple(args, \"ii\", &axis1, &axis2)) return NULL;\n\n\treturn PyArray_SwapAxes(self, axis1, axis2);\n}\n\nstatic char doc_getfield[] = \"m.getfield(dtype, offset) returns a field \"\\\n\t\" of the given array as a certain type. A field is a view of \"\\\n\t\" the array's data with each itemsize determined by the given type\"\\\n\t\" and the offset into the current array.\";\n\n/* steals typed reference */\n/*OBJECT_API\n Get a subset of bytes from each element of the array\n*/\nstatic PyObject *\nPyArray_GetField(PyArrayObject *self, PyArray_Descr *typed, int offset)\n{\n\tPyObject *ret=NULL;\n\n\tif (offset < 0 || (offset + typed->elsize) > self->descr->elsize) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need 0 <= offset <= %d for requested type \" \\\n\t\t\t \"but received offset = %d\",\n\t\t\t self->descr->elsize-typed->elsize, offset);\n\t\tPy_DECREF(typed);\n\t\treturn NULL;\n\t}\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t typed,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, \n\t\t\t\t self->data + offset,\n\t\t\t\t self->flags, (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self; \n\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\treturn ret;\n}\n\nstatic PyObject *\narray_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\n PyArray_Descr *dtype;\n\tint offset = 0;\n\tstatic char *kwlist[] = {\"dtype\", \"offset\", 0};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|i\", kwlist,\n\t\t\t\t\t PyArray_DescrConverter,\n\t\t\t\t\t &dtype, &offset)) return NULL;\n\t\n\treturn _ARET(PyArray_GetField(self, dtype, offset));\n}\n\n\nstatic char doc_setfield[] = \"m.setfield(value, dtype, offset) places val \"\\\n\t\"into field of the given array defined by the data type and offset.\";\n\n/*OBJECT_API\n Set a subset of bytes from each element of the array\n*/\nstatic int\nPyArray_SetField(PyArrayObject *self, PyArray_Descr *dtype,\n\t\t int offset, PyObject *val)\n{\n\tPyObject *ret=NULL;\n\tint retval = 0;\n \n\tif (offset < 0 || (offset + dtype->elsize) > self->descr->elsize) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need 0 <= offset <= %d for requested type \" \\\n\t\t\t \"but received offset = %d\",\n\t\t\t self->descr->elsize-dtype->elsize, offset);\n\t\tPy_DECREF(dtype);\n\t\treturn -1;\n\t}\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t dtype, self->nd, self->dimensions,\n\t\t\t\t self->strides, self->data + offset,\n\t\t\t\t self->flags, (PyObject *)self);\n\tif (ret == NULL) return -1;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self;\n\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\t\n\tretval = PyArray_CopyObject((PyArrayObject *)ret, val);\n\tPy_DECREF(ret);\n\treturn retval;\n}\n\nstatic PyObject *\narray_setfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n PyArray_Descr *dtype;\n\tint offset = 0;\n\tPyObject *value;\n\tstatic char *kwlist[] = {\"value\", \"dtype\", \"offset\", 0};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO&|i\", kwlist,\n\t\t\t\t\t &value, PyArray_DescrConverter,\n\t\t\t\t\t &dtype, &offset)) return NULL;\n\n\tif (PyArray_SetField(self, dtype, offset, value) < 0)\n\t\treturn NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n/* This doesn't change the descriptor just the actual data...\n */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_Byteswap(PyArrayObject *self, Bool inplace)\n{\n PyArrayObject *ret;\n\tintp size;\n\tPyArray_CopySwapNFunc *copyswapn;\n\tPyArray_CopySwapFunc *copyswap;\n\tPyArrayIterObject *it;\n\n\tif (inplace) {\n\t\tcopyswapn = self->descr->f->copyswapn;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\t\tif (PyArray_ISONESEGMENT(self)) {\n\t\t\tcopyswapn(self->data, NULL, size, 1, \n\t\t\t\t self->descr->elsize);\n\t\t}\n\t\telse { /* Use iterator */\n\t\t\t\n\t\t\tit = (PyArrayIterObject *)\\\n\t\t\t\tPyArray_IterNew((PyObject *)self);\n\t\t\tcopyswap = self->descr->f->copyswap;\n\t\t\twhile (it->index < it->size) {\n\t\t\t\tcopyswap(it->dataptr, NULL, 1, \n\t\t\t\t\t self->descr->elsize);\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t}\n\t\t\tPy_DECREF(it);\n\t\t}\n\t\t\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tif ((ret = (PyArrayObject *)PyArray_NewCopy(self,-1)) == NULL) \n\t\t\treturn NULL;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\n\t\t/* now ret has the same dtypedescr as self (including\n\t\t byteorder)\n\t\t*/\n\n\t\tret->descr->f->copyswapn(ret->data, NULL, size, 1, \n\t\t\t\t\t ret->descr->elsize);\n\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic char doc_byteswap[] = \"m.byteswap(False) Swap the bytes in\"\\\n\t\" the array. Return the byteswapped array. If the first argument\"\\\n\t\" is TRUE, byteswap in-place and return a reference to self.\";\n\nstatic PyObject *\narray_byteswap(PyArrayObject *self, PyObject *args) \n{\n\tBool inplace=FALSE;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter, &inplace))\n\t\treturn NULL;\n\t\n\treturn PyArray_Byteswap(self, inplace);\n}\n\nstatic char doc_tolist[] = \"m.tolist().\t Copy the data portion of the array\"\\\n\t\" to a hierarchical python list and return that list.\";\n\nstatic PyObject *\narray_tolist(PyArrayObject *self, PyObject *args) \n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n if (self->nd <= 0) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"can't convert a 0-d array to a list\");\n return NULL;\n }\n\t\n return PyArray_ToList(self);\n}\n\nstatic char doc_tostring[] = \"m.tostring() Construct a Python string \"\\\n \"containing the raw bytes in the array\";\n\nstatic PyObject *\narray_tostring(PyArrayObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n return PyArray_ToString(self);\n}\n\nstatic char doc_tofile[] = \"m.tofile(fid, sep=\"\") write the data to a file.\";\n\nstatic PyObject *\narray_tofile(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tint ret;\n PyObject *file;\n\tFILE *fd;\n char *sep=\"\";\n\tchar *format=\"\";\n\tchar *mode=\"\";\n\tstatic char *kwlist[] = {\"file\", \"sep\", \"format\", NULL};\n \n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ss\", kwlist, \n &file, &sep, &format)) return NULL;\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"wb\";\n\t\telse mode=\"w\";\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), mode);\n\t\tif (file==NULL) return NULL;\n\t}\n\telse {\n\t\tPy_INCREF(file);\n\t}\n\tfd = PyFile_AsFile(file);\n\tif (fd == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \"first argument must be a \" \\\n\t\t\t\t\"string or open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_ToFile(self, fd, sep, format);\n\tPy_DECREF(file);\n\tif (ret < 0) return NULL;\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_toscalar[] = \"m.item(). Copy the first data point of \"\\\n\t\"the array to a standard Python scalar and return it.\";\n\nstatic PyObject *\narray_toscalar(PyArrayObject *self, PyObject *args) {\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\tif (self->nd == 0 || PyArray_SIZE(self) == 1) \n\t\treturn self->descr->f->getitem(self->data, self);\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError, \"can only convert an\"\t\\\n\t\t\t\t\" array of size 1 to Python scalar.\");\n\t\treturn NULL;\n\t}\n}\n\nstatic char doc_cast[] = \"m.astype(t).\tCast array m to type t.\t \\n\\n\"\\\n\t\"t can be either a string representing a typecode, or a python type\"\\\n\t\" object of type int, float, or complex.\";\n\nstatic PyObject *\narray_cast(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Descr *descr=NULL;\n\tPyObject *obj;\n\t\n if (!PyArg_ParseTuple(args, \"O&\", PyArray_DescrConverter,\n\t\t\t &descr)) return NULL;\n\t\n\tif (descr == self->descr) {\n\t\tobj = _ARET(PyArray_NewCopy(self,0));\n\t\tPy_XDECREF(descr);\n\t\treturn obj;\n\t}\n\treturn _ARET(PyArray_CastToType(self, descr, 0));\n}\t \n\n/* default sub-type implementation */\n\nstatic char doc_wraparray[] = \"m.__array_wrap__(obj) returns an object of \"\\\n\t\"type m from the ndarray object obj\";\n\nstatic PyObject *\narray_wraparray(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *arr;\n\tPyObject *ret;\n\t\n\tif (PyTuple_Size(args) < 1) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"only accepts 1 argument\");\n\t\treturn NULL;\n\t}\n\tarr = PyTuple_GET_ITEM(args, 0);\n\tif (!PyArray_Check(arr)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"can only be called with ndarray object\");\n\t\treturn NULL;\n\t}\t\n\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t PyArray_NDIM(arr),\n\t\t\t\t PyArray_DIMS(arr), \n\t\t\t\t PyArray_STRIDES(arr), PyArray_DATA(arr),\n\t\t\t\t PyArray_FLAGS(arr), (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(arr);\n\tPyArray_BASE(ret) = arr;\n\treturn ret;\n}\n\n/* NO-OP --- just so all subclasses will have one by default. */\nstatic PyObject *\narray_finalize(PyArrayObject *self, PyObject *args)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic char doc_array_getarray[] = \"m.__array__(|dtype) just returns either a new reference to self if dtype is not given or a new array of provided data type if dtype is different from the current dtype of the array.\";\n\nstatic PyObject *\narray_getarray(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Descr *newtype=NULL;\n\tPyObject *ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_DescrConverter,\n\t\t\t &newtype)) return NULL;\n\t\n\t/* convert to PyArray_Type */\n\tif (!PyArray_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 = &PyArray_Type;\n\t\t}\n\t\t\n\t\tPy_INCREF(PyArray_DESCR(self));\n\t\tnew = PyArray_NewFromDescr(subtype, \n\t\t\t\t\t PyArray_DESCR(self),\n\t\t\t\t\t PyArray_NDIM(self),\n\t\t\t\t\t PyArray_DIMS(self), \n\t\t\t\t\t PyArray_STRIDES(self), \n\t\t\t\t\t PyArray_DATA(self),\n\t\t\t\t\t PyArray_FLAGS(self), NULL);\n\t\tif (new == NULL) return NULL;\n\t\tPy_INCREF(self);\n\t\tPyArray_BASE(new) = (PyObject *)self;\n\t\tself = (PyArrayObject *)new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t}\n\t\t\n\tif ((newtype == NULL) || \\\n\t PyArray_EquivTypes(self->descr, newtype)) {\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tret = PyArray_CastToType(self, newtype, 0);\n\t\tPy_DECREF(self);\n\t\treturn ret;\n\t}\n}\n\nstatic char doc_copy[] = \"m.copy(|fortran). Return a copy of the array.\\n\"\\\n\t\"If fortran is false then the result is contiguous (default). \\n\"\\\n\t\"If fortran is true then the result has fortran data order. \\n\"\\\n\t\"If fortran is None then the result has fortran data order only if m\\n\"\n\t\" is already in fortran order.\";\n\nstatic PyObject *\narray_copy(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_CONDITION fortran=PyArray_FALSE;\n if (!PyArg_ParseTuple(args, \"|O&\", PyArray_ConditionConverter,\n\t\t\t &fortran)) return NULL;\n\t\n return PyArray_NewCopy(self, fortran);\n}\n\nstatic char doc_resize[] = \"self.resize(new_shape, refcheck=True, fortran=False). \"\\\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, PyObject *kwds) \n{\n PyArray_Dims newshape;\n PyObject *ret;\n\tint n;\n\tint refcheck = 1;\n\tPyArray_CONDITION fortran=PyArray_DONTCARE;\n\t\n\tif (kwds != NULL) {\n\t\tPyObject *ref;\n\t\tref = PyDict_GetItemString(kwds, \"refcheck\");\n\t\tif (ref) {\n\t\t\trefcheck = PyInt_AsLong(ref);\n\t\t\tif (refcheck==-1 && PyErr_Occurred()) {\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\tref = PyDict_GetItemString(kwds, \"fortran\");\n\t\tif (ref != NULL || \n\t\t (PyArray_ConditionConverter(ref, &fortran) == PY_FAIL))\n\t\t\treturn NULL;\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}\t\n\tret = PyArray_Resize(self, &newshape, refcheck, fortran);\n PyDimMem_FREE(newshape.ptr);\n if (ret == NULL) return NULL;\n\tPy_DECREF(ret);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_repeat[] = \"a.repeat(repeats=, axis=None)\\n\"\\\n\t\"\\n\"\\\n\t\" Copy elements of a, repeats times. The repeats argument must\\n\"\\\n\t\" be a sequence of length a.shape[axis] or a scalar.\";\n\nstatic PyObject *\narray_repeat(PyArrayObject *self, PyObject *args, PyObject *kwds) {\n\tPyObject *repeats;\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"repeats\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &repeats, PyArray_AxisConverter,\n\t\t\t\t\t &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_Repeat(self, repeats, axis));\n}\n\nstatic char doc_choose[] = \"a.choose(b0, b1, ..., bn)\\n\"\\\n\t\"\\n\"\\\n\t\"Return an array with elements chosen from 'a' at the positions\\n\"\\\n \"of the given arrays b_i. The array 'a' should be an integer array\\n\"\\\n \"with entries from 0 to n+1, and the b_i arrays should have the same\\n\"\\\n \"shape as 'a'.\";\n\nstatic PyObject *\narray_choose(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *choices;\n\tint n;\n\t\n\tn = PyTuple_Size(args);\n\tif (n <= 1) {\n\t\tif (!PyArg_ParseTuple(args, \"O\", &choices))\n\t\t\treturn NULL;\n\t}\n else {\n\t\tchoices = args;\n\t}\n\t\n\treturn _ARET(PyArray_Choose(self, choices));\n}\n\nstatic char doc_sort[] = \"a.sort(axis=-1,kind='quicksort') sorts in place along axis. Return is None and kind can be 'quicksort', 'mergesort', or 'heapsort'\";\n\nstatic PyObject *\narray_sort(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=-1;\n\tint val;\n\tPyArray_SORTKIND which=PyArray_QUICKSORT;\n\tstatic char *kwlist[] = {\"axis\", \"kind\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iO&\", kwlist, &axis,\n\t\t\t\t\t PyArray_SortkindConverter, &which))\n\t\treturn NULL;\n\t\n\tval = PyArray_Sort(self, axis, which);\n\tif (val < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_argsort[] = \"a.argsort(axis=-1,kind='quicksort')\\n\"\\\n\t\" Return the indexes into a that would sort it along the\"\\\n\t\" given axis; kind can be 'quicksort', 'mergesort', or 'heapsort'\";\n\nstatic PyObject *\narray_argsort(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=-1;\n\tPyArray_SORTKIND which=PyArray_QUICKSORT;\n\tstatic char *kwlist[] = {\"axis\", \"kind\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iO&\", kwlist, &axis,\n\t\t\t\t\t PyArray_SortkindConverter, &which))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_ArgSort(self, axis, which));\n}\n\nstatic char doc_searchsorted[] = \"a.searchsorted(v)\\n\"\\\n\t\" Assuming that a is a 1-D array, in ascending order and\\n\"\\\n\t\" represents bin boundaries, then a.searchsorted(values) gives an\\n\"\\\n\t\" array of bin numbers, giving the bin into which each value would\\n\"\\\n\t\" be placed. This method is helpful for histograming. \\n\"\\\n\t\" Note: No warning is given if the boundaries, in a, are not \\n\"\\\n\t\" in ascending order.\";\n\nstatic PyObject *\narray_searchsorted(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *values;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &values)) return NULL;\n\t\n\treturn _ARET(PyArray_SearchSorted(self, values));\n}\n\nstatic char doc_deepcopy[] = \"Used if copy.deepcopy is called on an array.\";\n\nstatic PyObject *\narray_deepcopy(PyArrayObject *self, PyObject *args) \n{\n PyObject* visit;\n PyObject **optr;\n PyArrayIterObject *it;\n PyObject *copy, *ret, *deepcopy, *temp, *res;\n\n if (!PyArg_ParseTuple(args, \"O\", &visit)) return NULL;\n ret = PyArray_Copy(self);\n if (PyArray_ISOBJECT(self)) {\n copy = PyImport_ImportModule(\"copy\");\n if (copy == NULL) return NULL;\n deepcopy = PyObject_GetAttrString(copy, \"deepcopy\");\n Py_DECREF(copy);\n if (deepcopy == NULL) return NULL;\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it == NULL) {Py_DECREF(deepcopy); return NULL;}\n optr = (PyObject **)PyArray_DATA(ret);\n while(it->index < it->size) {\n temp = *((PyObject **)it->dataptr);\n Py_INCREF(temp);\n /* call deepcopy on this argument */\n res = PyObject_CallFunctionObjArgs(deepcopy, \n temp, visit, NULL);\n Py_DECREF(temp);\n Py_DECREF(*optr);\n *optr++ = res;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(deepcopy);\n Py_DECREF(it);\n }\n return _ARET(ret);\n}\n\n/* Convert Object Array to flat list and pickle the flat list string */\nstatic PyObject *\n_getobject_pkl(PyArrayObject *self)\n{\n\tPyObject *theobject;\n\tPyArrayIterObject *iter=NULL;\n\tPyObject *list;\n\n\t\n\titer = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (iter == NULL) return NULL;\n\tlist = PyList_New(iter->size);\n\tif (list == NULL) {Py_DECREF(iter); return NULL;}\n\twhile (iter->index < iter->size) {\n\t\ttheobject = *((PyObject **)iter->dataptr);\n\t\tPy_INCREF(theobject);\n\t\tPyList_SET_ITEM(list, (int) iter->index, theobject);\n\t\tPyArray_ITER_NEXT(iter);\n\t}\n\tPy_DECREF(iter);\n\treturn list;\n}\n\nstatic int\n_setobject_pkl(PyArrayObject *self, PyObject *list)\n{\n\tPyObject *theobject;\n\tPyArrayIterObject *iter=NULL;\n\tint size;\n\n\tsize = self->descr->elsize;\n\t\n\titer = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (iter == NULL) return -1;\n\twhile(iter->index < iter->size) {\n\t\ttheobject = PyList_GET_ITEM(list, (int) iter->index);\n\t\tPy_INCREF(theobject);\n\t\t*((PyObject **)iter->dataptr) = theobject;\n\t\tPyArray_ITER_NEXT(iter);\n\t}\n\tPy_XDECREF(iter);\n\treturn 0;\n}\n\nstatic char doc_reduce[] = \"a.__reduce__() for pickling.\";\n\nstatic PyObject *\narray_reduce(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *ret=NULL, *state=NULL, *obj=NULL, *mod=NULL;\n\tPyObject *mybool, *thestr=NULL;\n\tPyArray_Descr *descr;\n\n\t/* Return a tuple of (callable object, arguments, object's state) */\n\t/* We will put everything in the object's state, so that on UnPickle\n\t it can use the string object as memory without a copy */\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core._internal\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"_reconstruct\");\n\tPy_DECREF(mod);\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t Py_BuildValue(\"ONN\",\n\t\t\t\t (PyObject *)self->ob_type,\n\t\t\t\t Py_BuildValue(\"(N)\",\n\t\t\t\t\t\t PyInt_FromLong(0)),\n\t\t\t\t PyObject_GetAttrString((PyObject *)(self->descr),\n\t\t\t\t\t\t\t \"char\")));\n\t\n\t/* Now fill in object's state. This is a tuple with \n\t 4 arguments\n\n\t 1) a Tuple giving the shape\n\t 2) a PyArray_Descr Object (with correct bytorder set)\n\t 3) a Bool stating if Fortran or not\n\t 4) a binary string with the data (or a list for Object arrays)\n\n\t Notice because Python does not describe a mechanism to write \n\t raw data to the pickle, this performs a copy to a string first\n\t*/\n\n\tstate = PyTuple_New(4);\n\tif (state == NULL) {\n\t\tPy_DECREF(ret); return NULL;\n\t}\n\tPyTuple_SET_ITEM(state, 0, PyObject_GetAttrString((PyObject *)self, \n\t\t\t\t\t\t\t \"shape\"));\n\tdescr = self->descr;\n\tPy_INCREF(descr);\n\tPyTuple_SET_ITEM(state, 1, (PyObject *)descr);\n\tmybool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);\n\tPy_INCREF(mybool);\n\tPyTuple_SET_ITEM(state, 2, mybool);\n\tif (PyArray_ISOBJECT(self)) {\n\t\tthestr = _getobject_pkl(self);\n\t}\n\telse {\n thestr = PyArray_ToString(self);\n\t}\n\tif (thestr == NULL) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(state);\n\t\treturn NULL;\n\t}\n\tPyTuple_SET_ITEM(state, 3, thestr);\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\nstatic char doc_setstate[] = \"a.__setstate__(tuple) for unpickling.\";\n\n/*\n\t 1) a Tuple giving the shape\n\t 2) a PyArray_Descr Object\n\t 3) a Bool stating if Fortran or not\n\t 4) a binary string with the data (or a list if Object array) \n*/\n\nstatic intp _array_fill_strides(intp *, intp *, int, intp, int, int *);\n\nstatic int _IsAligned(PyArrayObject *); \n\nstatic PyArray_Descr * _array_typedescr_fromstr(char *);\n\nstatic PyObject *\narray_setstate(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *shape;\n\tPyArray_Descr *typecode;\n\tint fortran;\n\tPyObject *rawdata;\n\tchar *datastr;\n\tint len;\n\tintp dimensions[MAX_DIMS];\n\tint nd;\n\t\n\t/* This will free any memory associated with a and\n\t use the string in setstate as the (writeable) memory.\n\t*/\n\tif (!PyArg_ParseTuple(args, \"(O!O!iO)\", &PyTuple_Type,\n\t\t\t &shape, &PyArrayDescr_Type, &typecode, \n\t\t\t &fortran, &rawdata))\n\t\treturn NULL;\n\n\tPy_XDECREF(self->descr);\n\tself->descr = typecode;\n\tPy_INCREF(typecode);\n\tnd = PyArray_IntpFromSequence(shape, dimensions, MAX_DIMS);\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (!PyList_Check(rawdata)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"object pickle not returning list\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tif (!PyString_Check(rawdata)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"pickle not returning string\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (PyString_AsStringAndSize(rawdata, &datastr, &len))\n\t\t\treturn NULL;\n\n\t\tif ((len != (self->descr->elsize *\t\t\t\\\n\t\t\t (int) PyArray_MultiplyList(dimensions, nd)))) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size does not\"\t\\\n\t\t\t\t\t\" match array size\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n if ((self->flags & OWN_DATA)) {\n\t\tif (self->data != NULL)\n\t\t\tPyDataMem_FREE(self->data);\n\t\tself->flags &= ~OWN_DATA;\n }\n\tPy_XDECREF(self->base);\n\n\tself->flags &= ~UPDATEIFCOPY;\n\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t\tself->dimensions = NULL;\n\t}\n\n\tself->flags = DEFAULT_FLAGS;\n\n\tself->nd = nd;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(nd * 2);\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dimensions, sizeof(intp)*nd);\n\t\t(void) _array_fill_strides(self->strides, dimensions, nd,\n\t\t\t\t\t self->descr->elsize, \n (fortran ? FORTRAN : CONTIGUOUS),\n\t\t\t\t\t &(self->flags));\n\t}\n\n\tif (typecode->type_num != PyArray_OBJECT) {\n\t\tself->data = datastr;\n\t\tif (!_IsAligned(self)) {\n\t\t\tintp num = PyArray_NBYTES(self);\n\t\t\tself->data = PyDataMem_NEW(num);\n\t\t\tif (self->data == NULL) {\n\t\t\t\tself->nd = 0;\n\t\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemcpy(self->data, datastr, num);\n\t\t\tself->flags |= OWN_DATA;\n\t\t\tself->base = NULL;\n\t\t}\n\t\telse {\n\t\t\tself->base = rawdata;\n\t\t\tPy_INCREF(self->base);\n\t\t}\n\t}\n\telse {\n\t\tself->data = PyDataMem_NEW(PyArray_NBYTES(self));\n\t\tif (self->data == NULL) { \n\t\t\tself->nd = 0;\n\t\t\tself->data = PyDataMem_NEW(self->descr->elsize);\n\t\t\tif (self->dimensions) PyDimMem_FREE(self->dimensions);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\t\tself->base = NULL;\n\t\tif (_setobject_pkl(self, rawdata) < 0) \n\t\t\treturn NULL;\n\t}\n\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\t\n}\n\n/*OBJECT_API*/\nstatic int\nPyArray_Dump(PyObject *self, PyObject *file, int protocol)\n{\n\tPyObject *cpick=NULL;\n\tPyObject *ret;\n\tif (protocol < 0) protocol = 2;\n\n\tcpick = PyImport_ImportModule(\"cPickle\");\n\tif (cpick==NULL) return -1;\n\n\tif PyString_Check(file) {\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), \"wb\");\n\t\tif (file==NULL) return -1;\n\t}\n\telse Py_INCREF(file);\n\tret = PyObject_CallMethod(cpick, \"dump\", \"OOi\", self, \n\t\t\t\t file, protocol);\n\tPy_XDECREF(ret);\n\tPy_DECREF(file);\n\tPy_DECREF(cpick);\n\tif (PyErr_Occurred()) return -1;\n\treturn 0;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_Dumps(PyObject *self, int protocol)\n{\n\tPyObject *cpick=NULL;\n\tPyObject *ret;\n\tif (protocol < 0) protocol = 2;\n\n\tcpick = PyImport_ImportModule(\"cPickle\");\n\tif (cpick==NULL) return NULL;\n\tret = PyObject_CallMethod(cpick, \"dumps\", \"Oi\", self, protocol);\n\tPy_DECREF(cpick);\n\treturn ret;\n}\n\n\nstatic char doc_dump[] = \"m.dump(file)\";\n\nstatic PyObject *\narray_dump(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *file=NULL;\n\tint ret;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &file))\n\t\treturn NULL;\n\tret = PyArray_Dump((PyObject *)self, file, 2);\n\tif (ret < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_dumps[] = \"m.dumps()\";\n\nstatic PyObject *\narray_dumps(PyArrayObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\"))\n\t\treturn NULL;\n\treturn PyArray_Dumps((PyObject *)self, 2);\n}\n\n\nstatic char doc_transpose[] = \"m.transpose()\";\n\nstatic PyObject *\narray_transpose(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *shape=Py_None;\n\tint n;\n\tPyArray_Dims permute;\n\tPyObject *ret;\n\n\tn = PyTuple_Size(args);\n\tif (n > 1) shape = args;\n\telse if (n == 1) shape = PyTuple_GET_ITEM(args, 0);\n\t\n\tif (shape == Py_None)\n\t\tret = PyArray_Transpose(self, NULL);\n\telse {\n\t\tif (!PyArray_IntpConverter(shape, &permute)) return NULL;\n\t\tret = PyArray_Transpose(self, &permute);\n\t\tPyDimMem_FREE(permute.ptr);\n\t}\n\t\n\treturn _ARET(ret);\n}\n\nstatic char doc_mean[] = \"a.mean(axis=None, dtype=None)\\n\\n\"\\\n \"Average the array over the given axis. If the axis is None, average\\n\"\\\n \"over all dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, dtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\\n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, dtype) * 1.0 / product(a.shape)\\n\"\\\n \"\\n\"\\\n \"The optional dtype argument is the data type for intermediate\\n\"\\\n \"calculations in the sum.\";\n\n#define _CHKTYPENUM(typ) ((typ) ? (typ)->type_num : PyArray_NOTYPE)\n\nstatic PyObject *\narray_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist,\n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\n\treturn PyArray_Mean(self, axis, _CHKTYPENUM(dtype));\n}\n\nstatic char doc_sum[] = \"a.sum(axis=None, dtype=None)\\n\\n\"\\\n \"Sum the array over the given axis. If the axis is None, sum over all\\n\"\\\n \"dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"The optional dtype argument is the data type for the returned value\\n\"\\\n \"and intermediate calculations. The default is to upcast (promote)\\n\"\\\n \"smaller integer types to the platform-dependent int. For example, on\\n\"\\\n \"32-bit platforms:\\n\"\\\n \"\\n\"\\\n \" a.dtype default sum() dtype\\n\"\\\n \" ---------------------------------------------------\\n\"\\\n \" bool, int8, int16, int32 int32\\n\"\\\n \"\\n\"\\\n \"Examples:\\n\"\\\n \"\\n\"\\\n \">>> array([0.5, 1.5]).sum()\\n\"\\\n \"2.0\\n\"\\\n \">>> array([0.5, 1.5]).sum(dtype=int32)\\n\"\\\n \"1\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum(axis=0)\\n\"\\\n \"array([0, 6])\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum(axis=1)\\n\"\\\n \"array([1, 5])\";\n\nstatic PyObject *\narray_sum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Sum(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_cumsum[] = \"a.cumsum(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_CumSum(self, axis, _CHKTYPENUM(dtype));\n}\n\nstatic char doc_prod[] = \"a.prod(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Prod(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_cumprod[] = \"a.cumprod(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_CumProd(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_any[] = \"a.any(axis=None)\";\n\nstatic PyObject *\narray_any(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\n\n\treturn PyArray_All(self, axis);\n}\n\nstatic char doc_stddev[] = \"a.std(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, _CHKTYPENUM(dtype), 0);\n}\n\nstatic char doc_variance[] = \"a.var(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_variance(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, _CHKTYPENUM(dtype), 1);\n}\n\nstatic char doc_compress[] = \"a.compress(condition=, axis=None)\";\n\nstatic PyObject *\narray_compress(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyObject *condition;\t\n\tstatic char *kwlist[] = {\"condition\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &condition, PyArray_AxisConverter,\n\t\t\t\t\t &axis)) return NULL;\n\n\treturn _ARET(PyArray_Compress(self, condition, axis));\n}\n\nstatic char doc_nonzero[] = \"a.nonzero() return a tuple of indices referencing \"\\\n\t\"the elements of a that are nonzero.\";\n\nstatic PyObject *\narray_nonzero(PyArrayObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\treturn _ARET(PyArray_Nonzero(self));\n}\n\n\nstatic char doc_trace[] = \"a.trace(offset=0, axis1=0, axis2=1, dtype=None)\\n\"\\\n\t\"return the sum along the offset diagonal of the arrays indicated\\n\" \\\n\t\"axis1 and axis2.\";\n\nstatic PyObject *\narray_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iiiO&\", kwlist, \n\t\t\t\t\t &offset, &axis1, &axis2,\n\t\t\t\t\t PyArray_DescrConverter2, &dtype))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Trace(self, offset, axis1, axis2, \n\t\t\t\t _CHKTYPENUM(dtype)));\n}\n\n#undef _CHKTYPENUM\n\n\nstatic char doc_clip[] = \"a.clip(min=, max=)\";\n\nstatic PyObject *\narray_clip(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *min, *max;\n\tstatic char *kwlist[] = {\"min\", \"max\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &min, &max)) \n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Clip(self, min, max));\n}\n\nstatic char doc_conj[] = \"a.conj()\";\n\nstatic char doc_conjugate[] = \"a.conjugate()\";\n\nstatic PyObject *\narray_conjugate(PyArrayObject *self, PyObject *args) \n{\n\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n\treturn PyArray_Conjugate(self);\n}\n\n\nstatic char doc_diagonal[] = \"a.diagonal(offset=0, axis1=0, axis2=1)\";\n\nstatic PyObject *\narray_diagonal(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iii\", kwlist, \n\t\t\t\t\t &offset, &axis1, &axis2))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Diagonal(self, offset, axis1, axis2));\n}\n\nstatic char doc_flatten[] = \"a.flatten([fortran]) return a 1-d array (always copy)\";\n\nstatic PyObject *\narray_flatten(PyArrayObject *self, PyObject *args)\n{\n\tPyArray_CONDITION fortran=PyArray_FALSE;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ConditionConverter, \n\t\t\t &fortran)) return NULL;\n \n\treturn PyArray_Flatten(self, 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\tPyArray_CONDITION fortran=PyArray_FALSE;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ConditionConverter, \n\t\t\t &fortran)) return NULL;\n\n\treturn PyArray_Ravel(self, fortran);\n}\n\nstatic char doc_round[] = \"a.round(decimals=0)\";\n\nstatic PyObject *\narray_round(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint decimals = 0;\n\tstatic char *kwlist[] = {\"decimals\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|i\", kwlist,\n\t\t\t\t\t &decimals)) \n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Round(self, decimals));\n}\n\n\nstatic char doc_setflags[] = \"a.setflags(write=None, align=None, uic=None)\";\n\nstatic int _IsAligned(PyArrayObject *);\nstatic Bool _IsWriteable(PyArrayObject *);\n\nstatic PyObject *\narray_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"write\", \"align\", \"uic\", NULL};\n\tPyObject *write=Py_None;\n\tPyObject *align=Py_None;\n\tPyObject *uic=Py_None;\n\tint flagback = self->flags;\n\t\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|OOO\", kwlist,\n\t\t\t\t\t &write, &align, &uic))\n\t\treturn NULL;\n\n\tif (align != Py_None) {\n\t\tif (PyObject_Not(align)) self->flags &= ~ALIGNED;\n\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"cannot set aligned flag of mis-\"\\\n\t\t\t\t\t\"aligned array to True\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif (uic != Py_None) {\n if (PyObject_IsTrue(uic)) {\n\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY\" \\\n \"flag to True\");\n return NULL;\n }\n else {\n self->flags &= ~UPDATEIFCOPY;\n Py_XDECREF(self->base);\n self->base = NULL;\n }\n }\n \n if (write != Py_None) {\n if (PyObject_IsTrue(write)) \n\t\t\tif (_IsWriteable(self)) {\n\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tself->flags = flagback;\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"cannot set WRITEABLE \"\t\\\n\t\t\t\t\t\t\"flag to True of this \"\t\\\n\t\t\t\t\t\t\"array\");\t\t\\\n\t\t\t\treturn NULL;\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n \n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_newbyteorder[] = \"a.newbyteorder() is equivalent\\n\" \\\n\t\" to a.view(a.dtype.newbytorder())\\n\";\n\nstatic PyObject *\narray_newbyteorder(PyArrayObject *self, PyObject *args) \n{\n\tchar endian = PyArray_SWAP;\n\tPyArray_Descr *new;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\tnew = PyArray_DescrNewByteorder(self->descr, endian);\n\tif (!new) return NULL;\n\treturn PyArray_View(self, new, NULL);\n\n}\n\nstatic PyMethodDef array_methods[] = {\n {\"tolist\",\t (PyCFunction)array_tolist,\t1, doc_tolist},\n {\"item\", (PyCFunction)array_toscalar, METH_VARARGS, doc_toscalar},\n\t{\"tofile\", (PyCFunction)array_tofile, \n METH_VARARGS | METH_KEYWORDS, doc_tofile},\n {\"tostring\", (PyCFunction)array_tostring, METH_VARARGS, doc_tostring},\n {\"byteswap\", (PyCFunction)array_byteswap,\t1, doc_byteswap},\n {\"astype\", (PyCFunction)array_cast, 1, doc_cast},\n\t{\"getfield\", (PyCFunction)array_getfield, \n\t METH_VARARGS | METH_KEYWORDS, doc_getfield},\n\t{\"setfield\", (PyCFunction)array_setfield, \n\t METH_VARARGS | METH_KEYWORDS, doc_setfield},\n {\"copy\", (PyCFunction)array_copy, 1, doc_copy}, \n {\"resize\", (PyCFunction)array_resize, \n\t METH_VARARGS | METH_KEYWORDS, doc_resize}, \n\n\t/* for subtypes */\n\t{\"__array__\", (PyCFunction)array_getarray, 1, doc_array_getarray},\n\t{\"__array_wrap__\", (PyCFunction)array_wraparray, 1, doc_wraparray},\n\t/* default version so it is found... -- only used for subclasses */\n\t{\"__array_finalize__\", (PyCFunction)array_finalize, 1, NULL},\n\t\n\t\n\t/* for the copy module */\n {\"__copy__\", (PyCFunction)array_copy, 1, doc_copy},\t \n {\"__deepcopy__\", (PyCFunction)array_deepcopy, 1, doc_deepcopy}, \n\t\n /* for Pickling */\n {\"__reduce__\", (PyCFunction) array_reduce, 1, doc_reduce},\t\n\t{\"__setstate__\", (PyCFunction) array_setstate, 1, doc_setstate},\n\t{\"dumps\", (PyCFunction) array_dumps, 1, doc_dumps},\n\t{\"dump\", (PyCFunction) array_dump, 1, doc_dump},\n\n\t/* Extended methods added 2005 */\n\t{\"fill\", (PyCFunction)array_fill,\n\t METH_VARARGS, doc_fill},\n\t{\"transpose\",\t(PyCFunction)array_transpose, \n\t METH_VARARGS, doc_transpose},\n\t{\"take\",\t(PyCFunction)array_take, \n\t METH_VARARGS|METH_KEYWORDS, doc_take},\n\t{\"put\",\t(PyCFunction)array_put, \n\t METH_VARARGS|METH_KEYWORDS, doc_put},\n\t{\"putmask\",\t(PyCFunction)array_putmask, \n\t METH_VARARGS|METH_KEYWORDS, doc_putmask},\n\t{\"repeat\",\t(PyCFunction)array_repeat, \n\t METH_VARARGS|METH_KEYWORDS, doc_repeat},\n\t{\"choose\",\t(PyCFunction)array_choose, \n\t METH_VARARGS, doc_choose},\t\n\t{\"sort\",\t(PyCFunction)array_sort, \n\t METH_VARARGS|METH_KEYWORDS, doc_sort},\n\t{\"argsort\",\t(PyCFunction)array_argsort, \n\t METH_VARARGS|METH_KEYWORDS, doc_argsort},\n\t{\"searchsorted\", (PyCFunction)array_searchsorted, \n\t METH_VARARGS, doc_searchsorted},\t\n\t{\"argmax\",\t(PyCFunction)array_argmax, \n\t METH_VARARGS|METH_KEYWORDS, doc_argmax},\n\t{\"argmin\", (PyCFunction)array_argmin,\n\t METH_VARARGS|METH_KEYWORDS, doc_argmin},\n\t{\"reshape\",\t(PyCFunction)array_reshape, \n\t METH_VARARGS|METH_KEYWORDS, 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|METH_KEYWORDS, doc_max},\n\t{\"min\", (PyCFunction)array_min,\n\t METH_VARARGS|METH_KEYWORDS, doc_min},\n\t{\"ptp\", (PyCFunction)array_ptp,\n\t METH_VARARGS|METH_KEYWORDS, doc_ptp},\n\t{\"mean\", (PyCFunction)array_mean,\n\t METH_VARARGS|METH_KEYWORDS, doc_mean},\n\t{\"trace\", (PyCFunction)array_trace,\n\t METH_VARARGS|METH_KEYWORDS, doc_trace},\n\t{\"diagonal\", (PyCFunction)array_diagonal,\n\t METH_VARARGS|METH_KEYWORDS, doc_diagonal},\n\t{\"clip\", (PyCFunction)array_clip,\n\t METH_VARARGS|METH_KEYWORDS, doc_clip},\n\t{\"conj\", (PyCFunction)array_conjugate,\n\t METH_VARARGS, doc_conj},\n\t{\"conjugate\", (PyCFunction)array_conjugate,\n\t METH_VARARGS, doc_conjugate},\n\t{\"nonzero\", (PyCFunction)array_nonzero,\n\t METH_VARARGS, doc_nonzero},\n\t{\"std\", (PyCFunction)array_stddev,\n\t METH_VARARGS|METH_KEYWORDS, doc_stddev},\n\t{\"var\", (PyCFunction)array_variance,\n\t METH_VARARGS|METH_KEYWORDS, doc_variance},\n\t{\"sum\", (PyCFunction)array_sum,\n\t METH_VARARGS|METH_KEYWORDS, doc_sum},\n\t{\"cumsum\", (PyCFunction)array_cumsum,\n\t METH_VARARGS|METH_KEYWORDS, doc_cumsum},\n\t{\"prod\", (PyCFunction)array_prod,\n\t METH_VARARGS|METH_KEYWORDS, doc_prod},\n\t{\"cumprod\", (PyCFunction)array_cumprod,\n\t METH_VARARGS|METH_KEYWORDS, doc_cumprod},\n\t{\"all\", (PyCFunction)array_all,\n\t METH_VARARGS|METH_KEYWORDS, doc_all},\n\t{\"any\", (PyCFunction)array_any,\n\t METH_VARARGS|METH_KEYWORDS, 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{\"round\", (PyCFunction)array_round,\n\t METH_VARARGS|METH_KEYWORDS, doc_round},\n\t{\"setflags\", (PyCFunction)array_setflags,\n\t METH_VARARGS|METH_KEYWORDS, doc_setflags},\n\t{\"newbyteorder\", (PyCFunction)array_newbyteorder,\n\t METH_VARARGS, doc_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n#undef _ARET\n\n\n", + "source_code_before": "\n/* Should only be used if x is known to be an nd-array */\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_take[] = \"a.take(indices, axis=None). Selects the elements \"\\\n\t\"in indices from array a along the given axis.\";\n\nstatic PyObject *\narray_take(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint dimension=MAX_DIMS;\n\tPyObject *indices;\n\tstatic char *kwlist[] = {\"indices\", \"axis\", NULL};\n\t\n\tdimension=0;\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &indices, PyArray_AxisConverter,\n\t\t\t\t\t &dimension))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Take(self, indices, dimension));\n}\n\nstatic char doc_fill[] = \"a.fill(value) places the scalar value at every \"\\\n\t\"position in the array.\";\n\nstatic PyObject *\narray_fill(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *obj;\n\tif (!PyArg_ParseTuple(args, \"O\", &obj))\n\t\treturn NULL;\n\tif (PyArray_FillWithScalar(self, obj) < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_put[] = \"a.put(values, indices) sets a.flat[n] = v[n] \"\\\n\t\"for each n in indices. v can be scalar or shorter than indices, \"\\\n\t\"will repeat.\";\n\nstatic PyObject *\narray_put(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *indices, *values;\n\tstatic char *kwlist[] = {\"values\", \"indices\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &values, &indices))\n\t\treturn NULL;\n\treturn PyArray_Put(self, values, indices);\n}\n\nstatic char doc_putmask[] = \"a.putmask(values, mask) sets a.flat[n] = v[n] \"\\\n\t\"for each n where mask.flat[n] is TRUE. v can be scalar.\";\n\nstatic PyObject *\narray_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *mask, *values;\n\n\tstatic char *kwlist[] = {\"values\", \"mask\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &values, &mask))\n\t\treturn NULL;\n\treturn PyArray_PutMask(self, values, mask);\n}\n\n/* Used to reshape a Fortran Array */\nstatic void\n_reverse_shape(PyArray_Dims *newshape)\n{\n\tint i, n = newshape->len;\n\tintp *ptr = newshape->ptr;\n\tintp *eptr;\n\tintp tmp;\n\tint len = n >> 1;\n\n\teptr = ptr+n-1;\n\tfor(i=0; i) return a new view of array with same data. type can be either a new sub-type object or a data-descriptor object\";\n\nstatic PyObject *\narray_view(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *otype=NULL;\n PyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTuple(args, \"|O\", &otype)) return NULL;\n\n\tif (otype) {\n\t\tif (PyType_Check(otype) &&\t\t\t\\\n\t\t PyType_IsSubtype((PyTypeObject *)otype, \n\t\t\t\t &PyArray_Type)) {\n\t\t\treturn PyArray_View(self, NULL, \n (PyTypeObject *)otype);\n }\n\t\telse {\n\t\t\tif (PyArray_DescrConverter(otype, &type) == PY_FAIL) \n\t\t\t\treturn NULL;\n\t\t}\n\t}\n\treturn PyArray_View(self, type, NULL);\n}\n\nstatic char doc_argmax[] = \"a.argmax(axis=None)\";\n\nstatic PyObject *\narray_argmax(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\n\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\n\t\n\treturn PyArray_Min(self, axis);\n}\n\nstatic char doc_swapaxes[] = \"a.swapaxes(axis1, axis2) returns new view with axes swapped.\";\n\nstatic PyObject *\narray_swapaxes(PyArrayObject *self, PyObject *args)\n{\n\tint axis1, axis2;\n\n\tif (!PyArg_ParseTuple(args, \"ii\", &axis1, &axis2)) return NULL;\n\n\treturn PyArray_SwapAxes(self, axis1, axis2);\n}\n\nstatic char doc_getfield[] = \"m.getfield(dtype, offset) returns a field \"\\\n\t\" of the given array as a certain type. A field is a view of \"\\\n\t\" the array's data with each itemsize determined by the given type\"\\\n\t\" and the offset into the current array.\";\n\n/* steals typed reference */\n/*OBJECT_API\n Get a subset of bytes from each element of the array\n*/\nstatic PyObject *\nPyArray_GetField(PyArrayObject *self, PyArray_Descr *typed, int offset)\n{\n\tPyObject *ret=NULL;\n\n\tif (offset < 0 || (offset + typed->elsize) > self->descr->elsize) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need 0 <= offset <= %d for requested type \" \\\n\t\t\t \"but received offset = %d\",\n\t\t\t self->descr->elsize-typed->elsize, offset);\n\t\tPy_DECREF(typed);\n\t\treturn NULL;\n\t}\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t typed,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, \n\t\t\t\t self->data + offset,\n\t\t\t\t self->flags, (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self; \n\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\treturn ret;\n}\n\nstatic PyObject *\narray_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\n PyArray_Descr *dtype;\n\tint offset = 0;\n\tstatic char *kwlist[] = {\"dtype\", \"offset\", 0};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|i\", kwlist,\n\t\t\t\t\t PyArray_DescrConverter,\n\t\t\t\t\t &dtype, &offset)) return NULL;\n\t\n\treturn _ARET(PyArray_GetField(self, dtype, offset));\n}\n\n\nstatic char doc_setfield[] = \"m.setfield(value, dtype, offset) places val \"\\\n\t\"into field of the given array defined by the data type and offset.\";\n\n/*OBJECT_API\n Set a subset of bytes from each element of the array\n*/\nstatic int\nPyArray_SetField(PyArrayObject *self, PyArray_Descr *dtype,\n\t\t int offset, PyObject *val)\n{\n\tPyObject *ret=NULL;\n\tint retval = 0;\n \n\tif (offset < 0 || (offset + dtype->elsize) > self->descr->elsize) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need 0 <= offset <= %d for requested type \" \\\n\t\t\t \"but received offset = %d\",\n\t\t\t self->descr->elsize-dtype->elsize, offset);\n\t\tPy_DECREF(dtype);\n\t\treturn -1;\n\t}\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t dtype, self->nd, self->dimensions,\n\t\t\t\t self->strides, self->data + offset,\n\t\t\t\t self->flags, (PyObject *)self);\n\tif (ret == NULL) return -1;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self;\n\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\t\n\tretval = PyArray_CopyObject((PyArrayObject *)ret, val);\n\tPy_DECREF(ret);\n\treturn retval;\n}\n\nstatic PyObject *\narray_setfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n PyArray_Descr *dtype;\n\tint offset = 0;\n\tPyObject *value;\n\tstatic char *kwlist[] = {\"value\", \"dtype\", \"offset\", 0};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO&|i\", kwlist,\n\t\t\t\t\t &value, PyArray_DescrConverter,\n\t\t\t\t\t &dtype, &offset)) return NULL;\n\n\tif (PyArray_SetField(self, dtype, offset, value) < 0)\n\t\treturn NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n/* This doesn't change the descriptor just the actual data...\n */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_Byteswap(PyArrayObject *self, Bool inplace)\n{\n PyArrayObject *ret;\n\tintp size;\n\tPyArray_CopySwapNFunc *copyswapn;\n\tPyArray_CopySwapFunc *copyswap;\n\tPyArrayIterObject *it;\n\n\tif (inplace) {\n\t\tcopyswapn = self->descr->f->copyswapn;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\t\tif (PyArray_ISONESEGMENT(self)) {\n\t\t\tcopyswapn(self->data, NULL, size, 1, \n\t\t\t\t self->descr->elsize);\n\t\t}\n\t\telse { /* Use iterator */\n\t\t\t\n\t\t\tit = (PyArrayIterObject *)\\\n\t\t\t\tPyArray_IterNew((PyObject *)self);\n\t\t\tcopyswap = self->descr->f->copyswap;\n\t\t\twhile (it->index < it->size) {\n\t\t\t\tcopyswap(it->dataptr, NULL, 1, \n\t\t\t\t\t self->descr->elsize);\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t}\n\t\t\tPy_DECREF(it);\n\t\t}\n\t\t\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tif ((ret = (PyArrayObject *)PyArray_NewCopy(self,-1)) == NULL) \n\t\t\treturn NULL;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\n\t\t/* now ret has the same dtypedescr as self (including\n\t\t byteorder)\n\t\t*/\n\n\t\tret->descr->f->copyswapn(ret->data, NULL, size, 1, \n\t\t\t\t\t ret->descr->elsize);\n\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic char doc_byteswap[] = \"m.byteswap(False) Swap the bytes in\"\\\n\t\" the array. Return the byteswapped array. If the first argument\"\\\n\t\" is TRUE, byteswap in-place and return a reference to self.\";\n\nstatic PyObject *\narray_byteswap(PyArrayObject *self, PyObject *args) \n{\n\tBool inplace=FALSE;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter, &inplace))\n\t\treturn NULL;\n\t\n\treturn PyArray_Byteswap(self, inplace);\n}\n\nstatic char doc_tolist[] = \"m.tolist().\t Copy the data portion of the array\"\\\n\t\" to a hierarchical python list and return that list.\";\n\nstatic PyObject *\narray_tolist(PyArrayObject *self, PyObject *args) \n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n if (self->nd <= 0) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"can't convert a 0-d array to a list\");\n return NULL;\n }\n\t\n return PyArray_ToList(self);\n}\n\nstatic char doc_tostring[] = \"m.tostring() Construct a Python string \"\\\n \"containing the raw bytes in the array\";\n\nstatic PyObject *\narray_tostring(PyArrayObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n return PyArray_ToString(self);\n}\n\nstatic char doc_tofile[] = \"m.tofile(fid, sep=\"\") write the data to a file.\";\n\nstatic PyObject *\narray_tofile(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tint ret;\n PyObject *file;\n\tFILE *fd;\n char *sep=\"\";\n\tchar *format=\"\";\n\tchar *mode=\"\";\n\tstatic char *kwlist[] = {\"file\", \"sep\", \"format\", NULL};\n \n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ss\", kwlist, \n &file, &sep, &format)) return NULL;\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"wb\";\n\t\telse mode=\"w\";\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), mode);\n\t\tif (file==NULL) return NULL;\n\t}\n\telse {\n\t\tPy_INCREF(file);\n\t}\n\tfd = PyFile_AsFile(file);\n\tif (fd == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \"first argument must be a \" \\\n\t\t\t\t\"string or open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_ToFile(self, fd, sep, format);\n\tPy_DECREF(file);\n\tif (ret < 0) return NULL;\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_toscalar[] = \"m.item(). Copy the first data point of \"\\\n\t\"the array to a standard Python scalar and return it.\";\n\nstatic PyObject *\narray_toscalar(PyArrayObject *self, PyObject *args) {\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\tif (self->nd == 0 || PyArray_SIZE(self) == 1) \n\t\treturn self->descr->f->getitem(self->data, self);\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError, \"can only convert an\"\t\\\n\t\t\t\t\" array of size 1 to Python scalar.\");\n\t\treturn NULL;\n\t}\n}\n\nstatic char doc_cast[] = \"m.astype(t).\tCast array m to type t.\t \\n\\n\"\\\n\t\"t can be either a string representing a typecode, or a python type\"\\\n\t\" object of type int, float, or complex.\";\n\nstatic PyObject *\narray_cast(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Descr *descr=NULL;\n\tPyObject *obj;\n\t\n if (!PyArg_ParseTuple(args, \"O&\", PyArray_DescrConverter,\n\t\t\t &descr)) return NULL;\n\t\n\tif (descr == self->descr) {\n\t\tobj = _ARET(PyArray_NewCopy(self,0));\n\t\tPy_XDECREF(descr);\n\t\treturn obj;\n\t}\n\treturn _ARET(PyArray_CastToType(self, descr, 0));\n}\t \n\n/* default sub-type implementation */\n\nstatic char doc_wraparray[] = \"m.__array_wrap__(obj) returns an object of \"\\\n\t\"type m from the ndarray object obj\";\n\nstatic PyObject *\narray_wraparray(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *arr;\n\tPyObject *ret;\n\t\n\tif (PyTuple_Size(args) < 1) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"only accepts 1 argument\");\n\t\treturn NULL;\n\t}\n\tarr = PyTuple_GET_ITEM(args, 0);\n\tif (!PyArray_Check(arr)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"can only be called with ndarray object\");\n\t\treturn NULL;\n\t}\t\n\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t PyArray_NDIM(arr),\n\t\t\t\t PyArray_DIMS(arr), \n\t\t\t\t PyArray_STRIDES(arr), PyArray_DATA(arr),\n\t\t\t\t PyArray_FLAGS(arr), (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(arr);\n\tPyArray_BASE(ret) = arr;\n\treturn ret;\n}\n\n/* NO-OP --- just so all subclasses will have one by default. */\nstatic PyObject *\narray_finalize(PyArrayObject *self, PyObject *args)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic char doc_array_getarray[] = \"m.__array__(|dtype) just returns either a new reference to self if dtype is not given or a new array of provided data type if dtype is different from the current dtype of the array.\";\n\nstatic PyObject *\narray_getarray(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Descr *newtype=NULL;\n\tPyObject *ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_DescrConverter,\n\t\t\t &newtype)) return NULL;\n\t\n\t/* convert to PyArray_Type */\n\tif (!PyArray_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 = &PyArray_Type;\n\t\t}\n\t\t\n\t\tPy_INCREF(PyArray_DESCR(self));\n\t\tnew = PyArray_NewFromDescr(subtype, \n\t\t\t\t\t PyArray_DESCR(self),\n\t\t\t\t\t PyArray_NDIM(self),\n\t\t\t\t\t PyArray_DIMS(self), \n\t\t\t\t\t PyArray_STRIDES(self), \n\t\t\t\t\t PyArray_DATA(self),\n\t\t\t\t\t PyArray_FLAGS(self), NULL);\n\t\tif (new == NULL) return NULL;\n\t\tPy_INCREF(self);\n\t\tPyArray_BASE(new) = (PyObject *)self;\n\t\tself = (PyArrayObject *)new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t}\n\t\t\n\tif ((newtype == NULL) || \\\n\t PyArray_EquivTypes(self->descr, newtype)) {\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tret = PyArray_CastToType(self, newtype, 0);\n\t\tPy_DECREF(self);\n\t\treturn ret;\n\t}\n}\n\nstatic char doc_copy[] = \"m.copy(|fortran). Return a copy of the array.\\n\"\\\n\t\"If fortran == 0 then the result is contiguous (default). \\n\"\\\n\t\"If fortran > 0 then the result has fortran data order. \\n\"\\\n\t\"If fortran < 0 then the result has fortran data order only if m\\n\"\n\t\" is already in fortran order.\";\n\nstatic PyObject *\narray_copy(PyArrayObject *self, PyObject *args) \n{\n\tint fortran=0;\n if (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n\t\n return PyArray_NewCopy(self, fortran);\n}\n\nstatic char doc_resize[] = \"self.resize(new_shape, refcheck=True). \"\\\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, PyObject *kwds) \n{\n PyArray_Dims newshape;\n PyObject *ret;\n\tint n;\n\tint refcheck = 1;\n\t\n\tif (kwds != NULL) {\n\t\tPyObject *ref;\n\t\tref = PyDict_GetItemString(kwds, \"refcheck\");\n\t\tif (ref) {\n\t\t\trefcheck = PyInt_AsLong(ref);\n\t\t\tif (refcheck==-1 && PyErr_Occurred()) {\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\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\t\n\tret = PyArray_Resize(self, &newshape, refcheck);\n PyDimMem_FREE(newshape.ptr);\n if (ret == NULL) return NULL;\n\tPy_DECREF(ret);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_repeat[] = \"a.repeat(repeats=, axis=None)\\n\"\\\n\t\"\\n\"\\\n\t\" Copy elements of a, repeats times. The repeats argument must\\n\"\\\n\t\" be a sequence of length a.shape[axis] or a scalar.\";\n\nstatic PyObject *\narray_repeat(PyArrayObject *self, PyObject *args, PyObject *kwds) {\n\tPyObject *repeats;\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"repeats\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &repeats, PyArray_AxisConverter,\n\t\t\t\t\t &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_Repeat(self, repeats, axis));\n}\n\nstatic char doc_choose[] = \"a.choose(b0, b1, ..., bn)\\n\"\\\n\t\"\\n\"\\\n\t\"Return an array with elements chosen from 'a' at the positions\\n\"\\\n \"of the given arrays b_i. The array 'a' should be an integer array\\n\"\\\n \"with entries from 0 to n+1, and the b_i arrays should have the same\\n\"\\\n \"shape as 'a'.\";\n\nstatic PyObject *\narray_choose(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *choices;\n\tint n;\n\t\n\tn = PyTuple_Size(args);\n\tif (n <= 1) {\n\t\tif (!PyArg_ParseTuple(args, \"O\", &choices))\n\t\t\treturn NULL;\n\t}\n else {\n\t\tchoices = args;\n\t}\n\t\n\treturn _ARET(PyArray_Choose(self, choices));\n}\n\nstatic char doc_sort[] = \"a.sort(axis=-1,kind='quicksort') sorts in place along axis. Return is None and kind can be 'quicksort', 'mergesort', or 'heapsort'\";\n\nstatic PyObject *\narray_sort(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=-1;\n\tint val;\n\tPyArray_SORTKIND which=PyArray_QUICKSORT;\n\tstatic char *kwlist[] = {\"axis\", \"kind\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iO&\", kwlist, &axis,\n\t\t\t\t\t PyArray_SortkindConverter, &which))\n\t\treturn NULL;\n\t\n\tval = PyArray_Sort(self, axis, which);\n\tif (val < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_argsort[] = \"a.argsort(axis=-1,kind='quicksort')\\n\"\\\n\t\" Return the indexes into a that would sort it along the\"\\\n\t\" given axis; kind can be 'quicksort', 'mergesort', or 'heapsort'\";\n\nstatic PyObject *\narray_argsort(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=-1;\n\tPyArray_SORTKIND which=PyArray_QUICKSORT;\n\tstatic char *kwlist[] = {\"axis\", \"kind\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iO&\", kwlist, &axis,\n\t\t\t\t\t PyArray_SortkindConverter, &which))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_ArgSort(self, axis, which));\n}\n\nstatic char doc_searchsorted[] = \"a.searchsorted(v)\\n\"\\\n\t\" Assuming that a is a 1-D array, in ascending order and\\n\"\\\n\t\" represents bin boundaries, then a.searchsorted(values) gives an\\n\"\\\n\t\" array of bin numbers, giving the bin into which each value would\\n\"\\\n\t\" be placed. This method is helpful for histograming. \\n\"\\\n\t\" Note: No warning is given if the boundaries, in a, are not \\n\"\\\n\t\" in ascending order.\";\n\nstatic PyObject *\narray_searchsorted(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *values;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &values)) return NULL;\n\t\n\treturn _ARET(PyArray_SearchSorted(self, values));\n}\n\nstatic char doc_deepcopy[] = \"Used if copy.deepcopy is called on an array.\";\n\nstatic PyObject *\narray_deepcopy(PyArrayObject *self, PyObject *args) \n{\n PyObject* visit;\n PyObject **optr;\n PyArrayIterObject *it;\n PyObject *copy, *ret, *deepcopy, *temp, *res;\n\n if (!PyArg_ParseTuple(args, \"O\", &visit)) return NULL;\n ret = PyArray_Copy(self);\n if (PyArray_ISOBJECT(self)) {\n copy = PyImport_ImportModule(\"copy\");\n if (copy == NULL) return NULL;\n deepcopy = PyObject_GetAttrString(copy, \"deepcopy\");\n Py_DECREF(copy);\n if (deepcopy == NULL) return NULL;\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it == NULL) {Py_DECREF(deepcopy); return NULL;}\n optr = (PyObject **)PyArray_DATA(ret);\n while(it->index < it->size) {\n temp = *((PyObject **)it->dataptr);\n Py_INCREF(temp);\n /* call deepcopy on this argument */\n res = PyObject_CallFunctionObjArgs(deepcopy, \n temp, visit, NULL);\n Py_DECREF(temp);\n Py_DECREF(*optr);\n *optr++ = res;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(deepcopy);\n Py_DECREF(it);\n }\n return _ARET(ret);\n}\n\n/* Convert Object Array to flat list and pickle the flat list string */\nstatic PyObject *\n_getobject_pkl(PyArrayObject *self)\n{\n\tPyObject *theobject;\n\tPyArrayIterObject *iter=NULL;\n\tPyObject *list;\n\n\t\n\titer = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (iter == NULL) return NULL;\n\tlist = PyList_New(iter->size);\n\tif (list == NULL) {Py_DECREF(iter); return NULL;}\n\twhile (iter->index < iter->size) {\n\t\ttheobject = *((PyObject **)iter->dataptr);\n\t\tPy_INCREF(theobject);\n\t\tPyList_SET_ITEM(list, (int) iter->index, theobject);\n\t\tPyArray_ITER_NEXT(iter);\n\t}\n\tPy_DECREF(iter);\n\treturn list;\n}\n\nstatic int\n_setobject_pkl(PyArrayObject *self, PyObject *list)\n{\n\tPyObject *theobject;\n\tPyArrayIterObject *iter=NULL;\n\tint size;\n\n\tsize = self->descr->elsize;\n\t\n\titer = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (iter == NULL) return -1;\n\twhile(iter->index < iter->size) {\n\t\ttheobject = PyList_GET_ITEM(list, (int) iter->index);\n\t\tPy_INCREF(theobject);\n\t\t*((PyObject **)iter->dataptr) = theobject;\n\t\tPyArray_ITER_NEXT(iter);\n\t}\n\tPy_XDECREF(iter);\n\treturn 0;\n}\n\nstatic char doc_reduce[] = \"a.__reduce__() for pickling.\";\n\nstatic PyObject *\narray_reduce(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *ret=NULL, *state=NULL, *obj=NULL, *mod=NULL;\n\tPyObject *mybool, *thestr=NULL;\n\tPyArray_Descr *descr;\n\n\t/* Return a tuple of (callable object, arguments, object's state) */\n\t/* We will put everything in the object's state, so that on UnPickle\n\t it can use the string object as memory without a copy */\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core._internal\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"_reconstruct\");\n\tPy_DECREF(mod);\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t Py_BuildValue(\"ONN\",\n\t\t\t\t (PyObject *)self->ob_type,\n\t\t\t\t Py_BuildValue(\"(N)\",\n\t\t\t\t\t\t PyInt_FromLong(0)),\n\t\t\t\t PyObject_GetAttrString((PyObject *)(self->descr),\n\t\t\t\t\t\t\t \"char\")));\n\t\n\t/* Now fill in object's state. This is a tuple with \n\t 4 arguments\n\n\t 1) a Tuple giving the shape\n\t 2) a PyArray_Descr Object (with correct bytorder set)\n\t 3) a Bool stating if Fortran or not\n\t 4) a binary string with the data (or a list for Object arrays)\n\n\t Notice because Python does not describe a mechanism to write \n\t raw data to the pickle, this performs a copy to a string first\n\t*/\n\n\tstate = PyTuple_New(4);\n\tif (state == NULL) {\n\t\tPy_DECREF(ret); return NULL;\n\t}\n\tPyTuple_SET_ITEM(state, 0, PyObject_GetAttrString((PyObject *)self, \n\t\t\t\t\t\t\t \"shape\"));\n\tdescr = self->descr;\n\tPy_INCREF(descr);\n\tPyTuple_SET_ITEM(state, 1, (PyObject *)descr);\n\tmybool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);\n\tPy_INCREF(mybool);\n\tPyTuple_SET_ITEM(state, 2, mybool);\n\tif (PyArray_ISOBJECT(self)) {\n\t\tthestr = _getobject_pkl(self);\n\t}\n\telse {\n thestr = PyArray_ToString(self);\n\t}\n\tif (thestr == NULL) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(state);\n\t\treturn NULL;\n\t}\n\tPyTuple_SET_ITEM(state, 3, thestr);\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\nstatic char doc_setstate[] = \"a.__setstate__(tuple) for unpickling.\";\n\n/*\n\t 1) a Tuple giving the shape\n\t 2) a PyArray_Descr Object\n\t 3) a Bool stating if Fortran or not\n\t 4) a binary string with the data (or a list if Object array) \n*/\n\nstatic intp _array_fill_strides(intp *, intp *, int, intp, int, int *);\n\nstatic int _IsAligned(PyArrayObject *); \n\nstatic PyArray_Descr * _array_typedescr_fromstr(char *);\n\nstatic PyObject *\narray_setstate(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *shape;\n\tPyArray_Descr *typecode;\n\tint fortran;\n\tPyObject *rawdata;\n\tchar *datastr;\n\tint len;\n\tintp dimensions[MAX_DIMS];\n\tint nd;\n\t\n\t/* This will free any memory associated with a and\n\t use the string in setstate as the (writeable) memory.\n\t*/\n\tif (!PyArg_ParseTuple(args, \"(O!O!iO)\", &PyTuple_Type,\n\t\t\t &shape, &PyArrayDescr_Type, &typecode, \n\t\t\t &fortran, &rawdata))\n\t\treturn NULL;\n\n\tPy_XDECREF(self->descr);\n\tself->descr = typecode;\n\tPy_INCREF(typecode);\n\tnd = PyArray_IntpFromSequence(shape, dimensions, MAX_DIMS);\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (!PyList_Check(rawdata)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"object pickle not returning list\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tif (!PyString_Check(rawdata)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"pickle not returning string\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (PyString_AsStringAndSize(rawdata, &datastr, &len))\n\t\t\treturn NULL;\n\n\t\tif ((len != (self->descr->elsize *\t\t\t\\\n\t\t\t (int) PyArray_MultiplyList(dimensions, nd)))) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size does not\"\t\\\n\t\t\t\t\t\" match array size\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n if ((self->flags & OWN_DATA)) {\n\t\tif (self->data != NULL)\n\t\t\tPyDataMem_FREE(self->data);\n\t\tself->flags &= ~OWN_DATA;\n }\n\tPy_XDECREF(self->base);\n\n\tself->flags &= ~UPDATEIFCOPY;\n\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t\tself->dimensions = NULL;\n\t}\n\n\tself->flags = DEFAULT_FLAGS;\n\n\tself->nd = nd;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(nd * 2);\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dimensions, sizeof(intp)*nd);\n\t\t(void) _array_fill_strides(self->strides, dimensions, nd,\n\t\t\t\t\t self->descr->elsize, \n (fortran ? FORTRAN : CONTIGUOUS),\n\t\t\t\t\t &(self->flags));\n\t}\n\n\tif (typecode->type_num != PyArray_OBJECT) {\n\t\tself->data = datastr;\n\t\tif (!_IsAligned(self)) {\n\t\t\tintp num = PyArray_NBYTES(self);\n\t\t\tself->data = PyDataMem_NEW(num);\n\t\t\tif (self->data == NULL) {\n\t\t\t\tself->nd = 0;\n\t\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemcpy(self->data, datastr, num);\n\t\t\tself->flags |= OWN_DATA;\n\t\t\tself->base = NULL;\n\t\t}\n\t\telse {\n\t\t\tself->base = rawdata;\n\t\t\tPy_INCREF(self->base);\n\t\t}\n\t}\n\telse {\n\t\tself->data = PyDataMem_NEW(PyArray_NBYTES(self));\n\t\tif (self->data == NULL) { \n\t\t\tself->nd = 0;\n\t\t\tself->data = PyDataMem_NEW(self->descr->elsize);\n\t\t\tif (self->dimensions) PyDimMem_FREE(self->dimensions);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\t\tself->base = NULL;\n\t\tif (_setobject_pkl(self, rawdata) < 0) \n\t\t\treturn NULL;\n\t}\n\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\t\n}\n\n/*OBJECT_API*/\nstatic int\nPyArray_Dump(PyObject *self, PyObject *file, int protocol)\n{\n\tPyObject *cpick=NULL;\n\tPyObject *ret;\n\tif (protocol < 0) protocol = 2;\n\n\tcpick = PyImport_ImportModule(\"cPickle\");\n\tif (cpick==NULL) return -1;\n\n\tif PyString_Check(file) {\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), \"wb\");\n\t\tif (file==NULL) return -1;\n\t}\n\telse Py_INCREF(file);\n\tret = PyObject_CallMethod(cpick, \"dump\", \"OOi\", self, \n\t\t\t\t file, protocol);\n\tPy_XDECREF(ret);\n\tPy_DECREF(file);\n\tPy_DECREF(cpick);\n\tif (PyErr_Occurred()) return -1;\n\treturn 0;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_Dumps(PyObject *self, int protocol)\n{\n\tPyObject *cpick=NULL;\n\tPyObject *ret;\n\tif (protocol < 0) protocol = 2;\n\n\tcpick = PyImport_ImportModule(\"cPickle\");\n\tif (cpick==NULL) return NULL;\n\tret = PyObject_CallMethod(cpick, \"dumps\", \"Oi\", self, protocol);\n\tPy_DECREF(cpick);\n\treturn ret;\n}\n\n\nstatic char doc_dump[] = \"m.dump(file)\";\n\nstatic PyObject *\narray_dump(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *file=NULL;\n\tint ret;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &file))\n\t\treturn NULL;\n\tret = PyArray_Dump((PyObject *)self, file, 2);\n\tif (ret < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_dumps[] = \"m.dumps()\";\n\nstatic PyObject *\narray_dumps(PyArrayObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\"))\n\t\treturn NULL;\n\treturn PyArray_Dumps((PyObject *)self, 2);\n}\n\n\nstatic char doc_transpose[] = \"m.transpose()\";\n\nstatic PyObject *\narray_transpose(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *shape=Py_None;\n\tint n;\n\tPyArray_Dims permute;\n\tPyObject *ret;\n\n\tn = PyTuple_Size(args);\n\tif (n > 1) shape = args;\n\telse if (n == 1) shape = PyTuple_GET_ITEM(args, 0);\n\t\n\tif (shape == Py_None)\n\t\tret = PyArray_Transpose(self, NULL);\n\telse {\n\t\tif (!PyArray_IntpConverter(shape, &permute)) return NULL;\n\t\tret = PyArray_Transpose(self, &permute);\n\t\tPyDimMem_FREE(permute.ptr);\n\t}\n\t\n\treturn _ARET(ret);\n}\n\nstatic char doc_mean[] = \"a.mean(axis=None, dtype=None)\\n\\n\"\\\n \"Average the array over the given axis. If the axis is None, average\\n\"\\\n \"over all dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, dtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\\n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, dtype) * 1.0 / product(a.shape)\\n\"\\\n \"\\n\"\\\n \"The optional dtype argument is the data type for intermediate\\n\"\\\n \"calculations in the sum.\";\n\n#define _CHKTYPENUM(typ) ((typ) ? (typ)->type_num : PyArray_NOTYPE)\n\nstatic PyObject *\narray_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist,\n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\n\treturn PyArray_Mean(self, axis, _CHKTYPENUM(dtype));\n}\n\nstatic char doc_sum[] = \"a.sum(axis=None, dtype=None)\\n\\n\"\\\n \"Sum the array over the given axis. If the axis is None, sum over all\\n\"\\\n \"dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"The optional dtype argument is the data type for the returned value\\n\"\\\n \"and intermediate calculations. The default is to upcast (promote)\\n\"\\\n \"smaller integer types to the platform-dependent int. For example, on\\n\"\\\n \"32-bit platforms:\\n\"\\\n \"\\n\"\\\n \" a.dtype default sum() dtype\\n\"\\\n \" ---------------------------------------------------\\n\"\\\n \" bool, int8, int16, int32 int32\\n\"\\\n \"\\n\"\\\n \"Examples:\\n\"\\\n \"\\n\"\\\n \">>> array([0.5, 1.5]).sum()\\n\"\\\n \"2.0\\n\"\\\n \">>> array([0.5, 1.5]).sum(dtype=int32)\\n\"\\\n \"1\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum(axis=0)\\n\"\\\n \"array([0, 6])\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum(axis=1)\\n\"\\\n \"array([1, 5])\";\n\nstatic PyObject *\narray_sum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Sum(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_cumsum[] = \"a.cumsum(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_CumSum(self, axis, _CHKTYPENUM(dtype));\n}\n\nstatic char doc_prod[] = \"a.prod(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Prod(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_cumprod[] = \"a.cumprod(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_CumProd(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_any[] = \"a.any(axis=None)\";\n\nstatic PyObject *\narray_any(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\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, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter,\n\t\t\t\t\t &axis))\n\t\treturn NULL;\t\n\n\treturn PyArray_All(self, axis);\n}\n\nstatic char doc_stddev[] = \"a.std(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, _CHKTYPENUM(dtype), 0);\n}\n\nstatic char doc_variance[] = \"a.var(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_variance(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, _CHKTYPENUM(dtype), 1);\n}\n\nstatic char doc_compress[] = \"a.compress(condition=, axis=None)\";\n\nstatic PyObject *\narray_compress(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyObject *condition;\t\n\tstatic char *kwlist[] = {\"condition\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &condition, PyArray_AxisConverter,\n\t\t\t\t\t &axis)) return NULL;\n\n\treturn _ARET(PyArray_Compress(self, condition, axis));\n}\n\nstatic char doc_nonzero[] = \"a.nonzero() return a tuple of indices referencing \"\\\n\t\"the elements of a that are nonzero.\";\n\nstatic PyObject *\narray_nonzero(PyArrayObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\treturn _ARET(PyArray_Nonzero(self));\n}\n\n\nstatic char doc_trace[] = \"a.trace(offset=0, axis1=0, axis2=1, dtype=None)\\n\"\\\n\t\"return the sum along the offset diagonal of the arrays indicated\\n\" \\\n\t\"axis1 and axis2.\";\n\nstatic PyObject *\narray_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iiiO&\", kwlist, \n\t\t\t\t\t &offset, &axis1, &axis2,\n\t\t\t\t\t PyArray_DescrConverter2, &dtype))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Trace(self, offset, axis1, axis2, \n\t\t\t\t _CHKTYPENUM(dtype)));\n}\n\n#undef _CHKTYPENUM\n\n\nstatic char doc_clip[] = \"a.clip(min=, max=)\";\n\nstatic PyObject *\narray_clip(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *min, *max;\n\tstatic char *kwlist[] = {\"min\", \"max\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &min, &max)) \n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Clip(self, min, max));\n}\n\nstatic char doc_conj[] = \"a.conj()\";\n\nstatic char doc_conjugate[] = \"a.conjugate()\";\n\nstatic PyObject *\narray_conjugate(PyArrayObject *self, PyObject *args) \n{\n\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n\treturn PyArray_Conjugate(self);\n}\n\n\nstatic char doc_diagonal[] = \"a.diagonal(offset=0, axis1=0, axis2=1)\";\n\nstatic PyObject *\narray_diagonal(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iii\", kwlist, \n\t\t\t\t\t &offset, &axis1, &axis2))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Diagonal(self, offset, axis1, axis2));\n}\n\nstatic char doc_flatten[] = \"a.flatten([fortran]) return a 1-d array (always copy)\";\n\nstatic PyObject *\narray_flatten(PyArrayObject *self, PyObject *args)\n{\n\tint fortran=0;\n\n\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n \n\treturn PyArray_Flatten(self, (int) fortran);\n}\n\nstatic char doc_ravel[] = \"a.ravel([fortran]) return a 1-d array (copy only if needed)\";\n\nstatic PyObject *\narray_ravel(PyArrayObject *self, PyObject *args)\n{\n\tint fortran=0;\n\n\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n\n\treturn PyArray_Ravel(self, fortran);\n}\n\nstatic char doc_round[] = \"a.round(decimals=0)\";\n\nstatic PyObject *\narray_round(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint decimals = 0;\n\tstatic char *kwlist[] = {\"decimals\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|i\", kwlist,\n\t\t\t\t\t &decimals)) \n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Round(self, decimals));\n}\n\n\nstatic char doc_setflags[] = \"a.setflags(write=None, align=None, uic=None)\";\n\nstatic int _IsAligned(PyArrayObject *);\nstatic Bool _IsWriteable(PyArrayObject *);\n\nstatic PyObject *\narray_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"write\", \"align\", \"uic\", NULL};\n\tPyObject *write=Py_None;\n\tPyObject *align=Py_None;\n\tPyObject *uic=Py_None;\n\tint flagback = self->flags;\n\t\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|OOO\", kwlist,\n\t\t\t\t\t &write, &align, &uic))\n\t\treturn NULL;\n\n\tif (align != Py_None) {\n\t\tif (PyObject_Not(align)) self->flags &= ~ALIGNED;\n\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"cannot set aligned flag of mis-\"\\\n\t\t\t\t\t\"aligned array to True\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif (uic != Py_None) {\n if (PyObject_IsTrue(uic)) {\n\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY\" \\\n \"flag to True\");\n return NULL;\n }\n else {\n self->flags &= ~UPDATEIFCOPY;\n Py_XDECREF(self->base);\n self->base = NULL;\n }\n }\n \n if (write != Py_None) {\n if (PyObject_IsTrue(write)) \n\t\t\tif (_IsWriteable(self)) {\n\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tself->flags = flagback;\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"cannot set WRITEABLE \"\t\\\n\t\t\t\t\t\t\"flag to True of this \"\t\\\n\t\t\t\t\t\t\"array\");\t\t\\\n\t\t\t\treturn NULL;\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n \n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_newbyteorder[] = \"a.newbyteorder() is equivalent\\n\" \\\n\t\" to a.view(a.dtype.newbytorder())\\n\";\n\nstatic PyObject *\narray_newbyteorder(PyArrayObject *self, PyObject *args) \n{\n\tchar endian = PyArray_SWAP;\n\tPyArray_Descr *new;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\tnew = PyArray_DescrNewByteorder(self->descr, endian);\n\tif (!new) return NULL;\n\treturn PyArray_View(self, new, NULL);\n\n}\n\nstatic PyMethodDef array_methods[] = {\n {\"tolist\",\t (PyCFunction)array_tolist,\t1, doc_tolist},\n {\"item\", (PyCFunction)array_toscalar, METH_VARARGS, doc_toscalar},\n\t{\"tofile\", (PyCFunction)array_tofile, \n METH_VARARGS | METH_KEYWORDS, doc_tofile},\n {\"tostring\", (PyCFunction)array_tostring, METH_VARARGS, doc_tostring},\n {\"byteswap\", (PyCFunction)array_byteswap,\t1, doc_byteswap},\n {\"astype\", (PyCFunction)array_cast, 1, doc_cast},\n\t{\"getfield\", (PyCFunction)array_getfield, \n\t METH_VARARGS | METH_KEYWORDS, doc_getfield},\n\t{\"setfield\", (PyCFunction)array_setfield, \n\t METH_VARARGS | METH_KEYWORDS, doc_setfield},\n {\"copy\", (PyCFunction)array_copy, 1, doc_copy}, \n {\"resize\", (PyCFunction)array_resize, \n\t METH_VARARGS | METH_KEYWORDS, doc_resize}, \n\n\t/* for subtypes */\n\t{\"__array__\", (PyCFunction)array_getarray, 1, doc_array_getarray},\n\t{\"__array_wrap__\", (PyCFunction)array_wraparray, 1, doc_wraparray},\n\t/* default version so it is found... -- only used for subclasses */\n\t{\"__array_finalize__\", (PyCFunction)array_finalize, 1, NULL},\n\t\n\t\n\t/* for the copy module */\n {\"__copy__\", (PyCFunction)array_copy, 1, doc_copy},\t \n {\"__deepcopy__\", (PyCFunction)array_deepcopy, 1, doc_deepcopy}, \n\t\n /* for Pickling */\n {\"__reduce__\", (PyCFunction) array_reduce, 1, doc_reduce},\t\n\t{\"__setstate__\", (PyCFunction) array_setstate, 1, doc_setstate},\n\t{\"dumps\", (PyCFunction) array_dumps, 1, doc_dumps},\n\t{\"dump\", (PyCFunction) array_dump, 1, doc_dump},\n\n\t/* Extended methods added 2005 */\n\t{\"fill\", (PyCFunction)array_fill,\n\t METH_VARARGS, doc_fill},\n\t{\"transpose\",\t(PyCFunction)array_transpose, \n\t METH_VARARGS, doc_transpose},\n\t{\"take\",\t(PyCFunction)array_take, \n\t METH_VARARGS|METH_KEYWORDS, doc_take},\n\t{\"put\",\t(PyCFunction)array_put, \n\t METH_VARARGS|METH_KEYWORDS, doc_put},\n\t{\"putmask\",\t(PyCFunction)array_putmask, \n\t METH_VARARGS|METH_KEYWORDS, doc_putmask},\n\t{\"repeat\",\t(PyCFunction)array_repeat, \n\t METH_VARARGS|METH_KEYWORDS, doc_repeat},\n\t{\"choose\",\t(PyCFunction)array_choose, \n\t METH_VARARGS, doc_choose},\t\n\t{\"sort\",\t(PyCFunction)array_sort, \n\t METH_VARARGS|METH_KEYWORDS, doc_sort},\n\t{\"argsort\",\t(PyCFunction)array_argsort, \n\t METH_VARARGS|METH_KEYWORDS, doc_argsort},\n\t{\"searchsorted\", (PyCFunction)array_searchsorted, \n\t METH_VARARGS, doc_searchsorted},\t\n\t{\"argmax\",\t(PyCFunction)array_argmax, \n\t METH_VARARGS|METH_KEYWORDS, doc_argmax},\n\t{\"argmin\", (PyCFunction)array_argmin,\n\t METH_VARARGS|METH_KEYWORDS, 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|METH_KEYWORDS, doc_max},\n\t{\"min\", (PyCFunction)array_min,\n\t METH_VARARGS|METH_KEYWORDS, doc_min},\n\t{\"ptp\", (PyCFunction)array_ptp,\n\t METH_VARARGS|METH_KEYWORDS, doc_ptp},\n\t{\"mean\", (PyCFunction)array_mean,\n\t METH_VARARGS|METH_KEYWORDS, doc_mean},\n\t{\"trace\", (PyCFunction)array_trace,\n\t METH_VARARGS|METH_KEYWORDS, doc_trace},\n\t{\"diagonal\", (PyCFunction)array_diagonal,\n\t METH_VARARGS|METH_KEYWORDS, doc_diagonal},\n\t{\"clip\", (PyCFunction)array_clip,\n\t METH_VARARGS|METH_KEYWORDS, doc_clip},\n\t{\"conj\", (PyCFunction)array_conjugate,\n\t METH_VARARGS, doc_conj},\n\t{\"conjugate\", (PyCFunction)array_conjugate,\n\t METH_VARARGS, doc_conjugate},\n\t{\"nonzero\", (PyCFunction)array_nonzero,\n\t METH_VARARGS, doc_nonzero},\n\t{\"std\", (PyCFunction)array_stddev,\n\t METH_VARARGS|METH_KEYWORDS, doc_stddev},\n\t{\"var\", (PyCFunction)array_variance,\n\t METH_VARARGS|METH_KEYWORDS, doc_variance},\n\t{\"sum\", (PyCFunction)array_sum,\n\t METH_VARARGS|METH_KEYWORDS, doc_sum},\n\t{\"cumsum\", (PyCFunction)array_cumsum,\n\t METH_VARARGS|METH_KEYWORDS, doc_cumsum},\n\t{\"prod\", (PyCFunction)array_prod,\n\t METH_VARARGS|METH_KEYWORDS, doc_prod},\n\t{\"cumprod\", (PyCFunction)array_cumprod,\n\t METH_VARARGS|METH_KEYWORDS, doc_cumprod},\n\t{\"all\", (PyCFunction)array_all,\n\t METH_VARARGS|METH_KEYWORDS, doc_all},\n\t{\"any\", (PyCFunction)array_any,\n\t METH_VARARGS|METH_KEYWORDS, 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{\"round\", (PyCFunction)array_round,\n\t METH_VARARGS|METH_KEYWORDS, doc_round},\n\t{\"setflags\", (PyCFunction)array_setflags,\n\t METH_VARARGS|METH_KEYWORDS, doc_setflags},\n\t{\"newbyteorder\", (PyCFunction)array_newbyteorder,\n\t METH_VARARGS, doc_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n#undef _ARET\n\n\n", + "methods": [ + { + "name": "array_take", + "long_name": "array_take( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 12, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "array_fill", + "long_name": "array_fill( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "args" + ], + "start_line": 28, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_put", + "long_name": "array_put( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 71, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 43, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_putmask", + "long_name": "array_putmask( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 71, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 58, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_reshape", + "long_name": "array_reshape( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 38, + "complexity": 9, + "token_count": 201, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 77, + "end_line": 120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "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": 125, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_view", + "long_name": "array_view( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 19, + "complexity": 6, + "token_count": 110, + "parameters": [ + "self", + "args" + ], + "start_line": 134, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "array_argmax", + "long_name": "array_argmax( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 159, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_argmin", + "long_name": "array_argmin( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 175, + "end_line": 186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_max", + "long_name": "array_max( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 191, + "end_line": 202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_ptp", + "long_name": "array_ptp( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 207, + "end_line": 218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_min", + "long_name": "array_min( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 224, + "end_line": 235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "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": 240, + "end_line": 247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetField", + "long_name": "PyArray_GetField( PyArrayObject * self , PyArray_Descr * typed , int offset)", + "filename": "arraymethods.c", + "nloc": 23, + "complexity": 4, + "token_count": 155, + "parameters": [ + "self", + "typed", + "offset" + ], + "start_line": 259, + "end_line": 283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_getfield", + "long_name": "array_getfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 286, + "end_line": 298, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetField", + "long_name": "PyArray_SetField( PyArrayObject * self , PyArray_Descr * dtype , int offset , PyObject * val)", + "filename": "arraymethods.c", + "nloc": 25, + "complexity": 4, + "token_count": 184, + "parameters": [ + "self", + "dtype", + "offset", + "val" + ], + "start_line": 308, + "end_line": 334, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_setfield", + "long_name": "array_setfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 100, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 337, + "end_line": 352, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Byteswap", + "long_name": "PyArray_Byteswap( PyArrayObject * self , Bool inplace)", + "filename": "arraymethods.c", + "nloc": 37, + "complexity": 5, + "token_count": 226, + "parameters": [ + "self", + "inplace" + ], + "start_line": 359, + "end_line": 406, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_byteswap", + "long_name": "array_byteswap( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 413, + "end_line": 421, + "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": 427, + "end_line": 437, + "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": 443, + "end_line": 447, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_tofile", + "long_name": "array_tofile( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 33, + "complexity": 7, + "token_count": 208, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 452, + "end_line": 486, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_toscalar", + "long_name": "array_toscalar( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 4, + "token_count": 71, + "parameters": [ + "self", + "args" + ], + "start_line": 492, + "end_line": 501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_cast", + "long_name": "array_cast( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 13, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "args" + ], + "start_line": 508, + "end_line": 522, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_wraparray", + "long_name": "array_wraparray( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 27, + "complexity": 4, + "token_count": 147, + "parameters": [ + "self", + "args" + ], + "start_line": 530, + "end_line": 558, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "array_finalize", + "long_name": "array_finalize( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "args" + ], + "start_line": 562, + "end_line": 566, + "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": 7, + "token_count": 218, + "parameters": [ + "self", + "args" + ], + "start_line": 572, + "end_line": 615, + "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": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 624, + "end_line": 631, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_resize", + "long_name": "array_resize( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 42, + "complexity": 12, + "token_count": 227, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 639, + "end_line": 681, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "array_repeat", + "long_name": "array_repeat( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 689, + "end_line": 699, + "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": 709, + "end_line": 724, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_sort", + "long_name": "array_sort( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 98, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 729, + "end_line": 744, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_argsort", + "long_name": "array_argsort( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 80, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 751, + "end_line": 762, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_searchsorted", + "long_name": "array_searchsorted( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 773, + "end_line": 780, + "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": 785, + "end_line": 818, + "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": 822, + "end_line": 841, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_setobject_pkl", + "long_name": "_setobject_pkl( PyArrayObject * self , PyObject * list)", + "filename": "arraymethods.c", + "nloc": 17, + "complexity": 3, + "token_count": 115, + "parameters": [ + "self", + "list" + ], + "start_line": 844, + "end_line": 862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_reduce", + "long_name": "array_reduce( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 46, + "complexity": 7, + "token_count": 313, + "parameters": [ + "self", + "args" + ], + "start_line": 867, + "end_line": 930, + "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": 99, + "complexity": 18, + "token_count": 585, + "parameters": [ + "self", + "args" + ], + "start_line": 948, + "end_line": 1062, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 115, + "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": 1066, + "end_line": 1087, + "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": 1091, + "end_line": 1102, + "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": 1108, + "end_line": 1119, + "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": 1124, + "end_line": 1129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "array_transpose", + "long_name": "array_transpose( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 18, + "complexity": 5, + "token_count": 116, + "parameters": [ + "self", + "args" + ], + "start_line": 1135, + "end_line": 1155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "array_mean", + "long_name": "array_mean( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1173, + "end_line": 1185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_sum", + "long_name": "array_sum( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1212, + "end_line": 1224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_cumsum", + "long_name": "array_cumsum( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1230, + "end_line": 1242, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_prod", + "long_name": "array_prod( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1247, + "end_line": 1259, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_cumprod", + "long_name": "array_cumprod( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1265, + "end_line": 1277, + "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 , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1283, + "end_line": 1294, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_all", + "long_name": "array_all( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1299, + "end_line": 1310, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_stddev", + "long_name": "array_stddev( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1315, + "end_line": 1327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_variance", + "long_name": "array_variance( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1332, + "end_line": 1344, + "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": 1349, + "end_line": 1360, + "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": 1366, + "end_line": 1371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "array_trace", + "long_name": "array_trace( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 12, + "complexity": 2, + "token_count": 105, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1379, + "end_line": 1392, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "array_clip", + "long_name": "array_clip( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 74, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1400, + "end_line": 1410, + "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": 1417, + "end_line": 1423, + "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": 1429, + "end_line": 1439, + "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": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 1444, + "end_line": 1452, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ravel", + "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 1457, + "end_line": 1465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_round", + "long_name": "array_round( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1470, + "end_line": 1480, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_setflags", + "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 53, + "complexity": 10, + "token_count": 260, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1489, + "end_line": 1546, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "array_newbyteorder", + "long_name": "array_newbyteorder( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self", + "args" + ], + "start_line": 1552, + "end_line": 1564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "array_take", + "long_name": "array_take( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 12, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "array_fill", + "long_name": "array_fill( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "args" + ], + "start_line": 28, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_put", + "long_name": "array_put( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 71, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 43, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_putmask", + "long_name": "array_putmask( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 71, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 58, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_reverse_shape", + "long_name": "_reverse_shape( PyArray_Dims * newshape)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 2, + "token_count": 81, + "parameters": [ + "newshape" + ], + "start_line": 72, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_reshape", + "long_name": "array_reshape( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 50, + "complexity": 13, + "token_count": 299, + "parameters": [ + "self", + "args" + ], + "start_line": 94, + "end_line": 147, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_squeeze", + "long_name": "array_squeeze( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self", + "args" + ], + "start_line": 152, + "end_line": 156, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_view", + "long_name": "array_view( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 19, + "complexity": 6, + "token_count": 110, + "parameters": [ + "self", + "args" + ], + "start_line": 161, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "array_argmax", + "long_name": "array_argmax( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 186, + "end_line": 197, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_argmin", + "long_name": "array_argmin( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 202, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_max", + "long_name": "array_max( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 218, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_ptp", + "long_name": "array_ptp( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 234, + "end_line": 245, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_min", + "long_name": "array_min( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 251, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "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": 267, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetField", + "long_name": "PyArray_GetField( PyArrayObject * self , PyArray_Descr * typed , int offset)", + "filename": "arraymethods.c", + "nloc": 23, + "complexity": 4, + "token_count": 155, + "parameters": [ + "self", + "typed", + "offset" + ], + "start_line": 286, + "end_line": 310, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_getfield", + "long_name": "array_getfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 313, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetField", + "long_name": "PyArray_SetField( PyArrayObject * self , PyArray_Descr * dtype , int offset , PyObject * val)", + "filename": "arraymethods.c", + "nloc": 25, + "complexity": 4, + "token_count": 184, + "parameters": [ + "self", + "dtype", + "offset", + "val" + ], + "start_line": 335, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_setfield", + "long_name": "array_setfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 100, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 364, + "end_line": 379, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Byteswap", + "long_name": "PyArray_Byteswap( PyArrayObject * self , Bool inplace)", + "filename": "arraymethods.c", + "nloc": 37, + "complexity": 5, + "token_count": 226, + "parameters": [ + "self", + "inplace" + ], + "start_line": 386, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_byteswap", + "long_name": "array_byteswap( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 440, + "end_line": 448, + "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": 454, + "end_line": 464, + "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": 470, + "end_line": 474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_tofile", + "long_name": "array_tofile( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 33, + "complexity": 7, + "token_count": 208, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 479, + "end_line": 513, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_toscalar", + "long_name": "array_toscalar( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 4, + "token_count": 71, + "parameters": [ + "self", + "args" + ], + "start_line": 519, + "end_line": 528, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_cast", + "long_name": "array_cast( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 13, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "args" + ], + "start_line": 535, + "end_line": 549, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_wraparray", + "long_name": "array_wraparray( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 27, + "complexity": 4, + "token_count": 147, + "parameters": [ + "self", + "args" + ], + "start_line": 557, + "end_line": 585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "array_finalize", + "long_name": "array_finalize( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "args" + ], + "start_line": 589, + "end_line": 593, + "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": 7, + "token_count": 218, + "parameters": [ + "self", + "args" + ], + "start_line": 599, + "end_line": 642, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "array_copy", + "long_name": "array_copy( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "args" + ], + "start_line": 651, + "end_line": 657, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_resize", + "long_name": "array_resize( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 37, + "complexity": 10, + "token_count": 190, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 665, + "end_line": 703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "array_repeat", + "long_name": "array_repeat( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 711, + "end_line": 721, + "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": 731, + "end_line": 746, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_sort", + "long_name": "array_sort( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 98, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 751, + "end_line": 766, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_argsort", + "long_name": "array_argsort( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 80, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 773, + "end_line": 784, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_searchsorted", + "long_name": "array_searchsorted( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 795, + "end_line": 802, + "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": 807, + "end_line": 840, + "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": 844, + "end_line": 863, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_setobject_pkl", + "long_name": "_setobject_pkl( PyArrayObject * self , PyObject * list)", + "filename": "arraymethods.c", + "nloc": 17, + "complexity": 3, + "token_count": 115, + "parameters": [ + "self", + "list" + ], + "start_line": 866, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_reduce", + "long_name": "array_reduce( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 46, + "complexity": 7, + "token_count": 313, + "parameters": [ + "self", + "args" + ], + "start_line": 889, + "end_line": 952, + "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": 99, + "complexity": 18, + "token_count": 585, + "parameters": [ + "self", + "args" + ], + "start_line": 970, + "end_line": 1084, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 115, + "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": 1088, + "end_line": 1109, + "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": 1113, + "end_line": 1124, + "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": 1130, + "end_line": 1141, + "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": 1146, + "end_line": 1151, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "array_transpose", + "long_name": "array_transpose( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 18, + "complexity": 5, + "token_count": 116, + "parameters": [ + "self", + "args" + ], + "start_line": 1157, + "end_line": 1177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "array_mean", + "long_name": "array_mean( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1195, + "end_line": 1207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_sum", + "long_name": "array_sum( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1234, + "end_line": 1246, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_cumsum", + "long_name": "array_cumsum( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1252, + "end_line": 1264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_prod", + "long_name": "array_prod( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1269, + "end_line": 1281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_cumprod", + "long_name": "array_cumprod( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1287, + "end_line": 1299, + "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 , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1305, + "end_line": 1316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_all", + "long_name": "array_all( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1321, + "end_line": 1332, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_stddev", + "long_name": "array_stddev( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1337, + "end_line": 1349, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_variance", + "long_name": "array_variance( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1354, + "end_line": 1366, + "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": 1371, + "end_line": 1382, + "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": 1388, + "end_line": 1393, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "array_trace", + "long_name": "array_trace( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 12, + "complexity": 2, + "token_count": 105, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1401, + "end_line": 1414, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "array_clip", + "long_name": "array_clip( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 74, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1422, + "end_line": 1432, + "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": 1439, + "end_line": 1445, + "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": 1451, + "end_line": 1461, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_flatten", + "long_name": "array_flatten( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self", + "args" + ], + "start_line": 1466, + "end_line": 1473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_ravel", + "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "args" + ], + "start_line": 1478, + "end_line": 1485, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_round", + "long_name": "array_round( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1490, + "end_line": 1500, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_setflags", + "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 53, + "complexity": 10, + "token_count": 260, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1509, + "end_line": 1566, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "array_newbyteorder", + "long_name": "array_newbyteorder( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self", + "args" + ], + "start_line": 1572, + "end_line": 1584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "array_reshape", + "long_name": "array_reshape( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 50, + "complexity": 13, + "token_count": 299, + "parameters": [ + "self", + "args" + ], + "start_line": 94, + "end_line": 147, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_resize", + "long_name": "array_resize( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 42, + "complexity": 12, + "token_count": 227, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 639, + "end_line": 681, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "_reverse_shape", + "long_name": "_reverse_shape( PyArray_Dims * newshape)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 2, + "token_count": 81, + "parameters": [ + "newshape" + ], + "start_line": 72, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_reshape", + "long_name": "array_reshape( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 38, + "complexity": 9, + "token_count": 201, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 77, + "end_line": 120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "array_flatten", + "long_name": "array_flatten( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 1444, + "end_line": 1452, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_copy", + "long_name": "array_copy( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 624, + "end_line": 631, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_ravel", + "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 1457, + "end_line": 1465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + } + ], + "nloc": 1340, + "complexity": 222, + "token_count": 8342, + "diff_parsed": { + "added": [ + "\t\"self.reshape(d1, d2, ..., dn, fortran=False) \\n\"\t\\", + "\t\"Return a new array from this one. \\n\"\t\t\t\t\\", + "\t\"\\n The new array must have the same number of elements as self. \" \\", + "array_reshape(PyArrayObject *self, PyObject *args, PyObject *kwds)", + " PyObject *ret;", + "\tPyArray_CONDITION fortran=PyArray_FALSE;", + "\tif (kwds != NULL) {", + "\t\tPyObject *ref;", + "\t\tref = PyDict_GetItemString(kwds, \"fortran\");", + "\t\tif (ref == NULL || \\", + "\t\t (PyArray_ConditionConverter(ref, &fortran) == PY_FAIL))", + "\t\t\treturn NULL;", + "\t}", + "", + "", + "\tret = PyArray_Newshape(self, &newshape, fortran);", + " return ret;", + "\t\"If fortran is false then the result is contiguous (default). \\n\"\\", + "\t\"If fortran is true then the result has fortran data order. \\n\"\\", + "\t\"If fortran is None then the result has fortran data order only if m\\n\"", + "\tPyArray_CONDITION fortran=PyArray_FALSE;", + " if (!PyArg_ParseTuple(args, \"|O&\", PyArray_ConditionConverter,", + "\t\t\t &fortran)) return NULL;", + "static char doc_resize[] = \"self.resize(new_shape, refcheck=True, fortran=False). \"\\", + "\tPyArray_CONDITION fortran=PyArray_DONTCARE;", + "\t\tref = PyDict_GetItemString(kwds, \"fortran\");", + "\t\tif (ref != NULL ||", + "\t\t (PyArray_ConditionConverter(ref, &fortran) == PY_FAIL))", + "\t\t\treturn NULL;", + "\t}", + "\tret = PyArray_Resize(self, &newshape, refcheck, fortran);", + "\tPyArray_CONDITION fortran=PyArray_FALSE;", + "\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ConditionConverter,", + "\t\t\t &fortran)) return NULL;", + "\treturn PyArray_Flatten(self, fortran);", + "\tPyArray_CONDITION fortran=PyArray_FALSE;", + "", + "\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ConditionConverter,", + "\t\t\t &fortran)) return NULL;", + "\t METH_VARARGS|METH_KEYWORDS, doc_reshape}," + ], + "deleted": [ + "/* Used to reshape a Fortran Array */", + "static void", + "_reverse_shape(PyArray_Dims *newshape)", + "{", + "\tint i, n = newshape->len;", + "\tintp *ptr = newshape->ptr;", + "\tintp *eptr;", + "\tintp tmp;", + "\tint len = n >> 1;", + "", + "\teptr = ptr+n-1;", + "\tfor(i=0; i 0 then the result has fortran data order. \\n\"\\", + "\t\"If fortran < 0 then the result has fortran data order only if m\\n\"", + "\tint fortran=0;", + " if (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;", + "static char doc_resize[] = \"self.resize(new_shape, refcheck=True). \"\\", + "\t}", + "", + "\tret = PyArray_Resize(self, &newshape, refcheck);", + "\tint fortran=0;", + "\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;", + "\treturn PyArray_Flatten(self, (int) fortran);", + "\tint fortran=0;", + "", + "\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;", + "\t METH_VARARGS, doc_reshape}," + ] + } + }, + { + "old_path": "numpy/core/src/arrayobject.c", + "new_path": "numpy/core/src/arrayobject.c", + "filename": "arrayobject.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -801,10 +801,11 @@ PyArray_FromDims(int nd, int *d, int type)\n Copy an array.\n */\n static PyObject *\n-PyArray_NewCopy(PyArrayObject *m1, int fortran)\n+PyArray_NewCopy(PyArrayObject *m1, PyArray_CONDITION fortran)\n {\n \tPyArrayObject *ret;\n-\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n+\tif (fortran == PyArray_DONTCARE) \n+\t\tfortran = PyArray_ISFORTRAN(m1);\n \n \tPy_INCREF(m1->descr);\n \tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,\n@@ -4098,7 +4099,8 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,\n object.\n */\n static PyObject *\n-PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck)\n+PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck,\n+\t PyArray_CONDITION fortran)\n {\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n@@ -4115,6 +4117,9 @@ PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck)\n return NULL;\n }\n \n+\tif (fortran == PyArray_DONTCARE)\n+\t\tfortran = PyArray_FALSE;\n+\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n \n", + "added_lines": 8, + "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/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_)\n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear();\n priority = default_;\n }\n Py_XDECREF(ret);\n return priority;\n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a\n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n }\n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int\ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides,\n\t intp *src_dimensions, int src_nd, int elsize,\n\t int copies) {\n intp i, j;\n\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1,\n dest_dimensions+1, dest_nd-1,\n src, src_strides,\n src_dimensions, src_nd,\n elsize, copies) == -1)\n return -1;\n }\n return 0;\n }\n\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError,\n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) &&\n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] !=\n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src)\n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\n dest_strides_ptr = dest_strides;\n\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1)\n return NULL;\n\n new_data = (char *)_pya_malloc(stride);\n\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions,\n dest_nd, src->data, src_strides,\n src_dimensions, src_nd, elsize, copies);\n\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *,\n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int\nPyArray_INCREF(PyArrayObject *mp)\n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap)\n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n\n\n if ((numitems == 1) || (itemsize == srcstrides))\n memcpy(d1, s1, itemsize*numitems);\n else {\n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n }\n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG\n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i)\n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp\nPyArray_Size(PyObject *op)\n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n }\n\telse {\n return 0;\n }\n}\n\n/* If destination is not the right type, then src\n will be cast to destination.\n*/\n\n/* Does a flat iterator-based copy.\n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however.\n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n\n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError,\n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n\n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, elsize);\n PyArray_INCREF(dest);\n return 0;\n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n }\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int\nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)\n{\n PyArrayObject *src;\n int ret;\n\t\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d,\n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t} \n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, PyArray_CONDITION fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran == PyArray_DONTCARE) \n\t\tfortran = PyArray_ISFORTRAN(m1);\n\n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,\n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd,\n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran,\n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\n return (PyObject *)ret;\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) {\n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED;\n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=0;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use\n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifndef Py_UNICODE_WIDE\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\treturn obj;\n#endif\n\t\t}\n\t\telse {\n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, itemsize);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this.\n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag\n*/\n\n/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp)\n{\n\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n\n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int\nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs,\n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/*\n copyies over from the old descr table for anything\n NULL or zero in what is given.\n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)\n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data,\n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError,\n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr,\n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element\"\\\n \" %d to file\",\n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj);\n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj),\n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\",\n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1)\n fwrite(sep, 1, n3, fp);\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self)\n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0)\n\t\treturn self->descr->f->getitem(self->data,self);\n\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n\n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void\narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an\n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE\n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n\n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\narray_length(PyArrayObject *self)\n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i)\n{\n\tchar *item;\n\tPyArrayObject *r;\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1,\n\t\t\t\t\t\t self->dimensions+1,\n\t\t\t\t\t\t self->strides+1, item,\n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\nstatic PyObject *\narray_item_nice(PyArrayObject *self, _int_or_ssize_t i)\n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\n\nstatic int\narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v)\n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret;\n }\n\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if PY_VERSION_HEX < 0x02050000\n #if SIZEOF_INT == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#else\n #if SIZEOF_SIZE_T == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#endif\n#ifndef array_ass_item\nstatic int\narray_ass_item(PyArrayObject *self, _int_or_ssize_t i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int\nparse_index(PyArrayObject *self, PyObject *op,\n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError,\n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\n nd_old = nd_new = 0;\n\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n\t/* tuple for transpose is\n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of\n\t the broadcasted index array\n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the\n\t result\n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2)\n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call.\n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type,\n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret))\n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, PyArray_ITEMSIZE(arr));\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS];\n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL)\n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0\n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from\n Python when using a[object] unless object is a standard slice object\n (not an extended one).\n\n*/\n\n/* There are two situations:\n\n 1 - the subscript is a standard view and a reference to the\n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned.\n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *);\n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op)\n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr,\n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis) {\n\t\t\t/* XXX: This leads to a small inconsistency\n\t\t\t XXX: with the nd>0 case where (x[...] is x)\n\t\t\t XXX: is false for nd>0 case. */\n\t\t\tPy_INCREF(self);\n\t\t\treturn (PyObject *)self;\n\t\t}\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op)) {\n\t\t\t\tPy_INCREF(self);\n\t\t\t\treturn (PyObject *)self;\n\t\t\t}\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset))\n == -1)\n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset,\n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL)\n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be\n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *);\n\nstatic int\narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)\n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr,\n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1;\n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to\n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op)\n{\n\t/* The following is just a copy of PyArray_Return with an\n\t additional logic in the nd == 0 case. More efficient\n\t implementation may be possible by refactoring\n\t array_subscript */\n\n\tPyArrayObject *mp = (PyArrayObject *)array_subscript(self, op);\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tBool noellipses = TRUE;\n\t\tif (op == Py_Ellipsis)\n\t\t\tnoellipses = FALSE;\n\t\telse if (PySequence_Check(op)) {\n\t\t\tint n, i;\n\t\t\tn = PySequence_Size(op);\n\t\t\tfor (i = 0; i < n; ++i) \n\t\t\t\tif (PySequence_GetItem(op, i) == Py_Ellipsis) {\n\t\t\t\t\tnoellipses = FALSE;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t\tif (noellipses) {\n\t\t\tPyObject *ret;\n\t\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\t\tPy_DECREF(mp);\n\t\t\treturn ret;\n\t\t}\n\t}\n\treturn (PyObject *)mp;\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t /*mp_length*/\n#else\n (inquiry)array_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic _int_or_ssize_t\narray_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp)\n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic _int_or_ssize_t\narray_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"accessing non-existing array segment\");\n return -1;\n }\n\n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic _int_or_ssize_t\narray_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (PyArray_CHKFLAGS(self, WRITEABLE))\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic _int_or_ssize_t\narray_getcharbuf(PyArrayObject *self, _int_or_ssize_t segment, const char **ptrptr)\n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError,\n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (writebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (segcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (charbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#else\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#endif\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n *square,\n *reciprocal,\n *ones_like,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum,\n\t\t*rint;\n} NumericOps;\n\nstatic NumericOps n_ops; /* NB: static objects inlitialized to zero */\n\n/* Dictionary can contain any of the numeric operations, by name.\n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n\n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint\nPyArray_SetNumericOps(PyObject *dict)\n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n SET(square);\n SET(reciprocal);\n SET(ones_like);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\n SET(true_divide);\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n\tSET(rint);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void)\n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL)\n\t\treturn NULL;\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n GET(square);\n GET(reciprocal);\n GET(ones_like);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide);\n GET(true_divide);\n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\tGET(rint);\n\treturn dict;\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,\n\t\t\t\t PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2)\n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\n\nstatic PyObject *array_float(PyArrayObject *v);\n\n\nstatic int\narray_power_is_scalar(PyObject *o2, double* exp)\n{\n PyObject *temp;\n const int optimize_fpexps = 1;\n if (PyInt_Check(o2)) {\n *exp = (double)PyInt_AsLong(o2);\n return 1;\n }\n if (optimize_fpexps && PyFloat_Check(o2)) {\n *exp = PyFloat_AsDouble(o2);\n return 1;\n }\n if (PyArray_CheckScalar(o2)) {\n if (PyArray_ISINTEGER(o2) || (optimize_fpexps && PyArray_ISFLOAT(o2))) {\n temp = array_float((PyArrayObject *)o2);\n if (temp != NULL) {\n *exp = PyFloat_AsDouble(o2);\n Py_DECREF(temp);\n return 1;\n }\n }\n }\n return 0;\n}\n\n/* optimize float array or complex array to a scalar power */\nstatic PyObject *\nfast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) {\n double exp;\n if (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) || PyArray_ISCOMPLEX(a1))) {\n if (array_power_is_scalar(o2, &exp)) {\n PyObject *fastop = NULL;\n if (exp == 1.0) {\n /* we have to do this one special, as the \"copy\" method of\n array objects isn't set up early enough to be added\n by PyArray_SetNumericOps.\n */\n if (inplace) {\n return (PyObject *)a1;\n } else {\n return PyArray_Copy(a1);\n }\n } else if (exp == -1.0) {\n fastop = n_ops.reciprocal;\n } else if (exp == 0.0) {\n fastop = n_ops.ones_like;\n } else if (exp == 0.5) {\n fastop = n_ops.sqrt;\n } else if (exp == 2.0) {\n fastop = n_ops.square;\n } else {\n return NULL;\n }\n if (inplace) {\n PyArray_GenericInplaceUnaryFunction(a1, fastop);\n } else {\n return PyArray_GenericUnaryFunction(a1, fastop);\n }\n }\n }\n return NULL;\n}\n\nstatic PyObject *\narray_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 0);\n if (!value) {\n value = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\n\nstatic PyObject *\narray_negative(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 1);\n if (!value) {\n value = PyArray_GenericInplaceBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int\narray_any_nonzero(PyArrayObject *mp)\n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2)\n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_float(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to a \"\\\n\t\t\t\t\"float; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_long(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/\n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected\n*/\n\n\nstatic PyObject *\narray_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t _int_or_ssize_t ihigh)\n{\n PyArrayObject *r;\n _int_or_ssize_t l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n self->dimensions[0] = l;\n\tif (r == NULL) return NULL;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS);\n return (PyObject *)r;\n}\n\n\nstatic int\narray_ass_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t\t_int_or_ssize_t ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res;\n int ret;\n\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\nstatic PySequenceMethods array_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (ssizeargfunc)NULL,\n\t(ssizeargfunc)array_item_nice,\n\t(ssizessizeargfunc)array_slice,\n (ssizeobjargproc)array_ass_item,\t /*sq_ass_item*/\n (ssizessizeobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(ssizeargfunc)NULL,\n#else\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t /*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n#endif\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int\ndump_data(char **string, int *n, int *max_n, char *data, int nd,\n intp *dimensions, intp *strides, PyArrayObject* self)\n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\n if (nd == 0) {\n\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata,\n\t\t self->nd, self->dimensions,\n self->strides, self) < 0) {\n\t\t_pya_free(string); return NULL;\n\t}\n\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void\nPyArray_SetStringFunction(PyObject *op, int repr)\n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_ReprFunction = op;\n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_StrFunction = op;\n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)\n{\n PyObject *array_other, *result;\n\tint typenum;\n\n switch (cmp_op)\n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then return False\n\t\t\t\t This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of False\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the\n\t\t\t two array objects can not be compared together so\n\t\t\t return zero\n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be\n\t\t\t\t compared and cannot be equal, therefore,\n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t other,\n\t\t\t\t\t\t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL,\n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int\n_IsFortranContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap)\n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object\n\t If it is a writeable array, then return TRUE\n\t If we can find an array object\n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable\n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA))\n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly\n\t and unpickled array can be set and reset writeable\n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t\telse ret->flags &= ~WRITEABLE;\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not\n ever be able to walk outside of the memory implied numbytes and offset.\n\n The available memory is assumed to start at -offset and proceed\n to numbytes-offset. The strides are checked to ensure\n that accessing memory using striding will not try to reach beyond\n this memory for any of the axes.\n\n If numbytes is 0 it will be calculated using the dimensions and\n element-size.\n\n This function checks for walking beyond the beginning and right-end\n of the buffer and therefore works for any integer stride (positive\n or negative).\n*/\n\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\tintp byte_begin;\n\tintp begin;\n\tintp end;\n\n\tif (numbytes == 0)\n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\n\tbegin = -offset;\n\tend = numbytes - offset - elsize;\n\tfor (i=0; i end))\n\t\t\treturn FALSE;\n\t}\n\treturn TRUE;\n\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings\n depending on data and strides:\n\n If data is given, then flags is flags associated with data.\n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument\n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set).\n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired.\n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize,\n\t\t int inflag, int *objflags)\n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\n/* and update the dimensions and strides\n appropriately. Dimensions and strides are added\n to the end unless we have a FORTRAN array\n and then they are added to the beginning\n\n Strides are only added if given (because data is given).\n*/\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,\n\t\t\t intp *newstrides, int oldnd, int isfortran)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\tint tuple;\n\n\told = *des;\n\t*des = old->subarray->base;\n\n\n\tmydim = newdims + oldnd;\n\ttuple = PyTuple_Check(old->subarray->shape);\n\tif (tuple) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t}\n\telse {\n\t\tnumnew = 1;\n\t}\n\n\n\tnewnd = oldnd + numnew;\n\tif (newnd > MAX_DIMS) goto finish;\n\tif (isfortran) {\n\t\tmemmove(newdims+numnew, newdims, oldnd*sizeof(intp));\n\t\tmydim = newdims;\n\t}\n\n\tif (tuple) {\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\tif (isfortran) {\n\t\t\tmemmove(newstrides+numnew, newstrides,\n\t\t\t\toldnd*sizeof(intp));\n\t\t\tmystrides = newstrides;\n\t\t}\n\t\t/* Make new strides -- alwasy C-contiguous */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\n finish:\n\tPy_INCREF(*des);\n\tPy_DECREF(old);\n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,\n\t\t intp *dims, intp *strides, void *data,\n\t\t int flags, PyObject *obj)\n{\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tint isfortran=0;\n\t\tisfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || \\\n\t\t\t(!data && flags);\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims,\n\t\t\t\t\t\t newstrides, nd, isfortran);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims,\n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { \n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN;\n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse { /* we allow strides even when we create\n\t\t\t the memory, but be careful with this...\n\t\t */\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays\n\t\t e.g. shape=(0,) -- otherwise buffer exposure\n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in,\n\t\t\t\t\t this object won't own it\n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for\n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype.\n\t If obj is NULL, then call method with Py_None \n\t*/\n\tif ((subtype != &PyArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (strides != NULL) { /* did not allocate own data \n\t\t\t\t\t or funny strides */\n\t\t\t/* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tif (obj == NULL) obj=Py_None;\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n If refcheck is 0, then the reference count is not checked\n and assumed to be 1.\n You still must own this data and have no weak-references and no base\n object.\n*/\nstatic PyObject *\nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck,\n\t PyArray_CONDITION fortran)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\n if (!PyArray_ISONESEGMENT(self)) {\n PyErr_SetString(PyExc_ValueError,\n \"resize only works on single-segment arrays\");\n return NULL;\n }\n\n\tif (fortran == PyArray_DONTCARE)\n\t\tfortran = PyArray_FALSE;\n\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n\n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (refcheck) refcnt = REFCOUNT(self);\n\t\telse refcnt = 1;\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (newsize == 0) sd = self->descr->elsize;\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n\n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) {\n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0,\n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n\n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n\n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n self->flags, &(self->flags));\n\n\n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\n return Py_None;\n\n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\tPyArray_FillWithScalarFunc* fillwithscalar =\n\t\t\tarr->descr->f->fillwithscalar;\n\t\tif (fillwithscalar && PyArray_ISALIGNED(arr)) {\n\t\t\tcopyswap(fromptr, NULL, swap, itemsize);\n\t\t\tfillwithscalar(toptr, size, fromptr, arr);\n\t\t}\n\t\telse {\n\t\t\twhile (size--) {\n\t\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\t\ttoptr += itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL;\n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous\n\t array of a specific type and shape.\n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims,\n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter,\n &strides,\n &fortran))\n\t\tgoto fail;\n\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"data-type with unspecified variable length\");\n\t\tgoto fail;\n\t}\n\t\n\tif (strides.ptr != NULL) {\n\t\tintp nb, off;\n\t\tif (strides.len != dims.len) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides, if given, must be \"\t\\\n\t\t\t\t\t\"the same length as shape\");\n\t\t\tgoto fail;\n\t\t}\n\n\t\tif (buffer.ptr == NULL) {\n\t\t\tnb = 0;\n\t\t\toff = 0;\n\t\t}\n\t\telse {\n\t\t\tnb = buffer.len;\n\t\t\toff = offset;\n\t\t}\n\t\t\n\n\t\tif (!PyArray_CheckStrides(itemsize, dims.len, \n\t\t\t\t\t nb, off,\n\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides is incompatible \"\t\\\n\t\t\t\t\t\"with shape of requested \"\t\\\n\t\t\t\t\t\"array and size of buffer\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\t\t\t\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len,\n\t\t\t\t\t dims.ptr,\n\t\t\t\t\t strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = (buffer.len-offset) / itemsize;\n }\n else if ((strides.ptr == NULL) && \\\n\t\t\t buffer.len < itemsize*\t\t\t\t\\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError,\n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t offset + (char *)buffer.ptr,\n\t\t\t\t\t buffer.flags, NULL);\n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base);\n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyArray_NewFlagsObject((PyObject *)self);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n\tint nd;\n\tPyObject *ret;\n\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret),\n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret),\n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes=0;\n\tintp offset=0;\n\tint buf_len;\n\tchar *buf;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base && PyArray_Check(new->base)) {\n\t\tnew = (PyArrayObject *)(new->base);\n\t}\n\t/* Get the available memory through the buffer\n\t interface on new->base or if that fails\n\t from the current new */\n\tif (new->base && PyObject_AsReadBuffer(new->base,\n\t\t\t\t\t (const void **)&buf,\n\t\t\t\t\t &buf_len) >= 0) {\n\t\toffset = self->data - buf;\n\t\tnumbytes = buf_len + offset;\n\t}\n\telse {\n\t\tPyErr_Clear();\n \t\tnumbytes = PyArray_MultiplyList(new->dimensions,\n\t\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\toffset = self->data - new->data;\n\t}\n\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes,\n\t\t\t\t offset,\n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self))\n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self)\n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0,\n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf,\n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse\n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse\n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed.\n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the\n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0)\n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n\telse if (newtype->elsize > self->descr->elsize) {\n\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update\n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\t/* We would decref newtype here --- temp will\n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tif (temp == NULL) return -1;\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\tPy_INCREF(temp->descr);\n\t\t/* Fool deallocator not to delete these*/\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype;\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA);\n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num -\n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type,\n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new);\n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int\narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode,\n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr));\n memmove(selfit->dataptr, arrit->dataptr,\n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size)\n PyArray_ITER_RESET(arrit);\n }\n retval = 0;\n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->descr->elsize);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size)\n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\",\n\t (getter)array_ndim_get,\n\t NULL,\n\t \"number of array dimensions\"},\n {\"flags\",\n\t (getter)array_flags_get,\n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\",\n\t (getter)array_shape_get,\n\t (setter)array_shape_set,\n\t \"tuple of array dimensions\"},\n {\"strides\",\n\t (getter)array_strides_get,\n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)array_data_get,\n\t (setter)array_data_set,\n\t \"pointer to start of data\"},\n {\"itemsize\",\n\t (getter)array_itemsize_get,\n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\",\n\t (getter)array_real_get,\n\t (setter)array_real_set,\n\t \"real part of array\"},\n {\"imag\",\n\t (getter)array_imag_get,\n\t (setter)array_imag_set,\n\t \"imaginary part of array\"},\n\t{\"flat\",\n\t (getter)array_flat_get,\n\t (setter)array_flat_set,\n\t \"a 1-d view of a contiguous array\"},\n\t{\"__array_data__\",\n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\",\n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n\t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */\n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] =\n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\nstatic PyTypeObject PyArray_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0,\t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n &array_as_sequence,\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str,\t /*tp_str*/\n\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n &array_as_buffer, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT\n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter,\t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n array_alloc,\t /* tp_alloc */\n (newfunc)array_new,\t\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int\ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple)\n{\n int d=0;\n PyObject *e;\n\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0)\n\t\treturn 1;\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize)\n{\n\tint n, r, i;\n\tPyObject *e;\n\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s)\n\t\t\t*itemsize = MAX(*itemsize, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype ---\n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately\n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE &&\n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\nstatic PyArray_Descr *\n_array_find_python_scalar_type(PyObject *op)\n{\n if (PyFloat_Check(op)) {\n return PyArray_DescrFromType(PyArray_DOUBLE);\n } else if (PyComplex_Check(op)) {\n return PyArray_DescrFromType(PyArray_CDOUBLE);\n } else if (PyInt_Check(op)) {\n /* bools are a subclass of int */\n if (PyBool_Check(op)) {\n return PyArray_DescrFromType(PyArray_BOOL);\n } else {\n return PyArray_DescrFromType(PyArray_LONG);\n }\n } else if (PyLong_Check(op)) {\n /* if integer can fit into a longlong then return that\n */\n if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n PyErr_Clear();\n return PyArray_DescrFromType(PyArray_OBJECT);\n }\n return PyArray_DescrFromType(PyArray_LONGLONG);\n }\n return NULL;\n}\n\n/* op is an object to be converted to an ndarray.\n\n minitype is the minimum type-descriptor needed.\n\n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n\n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\n\tif (minitype == NULL)\n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\n if (max < 0) goto deflt;\n\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n chktype = _array_find_python_scalar_type(op);\n if (chktype) {\n goto finish;\n }\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n\n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind,\n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n }\n\n\tif (PyInstance_Check(op)) goto deflt;\n\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\n finish:\n\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype;\n}\n\nstatic int\nAssign_Array(PyArrayObject *self, PyObject *v)\n{\n PyObject *e;\n int l, r;\n\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\n l=PyObject_Length(v);\n if(l < 0) return -1;\n\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1;\n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */\n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode)\n{\n PyArrayObject *ret;\n\tint itemsize;\n\tint type;\n\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= 4;\n\n\t\tif (itemsize != typecode->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(typecode);\n\t\t\ttypecode->elsize = itemsize;\n\t\t}\n\t}\n\n ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL,\n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\tif (ret == NULL) return NULL;\n\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode */\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string,\n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid input sequence\");\n\t\tgoto fail;\n }\n\n\tif (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {\n\t\tnd = max_depth;\n\t}\n\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid number of dimensions\");\n\t\tgoto fail;\n }\n\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\n if(!r) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int\nPyArray_ValidType(int type)\n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in))\n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, 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\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n oelsize);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject *\nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING)\n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd,\n\t\t\t\t mp->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\n}\n\n/* The number of elements in out must be an integer multiple\n of the number of elements in mp.\n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1;\n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * mpsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr,\n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)\n{\n\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1)\n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse {\n if ((flags & ENSUREARRAY)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype,\n\t\t\t\t\t\t newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr;\n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\n\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong))\n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char))\n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long))\n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap)\n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n\n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL;\n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n\n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data,\n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr));\n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n\n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context)\n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, \n\t\t\t\t\t\t\t\t NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None,\n\t\t\t\t\t\t context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", \n\t\t\t\t\t\t typecode, context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", \n\t\t\t\t\t\t\t typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError,\n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n}\n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,\n int max_depth, int flags, PyObject *context)\n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op))\n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t} else if (newtype == NULL &&\n (newtype = _array_find_python_scalar_type(op))) {\n r = Array_FromScalar(op, newtype);\n }\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, \n\t\t\t\t\t\tflags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\n\t/* Be sure we succeed here */\n\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int\nPyArray_ObjectType(PyObject *op, int minimum_type)\n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of\n CONTIGUOUS,\n FORTRAN,\n ALIGNED,\n WRITEABLE,\n NOTSWAPPED,\n ENSURECOPY,\n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should\n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or\n not it has such features.\n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well.\n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n\n FORTRAN can be set in the FLAGS to request a FORTRAN array.\n Fortran arrays are always behaved (aligned,\n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d).\n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array.\n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe.\n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,\n int max_depth, int requires, PyObject *context)\n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0,\n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place\n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op)) return op;\n\n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int\nPyArray_CanCastSafely(int fromtype, int totype)\n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype))\n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode\n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\n\t\t*/\n\t}\n\treturn ret;\n}\n\n/*OBJECT_API\n See if array scalars can be cast.\n */\nstatic Bool\nPyArray_CanCastScalar(PyTypeObject *from, PyTypeObject *to)\n{\n\tint fromtype;\n\tint totype;\n\n\tfromtype = _typenum_fromtypeobj((PyObject *)from, 0);\n\ttotype = _typenum_fromtypeobj((PyObject *)to, 0);\n\tif (fromtype == PyArray_NOTYPE || totype == PyArray_NOTYPE) \n\t\treturn FALSE;\n\treturn (Bool) PyArray_CanCastSafely(fromtype, totype);\t\n}\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n\n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd;\n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D)\n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic _int_or_ssize_t\niter_length(PyArrayIterObject *self)\n{\n return self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr,\n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1)\n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t 1, &n_steps,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail;\n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0,\n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n\t\t\t\t itemsize);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size)\n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size)\n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)\n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size)\n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0,\n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)iter_length,\t\t /*mp_length*/\n#else\n (inquiry)iter_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op)\n{\n\n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options:\n 1) underlying array is contiguous\n -- return 1-d wrapper around it\n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, it->ao->data,\n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r);\n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n\n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\",\n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &iter_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t\t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular\n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators\n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++)\n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already\n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1)\n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\n\t\t\t\t\t\t\t\"to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of\n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord,\n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t sizeof(intp));\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so,\n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size.\n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere.\n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well.\n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0\n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t/* But, be sure to do it with a true array.\n\t */\n\tif (PyArray_CheckExact(arr)) {\n\t\tsub = array_subscript(arr, mit->indexobj);\n\t}\n\telse {\n\t\tPy_INCREF(arr);\n\t\tobj = PyArray_EnsureArray((PyObject *)arr);\n\t\tif (obj == NULL) goto fail;\n\t\tsub = array_subscript((PyArrayObject *)obj, mit->indexobj);\n\t\tPy_DECREF(obj);\n\t}\n\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects\n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been\n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj))\n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj,\n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1;\n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) *indptr, (int) (dimsize-1),\n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0,\n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n\tmit->index = 0;\n\tmit->ait = NULL;\n\tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY\n#undef SOBJ_ISFANCY\n#undef SOBJ_BADARRAY\n#undef SOBJ_TOOMANY\n#undef SOBJ_LISTTUP\n\n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple\n\t (with at least 1 list or arrayobject or Bool object), */\n\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i,\n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing\n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n\n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work.\n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a);\n mapiter is equivalent to a[indexobj].flat but the latter gets to use\n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t\t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t\t /* tp_iter */\n (iternextfunc)0,\t /* tp_iternext */\n 0,\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\n\tint i, err=0;\n\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\n\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL)\n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i,\n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(multi->iters[i]);\n\t_pya_free(multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\",\n\t (getter)arraymultiter_size_get,\n\t NULL,\n\t \"total size of broadcasted result\"},\n {\"index\",\n\t (getter)arraymultiter_index_get,\n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter),\n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t\t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods,\t /* tp_methods */\n arraymultiter_members,\t\t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types.\n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these\n builtins will be attempted leading to problems.\n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically\n allocated).\n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless\n there is a reference-count problem\n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set.\n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base,\n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0)\n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\",\n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self)\n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\",\n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr)\n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr)\n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv))\n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\n\t/* Now return the state which is at least\n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize\n and alignment for EXTENDED arrays\n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\n\tif (PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are:\n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args)\n{\n\tchar endian=PyArray_SWAP;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS,\n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n\tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\ndescr_length(PyArray_Descr *self)\n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op)\n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError,\n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)descr_length,\t\t /*mp_length*/\n#else\n (inquiry)descr_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t\t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &descr_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t/* tp_iternext */\n arraydescr_methods,\t\t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n\n/** Array Flags Object **/\n\ntypedef struct PyArrayFlagsObject {\n PyObject_HEAD\n PyObject *arr;\n int flags;\n} PyArrayFlagsObject;\n\n/*OBJECT_API\n Get New ArrayFlagsObject\n*/\nstatic PyObject *\nPyArray_NewFlagsObject(PyObject *obj)\n{\n PyObject *flagobj;\n int flags;\n if (obj == NULL) {\n flags = CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n }\n else {\n flags = PyArray_FLAGS(obj);\n }\n flagobj = PyArrayFlags_Type.tp_alloc(&PyArrayFlags_Type, 0);\n if (flagobj == NULL) return NULL;\n Py_XINCREF(obj);\n ((PyArrayFlagsObject *)flagobj)->arr = obj;\n ((PyArrayFlagsObject *)flagobj)->flags = flags;\n\n return flagobj;\n}\n\nstatic void\narrayflags_dealloc(PyArrayFlagsObject *self)\n{\n\tPy_XDECREF(self->arr);\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n\n#define _define_get(UPPER, lower) \\\nstatic PyObject * \\\narrayflags_ ## lower ## _get(PyArrayFlagsObject *self) \\\n{ \\\n PyObject *item; \\\n item = ((self->flags & (UPPER)) == (UPPER)) ? Py_True : Py_False; \\\n Py_INCREF(item); \\\n return item; \\\n}\n\n_define_get(CONTIGUOUS, contiguous)\n_define_get(FORTRAN, fortran)\n_define_get(UPDATEIFCOPY, updateifcopy)\n_define_get(OWNDATA, owndata)\n_define_get(ALIGNED, aligned)\n_define_get(WRITEABLE, writeable)\n\n_define_get(ALIGNED|WRITEABLE, behaved)\n_define_get(ALIGNED|WRITEABLE|CONTIGUOUS, carray)\n\nstatic PyObject *\narrayflags_forc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) ||\n ((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_fnc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_farray_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & (ALIGNED|WRITEABLE|FORTRAN)) == \\\n (ALIGNED|WRITEABLE|FORTRAN)) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_num_get(PyArrayFlagsObject *self)\n{\n return PyInt_FromLong(self->flags);\n}\n\n/* relies on setflags order being write, align, uic */\nstatic int\narrayflags_updateifcopy_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False));\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_aligned_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_writeable_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None, Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\n\nstatic PyGetSetDef arrayflags_getsets[] = {\n\t{\"contiguous\",\n\t (getter)arrayflags_contiguous_get,\n\t NULL,\n\t \"\"},\n {\"fortran\",\n (getter)arrayflags_fortran_get,\n NULL,\n \"\"},\n {\"updateifcopy\",\n (getter)arrayflags_updateifcopy_get,\n (setter)arrayflags_updateifcopy_set,\n \"\"},\n {\"owndata\",\n (getter)arrayflags_owndata_get,\n NULL,\n \"\"},\n {\"aligned\",\n (getter)arrayflags_aligned_get,\n (setter)arrayflags_aligned_set,\n \"\"},\n {\"writeable\",\n (getter)arrayflags_writeable_get,\n (setter)arrayflags_writeable_set,\n \"\"},\n {\"fnc\",\n (getter)arrayflags_fnc_get,\n NULL,\n \"\"},\n {\"forc\",\n (getter)arrayflags_forc_get,\n NULL,\n \"\"},\n {\"behaved\",\n (getter)arrayflags_behaved_get,\n NULL,\n \"\"},\n {\"carray\",\n (getter)arrayflags_carray_get,\n NULL,\n \"\"},\n {\"farray\",\n (getter)arrayflags_farray_get,\n NULL,\n \"\"},\n {\"num\",\n (getter)arrayflags_num_get,\n NULL,\n \"\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyObject *\narrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)\n{\n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n\tswitch(n) {\n\tcase 1:\n\t\tswitch(key[0]) {\n\t\tcase 'C':\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tcase 'F':\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tcase 'W':\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tcase 'B':\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tcase 'O':\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tcase 'A':\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tcase 'U':\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tdefault:\n\t\t\tgoto fail;\n\t\t}\n\t\tbreak;\n\tcase 2:\n\t\tif (strncmp(key, \"CA\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FA\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 3:\n\t\tif (strncmp(key, \"FNC\", n)==0)\n\t\t\treturn arrayflags_fnc_get(self);\n\t\tbreak;\n\tcase 4:\n\t\tif (strncmp(key, \"FORC\", n)==0)\n\t\t\treturn arrayflags_forc_get(self);\n\t\tbreak;\n\tcase 6:\n\t\tif (strncmp(key, \"CARRAY\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FARRAY\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 7:\n\t\tif (strncmp(key,\"FORTRAN\",n)==0)\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tif (strncmp(key,\"BEHAVED\",n)==0)\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tif (strncmp(key,\"OWNDATA\",n)==0)\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tif (strncmp(key,\"ALIGNED\",n)==0)\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tbreak;\n\tcase 9:\t\n\t\tif (strncmp(key,\"WRITEABLE\",n)==0)\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tbreak;\n\tcase 10:\n\t\tif (strncmp(key,\"CONTIGUOUS\",n)==0)\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tbreak;\n\tcase 12:\n\t\tif (strncmp(key, \"UPDATEIFCOPY\", n)==0)\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tbreak;\n\t}\n\n fail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return NULL;\n}\n\nstatic int\narrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)\n{ \n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n if (((n==9) && (strncmp(key, \"WRITEABLE\", n)==0)) ||\n\t ((n==1) && (strncmp(key, \"W\", n)==0)))\n return arrayflags_writeable_set(self, item);\n else if (((n==7) && (strncmp(key, \"ALIGNED\", n)==0)) || \n ((n==1) && (strncmp(key, \"A\", n)==0)))\n return arrayflags_aligned_set(self, item);\n else if (((n==12) && (strncmp(key, \"UPDATEIFCOPY\", n)==0)) ||\n ((n==1) && (strncmp(key, \"U\", n)==0)))\n return arrayflags_updateifcopy_set(self, item); \n\nfail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return -1;\n}\n\nstatic char *\n_torf_(int flags, int val)\n{\n if ((flags & val) == val) return \"True\";\n else return \"False\"; \n}\n\nstatic PyObject *\narrayflags_print(PyArrayFlagsObject *self)\n{\n int fl = self->flags;\n \n return PyString_FromFormat(\" %s : %s\\n %s : %s\\n %s : %s\\n\"\\\n \" %s : %s\\n %s : %s\\n %s : %s\",\n \"CONTIGUOUS\", _torf_(fl, CONTIGUOUS),\n \"FORTRAN\", _torf_(fl, FORTRAN),\n \"OWNDATA\", _torf_(fl, OWNDATA),\n \"WRITEABLE\", _torf_(fl, WRITEABLE),\n \"ALIGNED\", _torf_(fl, ALIGNED),\n \"UPDATEIFCOPY\", _torf_(fl, UPDATEIFCOPY));\n}\n\n\nstatic PyMappingMethods arrayflags_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)NULL, \t\t /*mp_length*/\n#else\n (inquiry)NULL, \t\t /*mp_length*/\n#endif\n (binaryfunc)arrayflags_getitem,\t /*mp_subscript*/\n (objobjargproc)arrayflags_setitem, /*mp_ass_subscript*/\n};\n\n\nstatic PyObject *\narrayflags_new(PyTypeObject *self, PyObject *args, PyObject *kwds)\n{\n PyObject *arg=NULL;\n if (!PyArg_UnpackTuple(args, \"flagsobj\", 0, 1, &arg))\n return NULL;\n\n if ((arg != NULL) && PyArray_Check(arg)) {\n return PyArray_NewFlagsObject(arg);\n }\n else {\n return PyArray_NewFlagsObject(NULL);\n }\n}\n\nstatic PyTypeObject PyArrayFlags_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\n \"numpy.flagsobj\",\n sizeof(PyArrayFlagsObject),\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayflags_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t0,\t\t /* tp_compare */\n (reprfunc)arrayflags_print, /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &arrayflags_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arrayflags_print, /* tp_str */\n 0,\t \t /* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t /* tp_iternext */\n 0,\t \t /* tp_methods */\n 0,\t /* tp_members */\n arrayflags_getsets, /* tp_getset */\n 0,\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t /* tp_init */\n 0,\t /* tp_alloc */\n arrayflags_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "source_code_before": "/*\n Provide multidimensional arrays as a basic object type in python.\n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004\n\nHeavily modified in 2005 with inspiration from Numarray\n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University\n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by\nSpace Science Telescope Institute\n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_)\n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear();\n priority = default_;\n }\n Py_XDECREF(ret);\n return priority;\n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a\n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n }\n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int\ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides,\n\t intp *src_dimensions, int src_nd, int elsize,\n\t int copies) {\n intp i, j;\n\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1,\n dest_dimensions+1, dest_nd-1,\n src, src_strides,\n src_dimensions, src_nd,\n elsize, copies) == -1)\n return -1;\n }\n return 0;\n }\n\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError,\n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) &&\n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] !=\n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src)\n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\n dest_strides_ptr = dest_strides;\n\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1)\n return NULL;\n\n new_data = (char *)_pya_malloc(stride);\n\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions,\n dest_nd, src->data, src_strides,\n src_dimensions, src_nd, elsize, copies);\n\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *,\n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int\nPyArray_INCREF(PyArrayObject *mp)\n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap)\n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n\n\n if ((numitems == 1) || (itemsize == srcstrides))\n memcpy(d1, s1, itemsize*numitems);\n else {\n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n }\n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG\n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i)\n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp\nPyArray_Size(PyObject *op)\n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n }\n\telse {\n return 0;\n }\n}\n\n/* If destination is not the right type, then src\n will be cast to destination.\n*/\n\n/* Does a flat iterator-based copy.\n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however.\n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n\n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError,\n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n\n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, elsize);\n PyArray_INCREF(dest);\n return 0;\n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n }\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int\nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)\n{\n PyArrayObject *src;\n int ret;\n\t\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d,\n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t} \n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,\n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd,\n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran,\n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\n return (PyObject *)ret;\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) {\n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED;\n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=0;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use\n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifndef Py_UNICODE_WIDE\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\treturn obj;\n#endif\n\t\t}\n\t\telse {\n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, itemsize);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this.\n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag\n*/\n\n/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp)\n{\n\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n\n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int\nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs,\n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/*\n copyies over from the old descr table for anything\n NULL or zero in what is given.\n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)\n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data,\n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError,\n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr,\n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element\"\\\n \" %d to file\",\n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj);\n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj),\n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\",\n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1)\n fwrite(sep, 1, n3, fp);\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self)\n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0)\n\t\treturn self->descr->f->getitem(self->data,self);\n\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n\n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void\narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an\n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE\n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n\n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\narray_length(PyArrayObject *self)\n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i)\n{\n\tchar *item;\n\tPyArrayObject *r;\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1,\n\t\t\t\t\t\t self->dimensions+1,\n\t\t\t\t\t\t self->strides+1, item,\n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\nstatic PyObject *\narray_item_nice(PyArrayObject *self, _int_or_ssize_t i)\n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\n\nstatic int\narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v)\n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret;\n }\n\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if PY_VERSION_HEX < 0x02050000\n #if SIZEOF_INT == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#else\n #if SIZEOF_SIZE_T == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#endif\n#ifndef array_ass_item\nstatic int\narray_ass_item(PyArrayObject *self, _int_or_ssize_t i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int\nparse_index(PyArrayObject *self, PyObject *op,\n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError,\n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\n nd_old = nd_new = 0;\n\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n\t/* tuple for transpose is\n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of\n\t the broadcasted index array\n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the\n\t result\n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2)\n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call.\n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type,\n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret))\n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, PyArray_ITEMSIZE(arr));\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS];\n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL)\n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0\n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from\n Python when using a[object] unless object is a standard slice object\n (not an extended one).\n\n*/\n\n/* There are two situations:\n\n 1 - the subscript is a standard view and a reference to the\n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned.\n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *);\n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op)\n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr,\n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis) {\n\t\t\t/* XXX: This leads to a small inconsistency\n\t\t\t XXX: with the nd>0 case where (x[...] is x)\n\t\t\t XXX: is false for nd>0 case. */\n\t\t\tPy_INCREF(self);\n\t\t\treturn (PyObject *)self;\n\t\t}\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op)) {\n\t\t\t\tPy_INCREF(self);\n\t\t\t\treturn (PyObject *)self;\n\t\t\t}\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset))\n == -1)\n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset,\n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL)\n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be\n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *);\n\nstatic int\narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)\n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr,\n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1;\n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to\n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op)\n{\n\t/* The following is just a copy of PyArray_Return with an\n\t additional logic in the nd == 0 case. More efficient\n\t implementation may be possible by refactoring\n\t array_subscript */\n\n\tPyArrayObject *mp = (PyArrayObject *)array_subscript(self, op);\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tBool noellipses = TRUE;\n\t\tif (op == Py_Ellipsis)\n\t\t\tnoellipses = FALSE;\n\t\telse if (PySequence_Check(op)) {\n\t\t\tint n, i;\n\t\t\tn = PySequence_Size(op);\n\t\t\tfor (i = 0; i < n; ++i) \n\t\t\t\tif (PySequence_GetItem(op, i) == Py_Ellipsis) {\n\t\t\t\t\tnoellipses = FALSE;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t\tif (noellipses) {\n\t\t\tPyObject *ret;\n\t\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\t\tPy_DECREF(mp);\n\t\t\treturn ret;\n\t\t}\n\t}\n\treturn (PyObject *)mp;\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t /*mp_length*/\n#else\n (inquiry)array_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic _int_or_ssize_t\narray_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp)\n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic _int_or_ssize_t\narray_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"accessing non-existing array segment\");\n return -1;\n }\n\n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic _int_or_ssize_t\narray_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (PyArray_CHKFLAGS(self, WRITEABLE))\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic _int_or_ssize_t\narray_getcharbuf(PyArrayObject *self, _int_or_ssize_t segment, const char **ptrptr)\n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError,\n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (writebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (segcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (charbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#else\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#endif\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n *square,\n *reciprocal,\n *ones_like,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum,\n\t\t*rint;\n} NumericOps;\n\nstatic NumericOps n_ops; /* NB: static objects inlitialized to zero */\n\n/* Dictionary can contain any of the numeric operations, by name.\n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n\n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint\nPyArray_SetNumericOps(PyObject *dict)\n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n SET(square);\n SET(reciprocal);\n SET(ones_like);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\n SET(true_divide);\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n\tSET(rint);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void)\n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL)\n\t\treturn NULL;\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n GET(square);\n GET(reciprocal);\n GET(ones_like);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide);\n GET(true_divide);\n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\tGET(rint);\n\treturn dict;\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,\n\t\t\t\t PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2)\n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\n\nstatic PyObject *array_float(PyArrayObject *v);\n\n\nstatic int\narray_power_is_scalar(PyObject *o2, double* exp)\n{\n PyObject *temp;\n const int optimize_fpexps = 1;\n if (PyInt_Check(o2)) {\n *exp = (double)PyInt_AsLong(o2);\n return 1;\n }\n if (optimize_fpexps && PyFloat_Check(o2)) {\n *exp = PyFloat_AsDouble(o2);\n return 1;\n }\n if (PyArray_CheckScalar(o2)) {\n if (PyArray_ISINTEGER(o2) || (optimize_fpexps && PyArray_ISFLOAT(o2))) {\n temp = array_float((PyArrayObject *)o2);\n if (temp != NULL) {\n *exp = PyFloat_AsDouble(o2);\n Py_DECREF(temp);\n return 1;\n }\n }\n }\n return 0;\n}\n\n/* optimize float array or complex array to a scalar power */\nstatic PyObject *\nfast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) {\n double exp;\n if (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) || PyArray_ISCOMPLEX(a1))) {\n if (array_power_is_scalar(o2, &exp)) {\n PyObject *fastop = NULL;\n if (exp == 1.0) {\n /* we have to do this one special, as the \"copy\" method of\n array objects isn't set up early enough to be added\n by PyArray_SetNumericOps.\n */\n if (inplace) {\n return (PyObject *)a1;\n } else {\n return PyArray_Copy(a1);\n }\n } else if (exp == -1.0) {\n fastop = n_ops.reciprocal;\n } else if (exp == 0.0) {\n fastop = n_ops.ones_like;\n } else if (exp == 0.5) {\n fastop = n_ops.sqrt;\n } else if (exp == 2.0) {\n fastop = n_ops.square;\n } else {\n return NULL;\n }\n if (inplace) {\n PyArray_GenericInplaceUnaryFunction(a1, fastop);\n } else {\n return PyArray_GenericUnaryFunction(a1, fastop);\n }\n }\n }\n return NULL;\n}\n\nstatic PyObject *\narray_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 0);\n if (!value) {\n value = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\n\nstatic PyObject *\narray_negative(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 1);\n if (!value) {\n value = PyArray_GenericInplaceBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int\narray_any_nonzero(PyArrayObject *mp)\n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2)\n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_float(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to a \"\\\n\t\t\t\t\"float; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_long(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/\n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected\n*/\n\n\nstatic PyObject *\narray_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t _int_or_ssize_t ihigh)\n{\n PyArrayObject *r;\n _int_or_ssize_t l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n self->dimensions[0] = l;\n\tif (r == NULL) return NULL;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS);\n return (PyObject *)r;\n}\n\n\nstatic int\narray_ass_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t\t_int_or_ssize_t ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res;\n int ret;\n\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\nstatic PySequenceMethods array_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (ssizeargfunc)NULL,\n\t(ssizeargfunc)array_item_nice,\n\t(ssizessizeargfunc)array_slice,\n (ssizeobjargproc)array_ass_item,\t /*sq_ass_item*/\n (ssizessizeobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(ssizeargfunc)NULL,\n#else\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t /*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n#endif\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int\ndump_data(char **string, int *n, int *max_n, char *data, int nd,\n intp *dimensions, intp *strides, PyArrayObject* self)\n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\n if (nd == 0) {\n\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata,\n\t\t self->nd, self->dimensions,\n self->strides, self) < 0) {\n\t\t_pya_free(string); return NULL;\n\t}\n\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void\nPyArray_SetStringFunction(PyObject *op, int repr)\n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_ReprFunction = op;\n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_StrFunction = op;\n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)\n{\n PyObject *array_other, *result;\n\tint typenum;\n\n switch (cmp_op)\n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then return False\n\t\t\t\t This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of False\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the\n\t\t\t two array objects can not be compared together so\n\t\t\t return zero\n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be\n\t\t\t\t compared and cannot be equal, therefore,\n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other,\n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t other,\n\t\t\t\t\t\t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL,\n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int\n_IsFortranContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap)\n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object\n\t If it is a writeable array, then return TRUE\n\t If we can find an array object\n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable\n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA))\n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly\n\t and unpickled array can be set and reset writeable\n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t\telse ret->flags &= ~WRITEABLE;\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not\n ever be able to walk outside of the memory implied numbytes and offset.\n\n The available memory is assumed to start at -offset and proceed\n to numbytes-offset. The strides are checked to ensure\n that accessing memory using striding will not try to reach beyond\n this memory for any of the axes.\n\n If numbytes is 0 it will be calculated using the dimensions and\n element-size.\n\n This function checks for walking beyond the beginning and right-end\n of the buffer and therefore works for any integer stride (positive\n or negative).\n*/\n\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\tintp byte_begin;\n\tintp begin;\n\tintp end;\n\n\tif (numbytes == 0)\n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\n\tbegin = -offset;\n\tend = numbytes - offset - elsize;\n\tfor (i=0; i end))\n\t\t\treturn FALSE;\n\t}\n\treturn TRUE;\n\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings\n depending on data and strides:\n\n If data is given, then flags is flags associated with data.\n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument\n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set).\n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired.\n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize,\n\t\t int inflag, int *objflags)\n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\n/* and update the dimensions and strides\n appropriately. Dimensions and strides are added\n to the end unless we have a FORTRAN array\n and then they are added to the beginning\n\n Strides are only added if given (because data is given).\n*/\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,\n\t\t\t intp *newstrides, int oldnd, int isfortran)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\tint tuple;\n\n\told = *des;\n\t*des = old->subarray->base;\n\n\n\tmydim = newdims + oldnd;\n\ttuple = PyTuple_Check(old->subarray->shape);\n\tif (tuple) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t}\n\telse {\n\t\tnumnew = 1;\n\t}\n\n\n\tnewnd = oldnd + numnew;\n\tif (newnd > MAX_DIMS) goto finish;\n\tif (isfortran) {\n\t\tmemmove(newdims+numnew, newdims, oldnd*sizeof(intp));\n\t\tmydim = newdims;\n\t}\n\n\tif (tuple) {\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\tif (isfortran) {\n\t\t\tmemmove(newstrides+numnew, newstrides,\n\t\t\t\toldnd*sizeof(intp));\n\t\t\tmystrides = newstrides;\n\t\t}\n\t\t/* Make new strides -- alwasy C-contiguous */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\n finish:\n\tPy_INCREF(*des);\n\tPy_DECREF(old);\n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,\n\t\t intp *dims, intp *strides, void *data,\n\t\t int flags, PyObject *obj)\n{\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tint isfortran=0;\n\t\tisfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || \\\n\t\t\t(!data && flags);\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims,\n\t\t\t\t\t\t newstrides, nd, isfortran);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims,\n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { \n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN;\n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse { /* we allow strides even when we create\n\t\t\t the memory, but be careful with this...\n\t\t */\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays\n\t\t e.g. shape=(0,) -- otherwise buffer exposure\n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in,\n\t\t\t\t\t this object won't own it\n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for\n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype.\n\t If obj is NULL, then call method with Py_None \n\t*/\n\tif ((subtype != &PyArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (strides != NULL) { /* did not allocate own data \n\t\t\t\t\t or funny strides */\n\t\t\t/* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tif (obj == NULL) obj=Py_None;\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n If refcheck is 0, then the reference count is not checked\n and assumed to be 1.\n You still must own this data and have no weak-references and no base\n object.\n*/\nstatic PyObject *\nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\n if (!PyArray_ISONESEGMENT(self)) {\n PyErr_SetString(PyExc_ValueError,\n \"resize only works on single-segment arrays\");\n return NULL;\n }\n\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n\n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (refcheck) refcnt = REFCOUNT(self);\n\t\telse refcnt = 1;\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (newsize == 0) sd = self->descr->elsize;\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n\n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) {\n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0,\n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n\n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n\n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n self->flags, &(self->flags));\n\n\n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\n return Py_None;\n\n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\tPyArray_FillWithScalarFunc* fillwithscalar =\n\t\t\tarr->descr->f->fillwithscalar;\n\t\tif (fillwithscalar && PyArray_ISALIGNED(arr)) {\n\t\t\tcopyswap(fromptr, NULL, swap, itemsize);\n\t\t\tfillwithscalar(toptr, size, fromptr, arr);\n\t\t}\n\t\telse {\n\t\t\twhile (size--) {\n\t\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\t\ttoptr += itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL;\n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous\n\t array of a specific type and shape.\n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims,\n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter,\n &strides,\n &fortran))\n\t\tgoto fail;\n\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"data-type with unspecified variable length\");\n\t\tgoto fail;\n\t}\n\t\n\tif (strides.ptr != NULL) {\n\t\tintp nb, off;\n\t\tif (strides.len != dims.len) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides, if given, must be \"\t\\\n\t\t\t\t\t\"the same length as shape\");\n\t\t\tgoto fail;\n\t\t}\n\n\t\tif (buffer.ptr == NULL) {\n\t\t\tnb = 0;\n\t\t\toff = 0;\n\t\t}\n\t\telse {\n\t\t\tnb = buffer.len;\n\t\t\toff = offset;\n\t\t}\n\t\t\n\n\t\tif (!PyArray_CheckStrides(itemsize, dims.len, \n\t\t\t\t\t nb, off,\n\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides is incompatible \"\t\\\n\t\t\t\t\t\"with shape of requested \"\t\\\n\t\t\t\t\t\"array and size of buffer\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\t\t\t\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len,\n\t\t\t\t\t dims.ptr,\n\t\t\t\t\t strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = (buffer.len-offset) / itemsize;\n }\n else if ((strides.ptr == NULL) && \\\n\t\t\t buffer.len < itemsize*\t\t\t\t\\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError,\n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t offset + (char *)buffer.ptr,\n\t\t\t\t\t buffer.flags, NULL);\n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base);\n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyArray_NewFlagsObject((PyObject *)self);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n\tint nd;\n\tPyObject *ret;\n\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret),\n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret),\n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes=0;\n\tintp offset=0;\n\tint buf_len;\n\tchar *buf;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base && PyArray_Check(new->base)) {\n\t\tnew = (PyArrayObject *)(new->base);\n\t}\n\t/* Get the available memory through the buffer\n\t interface on new->base or if that fails\n\t from the current new */\n\tif (new->base && PyObject_AsReadBuffer(new->base,\n\t\t\t\t\t (const void **)&buf,\n\t\t\t\t\t &buf_len) >= 0) {\n\t\toffset = self->data - buf;\n\t\tnumbytes = buf_len + offset;\n\t}\n\telse {\n\t\tPyErr_Clear();\n \t\tnumbytes = PyArray_MultiplyList(new->dimensions,\n\t\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\toffset = self->data - new->data;\n\t}\n\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes,\n\t\t\t\t offset,\n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self))\n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self)\n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0,\n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf,\n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse\n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse\n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed.\n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the\n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0)\n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n\telse if (newtype->elsize > self->descr->elsize) {\n\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update\n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\t/* We would decref newtype here --- temp will\n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tif (temp == NULL) return -1;\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\tPy_INCREF(temp->descr);\n\t\t/* Fool deallocator not to delete these*/\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype;\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA);\n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num -\n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type,\n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new);\n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int\narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode,\n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr));\n memmove(selfit->dataptr, arrit->dataptr,\n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size)\n PyArray_ITER_RESET(arrit);\n }\n retval = 0;\n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->descr->elsize);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size)\n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\",\n\t (getter)array_ndim_get,\n\t NULL,\n\t \"number of array dimensions\"},\n {\"flags\",\n\t (getter)array_flags_get,\n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\",\n\t (getter)array_shape_get,\n\t (setter)array_shape_set,\n\t \"tuple of array dimensions\"},\n {\"strides\",\n\t (getter)array_strides_get,\n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)array_data_get,\n\t (setter)array_data_set,\n\t \"pointer to start of data\"},\n {\"itemsize\",\n\t (getter)array_itemsize_get,\n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\",\n\t (getter)array_real_get,\n\t (setter)array_real_set,\n\t \"real part of array\"},\n {\"imag\",\n\t (getter)array_imag_get,\n\t (setter)array_imag_set,\n\t \"imaginary part of array\"},\n\t{\"flat\",\n\t (getter)array_flat_get,\n\t (setter)array_flat_set,\n\t \"a 1-d view of a contiguous array\"},\n\t{\"__array_data__\",\n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\",\n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n\t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */\n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] =\n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\nstatic PyTypeObject PyArray_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0,\t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n &array_as_sequence,\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str,\t /*tp_str*/\n\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n &array_as_buffer, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT\n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter,\t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n array_alloc,\t /* tp_alloc */\n (newfunc)array_new,\t\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int\ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple)\n{\n int d=0;\n PyObject *e;\n\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0)\n\t\treturn 1;\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize)\n{\n\tint n, r, i;\n\tPyObject *e;\n\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s)\n\t\t\t*itemsize = MAX(*itemsize, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype ---\n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately\n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE &&\n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\nstatic PyArray_Descr *\n_array_find_python_scalar_type(PyObject *op)\n{\n if (PyFloat_Check(op)) {\n return PyArray_DescrFromType(PyArray_DOUBLE);\n } else if (PyComplex_Check(op)) {\n return PyArray_DescrFromType(PyArray_CDOUBLE);\n } else if (PyInt_Check(op)) {\n /* bools are a subclass of int */\n if (PyBool_Check(op)) {\n return PyArray_DescrFromType(PyArray_BOOL);\n } else {\n return PyArray_DescrFromType(PyArray_LONG);\n }\n } else if (PyLong_Check(op)) {\n /* if integer can fit into a longlong then return that\n */\n if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n PyErr_Clear();\n return PyArray_DescrFromType(PyArray_OBJECT);\n }\n return PyArray_DescrFromType(PyArray_LONGLONG);\n }\n return NULL;\n}\n\n/* op is an object to be converted to an ndarray.\n\n minitype is the minimum type-descriptor needed.\n\n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n\n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\n\tif (minitype == NULL)\n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\n if (max < 0) goto deflt;\n\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n chktype = _array_find_python_scalar_type(op);\n if (chktype) {\n goto finish;\n }\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n\n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind,\n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n }\n\n\tif (PyInstance_Check(op)) goto deflt;\n\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\n finish:\n\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype;\n}\n\nstatic int\nAssign_Array(PyArrayObject *self, PyObject *v)\n{\n PyObject *e;\n int l, r;\n\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\n l=PyObject_Length(v);\n if(l < 0) return -1;\n\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1;\n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */\n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode)\n{\n PyArrayObject *ret;\n\tint itemsize;\n\tint type;\n\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= 4;\n\n\t\tif (itemsize != typecode->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(typecode);\n\t\t\ttypecode->elsize = itemsize;\n\t\t}\n\t}\n\n ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL,\n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\tif (ret == NULL) return NULL;\n\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode */\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string,\n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid input sequence\");\n\t\tgoto fail;\n }\n\n\tif (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {\n\t\tnd = max_depth;\n\t}\n\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid number of dimensions\");\n\t\tgoto fail;\n }\n\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\n if(!r) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int\nPyArray_ValidType(int type)\n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in))\n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, 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\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n oelsize);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject *\nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING)\n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd,\n\t\t\t\t mp->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\n}\n\n/* The number of elements in out must be an integer multiple\n of the number of elements in mp.\n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1;\n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * mpsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr,\n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)\n{\n\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1)\n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse {\n if ((flags & ENSUREARRAY)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype,\n\t\t\t\t\t\t newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr;\n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\n\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong))\n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char))\n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long))\n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap)\n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n\n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL;\n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n\n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data,\n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr));\n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n\n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context)\n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, \n\t\t\t\t\t\t\t\t NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None,\n\t\t\t\t\t\t context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", \n\t\t\t\t\t\t typecode, context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", \n\t\t\t\t\t\t\t typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError,\n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n}\n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,\n int max_depth, int flags, PyObject *context)\n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op))\n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t} else if (newtype == NULL &&\n (newtype = _array_find_python_scalar_type(op))) {\n r = Array_FromScalar(op, newtype);\n }\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, \n\t\t\t\t\t\tflags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\n\t/* Be sure we succeed here */\n\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int\nPyArray_ObjectType(PyObject *op, int minimum_type)\n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of\n CONTIGUOUS,\n FORTRAN,\n ALIGNED,\n WRITEABLE,\n NOTSWAPPED,\n ENSURECOPY,\n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should\n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or\n not it has such features.\n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well.\n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n\n FORTRAN can be set in the FLAGS to request a FORTRAN array.\n Fortran arrays are always behaved (aligned,\n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d).\n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array.\n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe.\n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,\n int max_depth, int requires, PyObject *context)\n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0,\n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place\n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op)) return op;\n\n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int\nPyArray_CanCastSafely(int fromtype, int totype)\n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype))\n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode\n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\n\t\t*/\n\t}\n\treturn ret;\n}\n\n/*OBJECT_API\n See if array scalars can be cast.\n */\nstatic Bool\nPyArray_CanCastScalar(PyTypeObject *from, PyTypeObject *to)\n{\n\tint fromtype;\n\tint totype;\n\n\tfromtype = _typenum_fromtypeobj((PyObject *)from, 0);\n\ttotype = _typenum_fromtypeobj((PyObject *)to, 0);\n\tif (fromtype == PyArray_NOTYPE || totype == PyArray_NOTYPE) \n\t\treturn FALSE;\n\treturn (Bool) PyArray_CanCastSafely(fromtype, totype);\t\n}\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n\n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd;\n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D)\n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic _int_or_ssize_t\niter_length(PyArrayIterObject *self)\n{\n return self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr,\n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1)\n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t 1, &n_steps,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail;\n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0,\n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n\t\t\t\t itemsize);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size)\n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size)\n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)\n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size)\n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0,\n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)iter_length,\t\t /*mp_length*/\n#else\n (inquiry)iter_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op)\n{\n\n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options:\n 1) underlying array is contiguous\n -- return 1-d wrapper around it\n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, it->ao->data,\n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r);\n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n\n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\",\n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &iter_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t\t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular\n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators\n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++)\n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already\n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1)\n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\n\t\t\t\t\t\t\t\"to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of\n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord,\n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t sizeof(intp));\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so,\n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size.\n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere.\n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well.\n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0\n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t/* But, be sure to do it with a true array.\n\t */\n\tif (PyArray_CheckExact(arr)) {\n\t\tsub = array_subscript(arr, mit->indexobj);\n\t}\n\telse {\n\t\tPy_INCREF(arr);\n\t\tobj = PyArray_EnsureArray((PyObject *)arr);\n\t\tif (obj == NULL) goto fail;\n\t\tsub = array_subscript((PyArrayObject *)obj, mit->indexobj);\n\t\tPy_DECREF(obj);\n\t}\n\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects\n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been\n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj))\n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj,\n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1;\n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) *indptr, (int) (dimsize-1),\n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0,\n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n\tmit->index = 0;\n\tmit->ait = NULL;\n\tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY\n#undef SOBJ_ISFANCY\n#undef SOBJ_BADARRAY\n#undef SOBJ_TOOMANY\n#undef SOBJ_LISTTUP\n\n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple\n\t (with at least 1 list or arrayobject or Bool object), */\n\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i,\n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing\n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n\n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work.\n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a);\n mapiter is equivalent to a[indexobj].flat but the latter gets to use\n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t\t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t\t /* tp_iter */\n (iternextfunc)0,\t /* tp_iternext */\n 0,\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\n\tint i, err=0;\n\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\n\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL)\n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i,\n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(multi->iters[i]);\n\t_pya_free(multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\",\n\t (getter)arraymultiter_size_get,\n\t NULL,\n\t \"total size of broadcasted result\"},\n {\"index\",\n\t (getter)arraymultiter_index_get,\n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter),\n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t\t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods,\t /* tp_methods */\n arraymultiter_members,\t\t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types.\n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these\n builtins will be attempted leading to problems.\n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically\n allocated).\n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless\n there is a reference-count problem\n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set.\n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base,\n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0)\n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\",\n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self)\n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\",\n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr)\n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr)\n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv))\n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\n\t/* Now return the state which is at least\n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize\n and alignment for EXTENDED arrays\n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\n\tif (PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are:\n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args)\n{\n\tchar endian=PyArray_SWAP;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS,\n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n\tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\ndescr_length(PyArray_Descr *self)\n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op)\n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError,\n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)descr_length,\t\t /*mp_length*/\n#else\n (inquiry)descr_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t\t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &descr_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t/* tp_iternext */\n arraydescr_methods,\t\t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n\n/** Array Flags Object **/\n\ntypedef struct PyArrayFlagsObject {\n PyObject_HEAD\n PyObject *arr;\n int flags;\n} PyArrayFlagsObject;\n\n/*OBJECT_API\n Get New ArrayFlagsObject\n*/\nstatic PyObject *\nPyArray_NewFlagsObject(PyObject *obj)\n{\n PyObject *flagobj;\n int flags;\n if (obj == NULL) {\n flags = CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n }\n else {\n flags = PyArray_FLAGS(obj);\n }\n flagobj = PyArrayFlags_Type.tp_alloc(&PyArrayFlags_Type, 0);\n if (flagobj == NULL) return NULL;\n Py_XINCREF(obj);\n ((PyArrayFlagsObject *)flagobj)->arr = obj;\n ((PyArrayFlagsObject *)flagobj)->flags = flags;\n\n return flagobj;\n}\n\nstatic void\narrayflags_dealloc(PyArrayFlagsObject *self)\n{\n\tPy_XDECREF(self->arr);\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n\n#define _define_get(UPPER, lower) \\\nstatic PyObject * \\\narrayflags_ ## lower ## _get(PyArrayFlagsObject *self) \\\n{ \\\n PyObject *item; \\\n item = ((self->flags & (UPPER)) == (UPPER)) ? Py_True : Py_False; \\\n Py_INCREF(item); \\\n return item; \\\n}\n\n_define_get(CONTIGUOUS, contiguous)\n_define_get(FORTRAN, fortran)\n_define_get(UPDATEIFCOPY, updateifcopy)\n_define_get(OWNDATA, owndata)\n_define_get(ALIGNED, aligned)\n_define_get(WRITEABLE, writeable)\n\n_define_get(ALIGNED|WRITEABLE, behaved)\n_define_get(ALIGNED|WRITEABLE|CONTIGUOUS, carray)\n\nstatic PyObject *\narrayflags_forc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) ||\n ((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_fnc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_farray_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & (ALIGNED|WRITEABLE|FORTRAN)) == \\\n (ALIGNED|WRITEABLE|FORTRAN)) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_num_get(PyArrayFlagsObject *self)\n{\n return PyInt_FromLong(self->flags);\n}\n\n/* relies on setflags order being write, align, uic */\nstatic int\narrayflags_updateifcopy_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False));\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_aligned_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_writeable_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None, Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\n\nstatic PyGetSetDef arrayflags_getsets[] = {\n\t{\"contiguous\",\n\t (getter)arrayflags_contiguous_get,\n\t NULL,\n\t \"\"},\n {\"fortran\",\n (getter)arrayflags_fortran_get,\n NULL,\n \"\"},\n {\"updateifcopy\",\n (getter)arrayflags_updateifcopy_get,\n (setter)arrayflags_updateifcopy_set,\n \"\"},\n {\"owndata\",\n (getter)arrayflags_owndata_get,\n NULL,\n \"\"},\n {\"aligned\",\n (getter)arrayflags_aligned_get,\n (setter)arrayflags_aligned_set,\n \"\"},\n {\"writeable\",\n (getter)arrayflags_writeable_get,\n (setter)arrayflags_writeable_set,\n \"\"},\n {\"fnc\",\n (getter)arrayflags_fnc_get,\n NULL,\n \"\"},\n {\"forc\",\n (getter)arrayflags_forc_get,\n NULL,\n \"\"},\n {\"behaved\",\n (getter)arrayflags_behaved_get,\n NULL,\n \"\"},\n {\"carray\",\n (getter)arrayflags_carray_get,\n NULL,\n \"\"},\n {\"farray\",\n (getter)arrayflags_farray_get,\n NULL,\n \"\"},\n {\"num\",\n (getter)arrayflags_num_get,\n NULL,\n \"\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyObject *\narrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)\n{\n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n\tswitch(n) {\n\tcase 1:\n\t\tswitch(key[0]) {\n\t\tcase 'C':\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tcase 'F':\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tcase 'W':\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tcase 'B':\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tcase 'O':\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tcase 'A':\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tcase 'U':\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tdefault:\n\t\t\tgoto fail;\n\t\t}\n\t\tbreak;\n\tcase 2:\n\t\tif (strncmp(key, \"CA\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FA\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 3:\n\t\tif (strncmp(key, \"FNC\", n)==0)\n\t\t\treturn arrayflags_fnc_get(self);\n\t\tbreak;\n\tcase 4:\n\t\tif (strncmp(key, \"FORC\", n)==0)\n\t\t\treturn arrayflags_forc_get(self);\n\t\tbreak;\n\tcase 6:\n\t\tif (strncmp(key, \"CARRAY\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FARRAY\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 7:\n\t\tif (strncmp(key,\"FORTRAN\",n)==0)\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tif (strncmp(key,\"BEHAVED\",n)==0)\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tif (strncmp(key,\"OWNDATA\",n)==0)\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tif (strncmp(key,\"ALIGNED\",n)==0)\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tbreak;\n\tcase 9:\t\n\t\tif (strncmp(key,\"WRITEABLE\",n)==0)\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tbreak;\n\tcase 10:\n\t\tif (strncmp(key,\"CONTIGUOUS\",n)==0)\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tbreak;\n\tcase 12:\n\t\tif (strncmp(key, \"UPDATEIFCOPY\", n)==0)\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tbreak;\n\t}\n\n fail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return NULL;\n}\n\nstatic int\narrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)\n{ \n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n if (((n==9) && (strncmp(key, \"WRITEABLE\", n)==0)) ||\n\t ((n==1) && (strncmp(key, \"W\", n)==0)))\n return arrayflags_writeable_set(self, item);\n else if (((n==7) && (strncmp(key, \"ALIGNED\", n)==0)) || \n ((n==1) && (strncmp(key, \"A\", n)==0)))\n return arrayflags_aligned_set(self, item);\n else if (((n==12) && (strncmp(key, \"UPDATEIFCOPY\", n)==0)) ||\n ((n==1) && (strncmp(key, \"U\", n)==0)))\n return arrayflags_updateifcopy_set(self, item); \n\nfail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return -1;\n}\n\nstatic char *\n_torf_(int flags, int val)\n{\n if ((flags & val) == val) return \"True\";\n else return \"False\"; \n}\n\nstatic PyObject *\narrayflags_print(PyArrayFlagsObject *self)\n{\n int fl = self->flags;\n \n return PyString_FromFormat(\" %s : %s\\n %s : %s\\n %s : %s\\n\"\\\n \" %s : %s\\n %s : %s\\n %s : %s\",\n \"CONTIGUOUS\", _torf_(fl, CONTIGUOUS),\n \"FORTRAN\", _torf_(fl, FORTRAN),\n \"OWNDATA\", _torf_(fl, OWNDATA),\n \"WRITEABLE\", _torf_(fl, WRITEABLE),\n \"ALIGNED\", _torf_(fl, ALIGNED),\n \"UPDATEIFCOPY\", _torf_(fl, UPDATEIFCOPY));\n}\n\n\nstatic PyMappingMethods arrayflags_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)NULL, \t\t /*mp_length*/\n#else\n (inquiry)NULL, \t\t /*mp_length*/\n#endif\n (binaryfunc)arrayflags_getitem,\t /*mp_subscript*/\n (objobjargproc)arrayflags_setitem, /*mp_ass_subscript*/\n};\n\n\nstatic PyObject *\narrayflags_new(PyTypeObject *self, PyObject *args, PyObject *kwds)\n{\n PyObject *arg=NULL;\n if (!PyArg_UnpackTuple(args, \"flagsobj\", 0, 1, &arg))\n return NULL;\n\n if ((arg != NULL) && PyArray_Check(arg)) {\n return PyArray_NewFlagsObject(arg);\n }\n else {\n return PyArray_NewFlagsObject(NULL);\n }\n}\n\nstatic PyTypeObject PyArrayFlags_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\n \"numpy.flagsobj\",\n sizeof(PyArrayFlagsObject),\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayflags_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t0,\t\t /* tp_compare */\n (reprfunc)arrayflags_print, /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &arrayflags_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arrayflags_print, /* tp_str */\n 0,\t \t /* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t /* tp_iternext */\n 0,\t \t /* tp_methods */\n 0,\t /* tp_members */\n arrayflags_getsets, /* tp_getset */\n 0,\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t /* tp_init */\n 0,\t /* tp_alloc */\n arrayflags_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "methods": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 76, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 65, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 99, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 134, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 207, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 241, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 291, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 319, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 344, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 387, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 427, + "end_line": 509, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 516, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 593, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Size", + "long_name": "PyArray_Size( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 33, + "parameters": [ + "op" + ], + "start_line": 614, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 638, + "end_line": 718, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyObject", + "long_name": "PyArray_CopyObject( PyArrayObject * dest , PyObject * src_object)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 722, + "end_line": 736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDimsAndDataAndDescr", + "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 137, + "parameters": [ + "nd", + "d", + "descr", + "data" + ], + "start_line": 749, + "end_line": 775, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDims", + "long_name": "PyArray_FromDims( int nd , int * d , int type)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "nd", + "d", + "type" + ], + "start_line": 781, + "end_line": 795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewCopy", + "long_name": "PyArray_NewCopy( PyArrayObject * m1 , PyArray_CONDITION fortran)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 804, + "end_line": 825, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 17, + "token_count": 616, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 834, + "end_line": 950, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 966, + "end_line": 969, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Return", + "long_name": "PyArray_Return( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 91, + "parameters": [ + "mp" + ], + "start_line": 979, + "end_line": 1001, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDataType", + "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 9, + "token_count": 229, + "parameters": [ + "type" + ], + "start_line": 1015, + "end_line": 1055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDescrForType", + "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 214, + "parameters": [ + "typenum", + "descr" + ], + "start_line": 1070, + "end_line": 1111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToFile", + "long_name": "PyArray_ToFile( PyArrayObject * self , FILE * fp , char * sep , char * format)", + "filename": "arrayobject.c", + "nloc": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1118, + "end_line": 1209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToList", + "long_name": "PyArray_ToList( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self" + ], + "start_line": 1215, + "end_line": 1244, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToString", + "long_name": "PyArray_ToString( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 170, + "parameters": [ + "self" + ], + "start_line": 1247, + "end_line": 1283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_dealloc", + "long_name": "array_dealloc( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 1292, + "end_line": 1329, + "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": 1336, + "end_line": 1344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_big_item", + "long_name": "array_big_item( PyArrayObject * self , intp i)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 4, + "token_count": 151, + "parameters": [ + "self", + "i" + ], + "start_line": 1347, + "end_line": 1372, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , _int_or_ssize_t i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1375, + "end_line": 1378, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_ass_big_item", + "long_name": "array_ass_big_item( PyArrayObject * self , intp i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1381, + "end_line": 1416, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , _int_or_ssize_t i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1429, + "end_line": 1432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "slice_coerce_index", + "long_name": "slice_coerce_index( PyObject * o , intp * v)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "o", + "v" + ], + "start_line": 1438, + "end_line": 1446, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "slice_GetIndices", + "long_name": "slice_GetIndices( PySliceObject * r , intp length , intp * start , intp * stop , intp * step , intp * slicelength)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 24, + "token_count": 376, + "parameters": [ + "r", + "length", + "start", + "stop", + "step", + "slicelength" + ], + "start_line": 1452, + "end_line": 1502, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "parse_subindex", + "long_name": "parse_subindex( PyObject * op , intp * step_size , intp * n_steps , intp max)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "step_size", + "n_steps", + "max" + ], + "start_line": 1509, + "end_line": 1554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "parse_index", + "long_name": "parse_index( PyArrayObject * self , PyObject * op , intp * dimensions , intp * strides , intp * offset_ptr)", + "filename": "arrayobject.c", + "nloc": 88, + "complexity": 20, + "token_count": 539, + "parameters": [ + "self", + "op", + "dimensions", + "strides", + "offset_ptr" + ], + "start_line": 1558, + "end_line": 1652, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "_swap_axes", + "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1655, + "end_line": 1692, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1704, + "end_line": 1757, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetMap", + "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 53, + "complexity": 12, + "token_count": 382, + "parameters": [ + "mit", + "op" + ], + "start_line": 1760, + "end_line": 1820, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 0 + }, + { + "name": "count_new_axes_0d", + "long_name": "count_new_axes_0d( PyObject * tuple)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 7, + "token_count": 124, + "parameters": [ + "tuple" + ], + "start_line": 1823, + "end_line": 1850, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "add_new_axes_0d", + "long_name": "add_new_axes_0d( PyArrayObject * arr , int newaxis_count)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 121, + "parameters": [ + "arr", + "newaxis_count" + ], + "start_line": 1853, + "end_line": 1872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 1884, + "end_line": 1946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 107, + "complexity": 28, + "token_count": 674, + "parameters": [ + "self", + "op" + ], + "start_line": 1970, + "end_line": 2095, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2110, + "end_line": 2215, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 10, + "token_count": 182, + "parameters": [ + "self", + "op" + ], + "start_line": 2224, + "end_line": 2263, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , _int_or_ssize_t * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2286, + "end_line": 2298, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2301, + "end_line": 2316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2320, + "end_line": 2329, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , _int_or_ssize_t segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2332, + "end_line": 2343, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 1, + "token_count": 182, + "parameters": [ + "dict" + ], + "start_line": 2421, + "end_line": 2458, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 2, + "token_count": 203, + "parameters": [], + "start_line": 2468, + "end_line": 2511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2514, + "end_line": 2537, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericAccumulateFunction", + "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2541, + "end_line": 2564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericBinaryFunction", + "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 44, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2568, + "end_line": 2575, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericUnaryFunction", + "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 38, + "parameters": [ + "m1", + "op" + ], + "start_line": 2578, + "end_line": 2585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceBinaryFunction", + "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 46, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2588, + "end_line": 2596, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceUnaryFunction", + "long_name": "PyArray_GenericInplaceUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 40, + "parameters": [ + "m1", + "op" + ], + "start_line": 2599, + "end_line": 2606, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2609, + "end_line": 2612, + "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": 2615, + "end_line": 2618, + "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": 2621, + "end_line": 2624, + "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": 2627, + "end_line": 2630, + "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": 2633, + "end_line": 2636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power_is_scalar", + "long_name": "array_power_is_scalar( PyObject * o2 , double * exp)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 132, + "parameters": [ + "o2", + "exp" + ], + "start_line": 2643, + "end_line": 2666, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "fast_scalar_power", + "long_name": "fast_scalar_power( PyArrayObject * a1 , PyObject * o2 , int inplace)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 12, + "token_count": 181, + "parameters": [ + "a1", + "o2", + "inplace" + ], + "start_line": 2670, + "end_line": 2704, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2707, + "end_line": 2716, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2720, + "end_line": 2723, + "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": 2726, + "end_line": 2729, + "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": 2732, + "end_line": 2735, + "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": 2738, + "end_line": 2741, + "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": 2744, + "end_line": 2747, + "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": 2750, + "end_line": 2753, + "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": 2756, + "end_line": 2759, + "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": 2762, + "end_line": 2765, + "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": 2768, + "end_line": 2771, + "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": 2774, + "end_line": 2777, + "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": 2780, + "end_line": 2783, + "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": 2786, + "end_line": 2789, + "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": 2792, + "end_line": 2795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2798, + "end_line": 2807, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2810, + "end_line": 2813, + "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": 2816, + "end_line": 2819, + "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": 2822, + "end_line": 2825, + "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": 2828, + "end_line": 2831, + "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": 2834, + "end_line": 2837, + "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": 2840, + "end_line": 2843, + "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": 2846, + "end_line": 2849, + "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": 2852, + "end_line": 2856, + "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": 2859, + "end_line": 2863, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_any_nonzero", + "long_name": "array_any_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 95, + "parameters": [ + "mp" + ], + "start_line": 2867, + "end_line": 2885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_array_nonzero", + "long_name": "_array_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 3, + "token_count": 72, + "parameters": [ + "mp" + ], + "start_line": 2888, + "end_line": 2905, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_divmod", + "long_name": "array_divmod( PyArrayObject * op1 , PyObject * op2)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 89, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2910, + "end_line": 2925, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_int", + "long_name": "array_int( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2929, + "end_line": 2955, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_float", + "long_name": "array_float( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2958, + "end_line": 2983, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_long", + "long_name": "array_long( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 2986, + "end_line": 3008, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_oct", + "long_name": "array_oct( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3011, + "end_line": 3033, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_hex", + "long_name": "array_hex( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3036, + "end_line": 3058, + "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": 3061, + "end_line": 3065, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 12, + "token_count": 268, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 3126, + "end_line": 3167, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 3171, + "end_line": 3193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 3196, + "end_line": 3208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dump_data", + "long_name": "dump_data( char ** string , int * n , int * max_n , char * data , int nd , intp * dimensions , intp * strides , PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 7, + "token_count": 310, + "parameters": [ + "string", + "n", + "max_n", + "data", + "nd", + "dimensions", + "strides", + "self" + ], + "start_line": 3241, + "end_line": 3288, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_repr_builtin", + "long_name": "array_repr_builtin( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 4, + "token_count": 224, + "parameters": [ + "self" + ], + "start_line": 3291, + "end_line": 3327, + "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": 3336, + "end_line": 3353, + "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": 3356, + "end_line": 3368, + "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": 3371, + "end_line": 3383, + "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": 90, + "complexity": 19, + "token_count": 392, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3386, + "end_line": 3492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 171, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3495, + "end_line": 3524, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntTupleFromIntp", + "long_name": "PyArray_IntTupleFromIntp( int len , intp * vals)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 109, + "parameters": [ + "len", + "vals" + ], + "start_line": 3530, + "end_line": 3550, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3558, + "end_line": 3593, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3599, + "end_line": 3618, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 3622, + "end_line": 3640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 3643, + "end_line": 3660, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_IsWriteable", + "long_name": "_IsWriteable( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 107, + "parameters": [ + "ap" + ], + "start_line": 3663, + "end_line": 3696, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_UpdateFlags", + "long_name": "PyArray_UpdateFlags( PyArrayObject * ret , int flagmask)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 11, + "token_count": 157, + "parameters": [ + "ret", + "flagmask" + ], + "start_line": 3703, + "end_line": 3730, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 117, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 3750, + "end_line": 3770, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 3790, + "end_line": 3814, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_New", + "long_name": "PyArray_New( PyTypeObject * subtype , int nd , intp * dims , int type_num , intp * strides , * data , int itemsize , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 4, + "token_count": 128, + "parameters": [ + "subtype", + "nd", + "dims", + "type_num", + "strides", + "data", + "itemsize", + "flags", + "obj" + ], + "start_line": 3820, + "end_line": 3842, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd , int isfortran)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 10, + "token_count": 311, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd", + "isfortran" + ], + "start_line": 3853, + "end_line": 3915, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 132, + "complexity": 29, + "token_count": 785, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3923, + "end_line": 4089, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 167, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape , int refcheck , PyArray_CONDITION fortran)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 17, + "token_count": 524, + "parameters": [ + "self", + "newshape", + "refcheck", + "fortran" + ], + "start_line": 4102, + "end_line": 4205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 104, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillObjectArray", + "long_name": "PyArray_FillObjectArray( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 98, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4211, + "end_line": 4228, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 8, + "token_count": 279, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4232, + "end_line": 4282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 21, + "token_count": 620, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4285, + "end_line": 4416, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 132, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4420, + "end_line": 4428, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ndim_get", + "long_name": "array_ndim_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4434, + "end_line": 4437, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flags_get", + "long_name": "array_flags_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 4440, + "end_line": 4443, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_get", + "long_name": "array_shape_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4446, + "end_line": 4449, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_set", + "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4453, + "end_line": 4482, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "array_strides_get", + "long_name": "array_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4486, + "end_line": 4489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 9, + "token_count": 304, + "parameters": [ + "self", + "obj" + ], + "start_line": 4492, + "end_line": 4546, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4550, + "end_line": 4557, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4560, + "end_line": 4566, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4570, + "end_line": 4576, + "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": 4579, + "end_line": 4593, + "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": 4596, + "end_line": 4640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_itemsize_get", + "long_name": "array_itemsize_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 4644, + "end_line": 4647, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_size_get", + "long_name": "array_size_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4650, + "end_line": 4661, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nbytes_get", + "long_name": "array_nbytes_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4664, + "end_line": 4675, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4681, + "end_line": 4684, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_descr_get", + "long_name": "array_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 4687, + "end_line": 4691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "arg" + ], + "start_line": 4705, + "end_line": 4792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 4795, + "end_line": 4813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_struct_get", + "long_name": "array_struct_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 2, + "token_count": 130, + "parameters": [ + "self" + ], + "start_line": 4816, + "end_line": 4834, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 4837, + "end_line": 4847, + "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": 4851, + "end_line": 4876, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_real_set", + "long_name": "array_real_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 4, + "token_count": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 4880, + "end_line": 4913, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_get", + "long_name": "array_imag_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self" + ], + "start_line": 4916, + "end_line": 4949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 4952, + "end_line": 4989, + "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": 4992, + "end_line": 4995, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flat_set", + "long_name": "array_flat_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 9, + "token_count": 348, + "parameters": [ + "self", + "val" + ], + "start_line": 4998, + "end_line": 5048, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_alloc", + "long_name": "array_alloc( PyTypeObject * type , int nitems)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 1, + "token_count": 39, + "parameters": [ + "type", + "nitems" + ], + "start_line": 5138, + "end_line": 5145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "discover_depth", + "long_name": "discover_depth( PyObject * s , int max , int stop_at_string , int stop_at_tuple)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 19, + "token_count": 243, + "parameters": [ + "s", + "max", + "stop_at_string", + "stop_at_tuple" + ], + "start_line": 5233, + "end_line": 5266, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5269, + "end_line": 5291, + "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": 5298, + "end_line": 5324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_array_small_type", + "long_name": "_array_small_type( PyArray_Descr * chktype , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 169, + "parameters": [ + "chktype", + "mintype" + ], + "start_line": 5330, + "end_line": 5362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_python_scalar_type", + "long_name": "_array_find_python_scalar_type( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 8, + "token_count": 120, + "parameters": [ + "op" + ], + "start_line": 5365, + "end_line": 5388, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 28, + "token_count": 634, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5400, + "end_line": 5530, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "Assign_Array", + "long_name": "Assign_Array( PyArrayObject * self , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 121, + "parameters": [ + "self", + "v" + ], + "start_line": 5533, + "end_line": 5556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 189, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5561, + "end_line": 5599, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 24, + "token_count": 373, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5604, + "end_line": 5671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 68, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 5678, + "end_line": 5687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_bufferedcast", + "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 18, + "token_count": 525, + "parameters": [ + "out", + "in" + ], + "start_line": 5693, + "end_line": 5786, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5796, + "end_line": 5842, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastTo", + "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 241, + "parameters": [ + "out", + "mp" + ], + "start_line": 5852, + "end_line": 5905, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 31, + "token_count": 658, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5910, + "end_line": 6036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 501, + "parameters": [ + "str" + ], + "start_line": 6040, + "end_line": 6148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 6152, + "end_line": 6192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 6196, + "end_line": 6334, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6338, + "end_line": 6381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 21, + "token_count": 410, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6387, + "end_line": 6471, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6476, + "end_line": 6479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ObjectType", + "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 69, + "parameters": [ + "op", + "minimum_type" + ], + "start_line": 6486, + "end_line": 6499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6545, + "end_line": 6561, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 84, + "parameters": [ + "op" + ], + "start_line": 6574, + "end_line": 6590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastSafely", + "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 39, + "token_count": 444, + "parameters": [ + "fromtype", + "totype" + ], + "start_line": 6596, + "end_line": 6684, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 6689, + "end_line": 6717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastScalar", + "long_name": "PyArray_CanCastScalar( PyTypeObject * from , PyTypeObject * to)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 3, + "token_count": 68, + "parameters": [ + "from", + "to" + ], + "start_line": 6723, + "end_line": 6733, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterNew", + "long_name": "PyArray_IterNew( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 269, + "parameters": [ + "obj" + ], + "start_line": 6745, + "end_line": 6783, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterAllButAxis", + "long_name": "PyArray_IterAllButAxis( PyObject * obj , int axis)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 88, + "parameters": [ + "obj", + "axis" + ], + "start_line": 6791, + "end_line": 6808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_next", + "long_name": "arrayiter_next( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 48, + "parameters": [ + "it" + ], + "start_line": 6813, + "end_line": 6823, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_dealloc", + "long_name": "arrayiter_dealloc( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "it" + ], + "start_line": 6826, + "end_line": 6830, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 6833, + "end_line": 6836, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_Bool", + "long_name": "iter_subscript_Bool( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 7, + "token_count": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6840, + "end_line": 6890, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_int", + "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 52, + "complexity": 8, + "token_count": 352, + "parameters": [ + "self", + "ind" + ], + "start_line": 6893, + "end_line": 6947, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 6951, + "end_line": 7084, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 134, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_Bool", + "long_name": "iter_ass_sub_Bool( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7088, + "end_line": 7120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_int", + "long_name": "iter_ass_sub_int( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 8, + "token_count": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7123, + "end_line": 7165, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 7168, + "end_line": 7302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "iter_array", + "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 214, + "parameters": [ + "it", + "op" + ], + "start_line": 7319, + "end_line": 7364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "iter_copy", + "long_name": "iter_copy( PyArrayIterObject * it , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "it", + "args" + ], + "start_line": 7369, + "end_line": 7373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7389, + "end_line": 7404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7469, + "end_line": 7485, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Broadcast", + "long_name": "PyArray_Broadcast( PyArrayMultiIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 13, + "token_count": 464, + "parameters": [ + "mit" + ], + "start_line": 7492, + "end_line": 7561, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterReset", + "long_name": "PyArray_MapIterReset( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7565, + "end_line": 7602, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7608, + "end_line": 7652, + "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": 107, + "complexity": 23, + "token_count": 715, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7670, + "end_line": 7809, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 140, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7815, + "end_line": 7887, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 7890, + "end_line": 8016, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 8020, + "end_line": 8029, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiIterNew", + "long_name": "PyArray_MultiIterNew( int n , ...)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 10, + "token_count": 231, + "parameters": [ + "n" + ], + "start_line": 8100, + "end_line": 8149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_new", + "long_name": "arraymultiter_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 11, + "token_count": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8152, + "end_line": 8197, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_next", + "long_name": "arraymultiter_next( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 111, + "parameters": [ + "multi" + ], + "start_line": 8200, + "end_line": 8219, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_dealloc", + "long_name": "arraymultiter_dealloc( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 41, + "parameters": [ + "multi" + ], + "start_line": 8222, + "end_line": 8229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_size_get", + "long_name": "arraymultiter_size_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8232, + "end_line": 8242, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_index_get", + "long_name": "arraymultiter_index_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8245, + "end_line": 8255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_shape_get", + "long_name": "arraymultiter_shape_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 8258, + "end_line": 8261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_iters_get", + "long_name": "arraymultiter_iters_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 8264, + "end_line": 8276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_reset", + "long_name": "arraymultiter_reset( PyArrayMultiIterObject * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 38, + "parameters": [ + "self", + "args" + ], + "start_line": 8306, + "end_line": 8313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewFromType", + "long_name": "PyArray_DescrNewFromType( int type_num)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 1, + "token_count": 37, + "parameters": [ + "type_num" + ], + "start_line": 8372, + "end_line": 8381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNew", + "long_name": "PyArray_DescrNew( PyArray_Descr * base)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 151, + "parameters": [ + "base" + ], + "start_line": 8399, + "end_line": 8421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_dealloc", + "long_name": "arraydescr_dealloc( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 8427, + "end_line": 8437, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_subdescr_get", + "long_name": "arraydescr_subdescr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 8456, + "end_line": 8464, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8467, + "end_line": 8482, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8485, + "end_line": 8507, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8510, + "end_line": 8518, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8521, + "end_line": 8528, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 8531, + "end_line": 8550, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isbuiltin_get", + "long_name": "arraydescr_isbuiltin_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 8557, + "end_line": 8564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isnative_get", + "long_name": "arraydescr_isnative_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 8567, + "end_line": 8574, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_fields_get", + "long_name": "arraydescr_fields_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 8577, + "end_line": 8584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_new", + "long_name": "arraydescr_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 272, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8632, + "end_line": 8684, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 8690, + "end_line": 8751, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8759, + "end_line": 8801, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewByteorder", + "long_name": "PyArray_DescrNewByteorder( PyArray_Descr * self , char newendian)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 386, + "parameters": [ + "self", + "newendian" + ], + "start_line": 8821, + "end_line": 8887, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_newbyteorder", + "long_name": "arraydescr_newbyteorder( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 47, + "parameters": [ + "self", + "args" + ], + "start_line": 8898, + "end_line": 8906, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_str", + "long_name": "arraydescr_str( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 6, + "token_count": 287, + "parameters": [ + "self" + ], + "start_line": 8921, + "end_line": 8966, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_repr", + "long_name": "arraydescr_repr( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 8969, + "end_line": 8978, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_compare", + "long_name": "arraydescr_compare( PyArray_Descr * self , PyObject * other)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "other" + ], + "start_line": 8981, + "end_line": 8991, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 8998, + "end_line": 9005, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 9008, + "end_line": 9039, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFlagsObject", + "long_name": "PyArray_NewFlagsObject( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 3, + "token_count": 96, + "parameters": [ + "obj" + ], + "start_line": 9117, + "end_line": 9134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_dealloc", + "long_name": "arrayflags_dealloc( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 9137, + "end_line": 9141, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_forc_get", + "long_name": "arrayflags_forc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 9165, + "end_line": 9177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_fnc_get", + "long_name": "arrayflags_fnc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9180, + "end_line": 9192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_farray_get", + "long_name": "arrayflags_farray_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 9195, + "end_line": 9208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_num_get", + "long_name": "arrayflags_num_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 9211, + "end_line": 9214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_updateifcopy_set", + "long_name": "arrayflags_updateifcopy_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9218, + "end_line": 9230, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_aligned_set", + "long_name": "arrayflags_aligned_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9233, + "end_line": 9246, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_writeable_set", + "long_name": "arrayflags_writeable_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9249, + "end_line": 9262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_getitem", + "long_name": "arrayflags_getitem( PyArrayFlagsObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 75, + "complexity": 31, + "token_count": 431, + "parameters": [ + "self", + "ind" + ], + "start_line": 9318, + "end_line": 9393, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_setitem", + "long_name": "arrayflags_setitem( PyArrayFlagsObject * self , PyObject * ind , PyObject * item)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 14, + "token_count": 219, + "parameters": [ + "self", + "ind", + "item" + ], + "start_line": 9396, + "end_line": 9416, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_torf_", + "long_name": "_torf_( int flags , int val)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 27, + "parameters": [ + "flags", + "val" + ], + "start_line": 9419, + "end_line": 9423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_print", + "long_name": "arrayflags_print( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 1, + "token_count": 77, + "parameters": [ + "self" + ], + "start_line": 9426, + "end_line": 9438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_new", + "long_name": "arrayflags_new( PyTypeObject * self , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9453, + "end_line": 9465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 76, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 65, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 99, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 134, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 207, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 241, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 291, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 319, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 344, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 387, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 427, + "end_line": 509, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 516, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 593, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Size", + "long_name": "PyArray_Size( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 33, + "parameters": [ + "op" + ], + "start_line": 614, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 638, + "end_line": 718, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyObject", + "long_name": "PyArray_CopyObject( PyArrayObject * dest , PyObject * src_object)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 722, + "end_line": 736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDimsAndDataAndDescr", + "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 137, + "parameters": [ + "nd", + "d", + "descr", + "data" + ], + "start_line": 749, + "end_line": 775, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDims", + "long_name": "PyArray_FromDims( int nd , int * d , int type)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "nd", + "d", + "type" + ], + "start_line": 781, + "end_line": 795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewCopy", + "long_name": "PyArray_NewCopy( PyArrayObject * m1 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 804, + "end_line": 824, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 17, + "token_count": 616, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 833, + "end_line": 949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 965, + "end_line": 968, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Return", + "long_name": "PyArray_Return( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 91, + "parameters": [ + "mp" + ], + "start_line": 978, + "end_line": 1000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDataType", + "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 9, + "token_count": 229, + "parameters": [ + "type" + ], + "start_line": 1014, + "end_line": 1054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDescrForType", + "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 214, + "parameters": [ + "typenum", + "descr" + ], + "start_line": 1069, + "end_line": 1110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToFile", + "long_name": "PyArray_ToFile( PyArrayObject * self , FILE * fp , char * sep , char * format)", + "filename": "arrayobject.c", + "nloc": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1117, + "end_line": 1208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToList", + "long_name": "PyArray_ToList( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self" + ], + "start_line": 1214, + "end_line": 1243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToString", + "long_name": "PyArray_ToString( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 170, + "parameters": [ + "self" + ], + "start_line": 1246, + "end_line": 1282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_dealloc", + "long_name": "array_dealloc( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 1291, + "end_line": 1328, + "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": 1335, + "end_line": 1343, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_big_item", + "long_name": "array_big_item( PyArrayObject * self , intp i)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 4, + "token_count": 151, + "parameters": [ + "self", + "i" + ], + "start_line": 1346, + "end_line": 1371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , _int_or_ssize_t i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1374, + "end_line": 1377, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_ass_big_item", + "long_name": "array_ass_big_item( PyArrayObject * self , intp i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1380, + "end_line": 1415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , _int_or_ssize_t i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1428, + "end_line": 1431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "slice_coerce_index", + "long_name": "slice_coerce_index( PyObject * o , intp * v)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "o", + "v" + ], + "start_line": 1437, + "end_line": 1445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "slice_GetIndices", + "long_name": "slice_GetIndices( PySliceObject * r , intp length , intp * start , intp * stop , intp * step , intp * slicelength)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 24, + "token_count": 376, + "parameters": [ + "r", + "length", + "start", + "stop", + "step", + "slicelength" + ], + "start_line": 1451, + "end_line": 1501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "parse_subindex", + "long_name": "parse_subindex( PyObject * op , intp * step_size , intp * n_steps , intp max)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "step_size", + "n_steps", + "max" + ], + "start_line": 1508, + "end_line": 1553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "parse_index", + "long_name": "parse_index( PyArrayObject * self , PyObject * op , intp * dimensions , intp * strides , intp * offset_ptr)", + "filename": "arrayobject.c", + "nloc": 88, + "complexity": 20, + "token_count": 539, + "parameters": [ + "self", + "op", + "dimensions", + "strides", + "offset_ptr" + ], + "start_line": 1557, + "end_line": 1651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "_swap_axes", + "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1654, + "end_line": 1691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1703, + "end_line": 1756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetMap", + "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 53, + "complexity": 12, + "token_count": 382, + "parameters": [ + "mit", + "op" + ], + "start_line": 1759, + "end_line": 1819, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 0 + }, + { + "name": "count_new_axes_0d", + "long_name": "count_new_axes_0d( PyObject * tuple)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 7, + "token_count": 124, + "parameters": [ + "tuple" + ], + "start_line": 1822, + "end_line": 1849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "add_new_axes_0d", + "long_name": "add_new_axes_0d( PyArrayObject * arr , int newaxis_count)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 121, + "parameters": [ + "arr", + "newaxis_count" + ], + "start_line": 1852, + "end_line": 1871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 1883, + "end_line": 1945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 107, + "complexity": 28, + "token_count": 674, + "parameters": [ + "self", + "op" + ], + "start_line": 1969, + "end_line": 2094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2109, + "end_line": 2214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 10, + "token_count": 182, + "parameters": [ + "self", + "op" + ], + "start_line": 2223, + "end_line": 2262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , _int_or_ssize_t * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2285, + "end_line": 2297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2300, + "end_line": 2315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2319, + "end_line": 2328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , _int_or_ssize_t segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2331, + "end_line": 2342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 1, + "token_count": 182, + "parameters": [ + "dict" + ], + "start_line": 2420, + "end_line": 2457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 2, + "token_count": 203, + "parameters": [], + "start_line": 2467, + "end_line": 2510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2513, + "end_line": 2536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericAccumulateFunction", + "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2540, + "end_line": 2563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericBinaryFunction", + "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 44, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2567, + "end_line": 2574, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericUnaryFunction", + "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 38, + "parameters": [ + "m1", + "op" + ], + "start_line": 2577, + "end_line": 2584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceBinaryFunction", + "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 46, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2587, + "end_line": 2595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceUnaryFunction", + "long_name": "PyArray_GenericInplaceUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 40, + "parameters": [ + "m1", + "op" + ], + "start_line": 2598, + "end_line": 2605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2608, + "end_line": 2611, + "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": 2614, + "end_line": 2617, + "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": 2620, + "end_line": 2623, + "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": 2626, + "end_line": 2629, + "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": 2632, + "end_line": 2635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power_is_scalar", + "long_name": "array_power_is_scalar( PyObject * o2 , double * exp)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 132, + "parameters": [ + "o2", + "exp" + ], + "start_line": 2642, + "end_line": 2665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "fast_scalar_power", + "long_name": "fast_scalar_power( PyArrayObject * a1 , PyObject * o2 , int inplace)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 12, + "token_count": 181, + "parameters": [ + "a1", + "o2", + "inplace" + ], + "start_line": 2669, + "end_line": 2703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2706, + "end_line": 2715, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2719, + "end_line": 2722, + "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": 2725, + "end_line": 2728, + "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": 2731, + "end_line": 2734, + "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": 2737, + "end_line": 2740, + "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": 2743, + "end_line": 2746, + "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": 2749, + "end_line": 2752, + "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": 2755, + "end_line": 2758, + "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": 2761, + "end_line": 2764, + "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": 2767, + "end_line": 2770, + "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": 2773, + "end_line": 2776, + "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": 2779, + "end_line": 2782, + "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": 2785, + "end_line": 2788, + "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": 2791, + "end_line": 2794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2797, + "end_line": 2806, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2809, + "end_line": 2812, + "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": 2815, + "end_line": 2818, + "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": 2821, + "end_line": 2824, + "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": 2827, + "end_line": 2830, + "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": 2833, + "end_line": 2836, + "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": 2839, + "end_line": 2842, + "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": 2845, + "end_line": 2848, + "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": 2851, + "end_line": 2855, + "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": 2858, + "end_line": 2862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_any_nonzero", + "long_name": "array_any_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 95, + "parameters": [ + "mp" + ], + "start_line": 2866, + "end_line": 2884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_array_nonzero", + "long_name": "_array_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 3, + "token_count": 72, + "parameters": [ + "mp" + ], + "start_line": 2887, + "end_line": 2904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_divmod", + "long_name": "array_divmod( PyArrayObject * op1 , PyObject * op2)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 89, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2909, + "end_line": 2924, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_int", + "long_name": "array_int( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2928, + "end_line": 2954, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_float", + "long_name": "array_float( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 2957, + "end_line": 2982, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_long", + "long_name": "array_long( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 2985, + "end_line": 3007, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_oct", + "long_name": "array_oct( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3010, + "end_line": 3032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_hex", + "long_name": "array_hex( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3035, + "end_line": 3057, + "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": 3060, + "end_line": 3064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 12, + "token_count": 268, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 3125, + "end_line": 3166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 3170, + "end_line": 3192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 3195, + "end_line": 3207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dump_data", + "long_name": "dump_data( char ** string , int * n , int * max_n , char * data , int nd , intp * dimensions , intp * strides , PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 7, + "token_count": 310, + "parameters": [ + "string", + "n", + "max_n", + "data", + "nd", + "dimensions", + "strides", + "self" + ], + "start_line": 3240, + "end_line": 3287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_repr_builtin", + "long_name": "array_repr_builtin( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 4, + "token_count": 224, + "parameters": [ + "self" + ], + "start_line": 3290, + "end_line": 3326, + "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": 3335, + "end_line": 3352, + "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": 3355, + "end_line": 3367, + "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": 3370, + "end_line": 3382, + "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": 90, + "complexity": 19, + "token_count": 392, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3385, + "end_line": 3491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 171, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3494, + "end_line": 3523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntTupleFromIntp", + "long_name": "PyArray_IntTupleFromIntp( int len , intp * vals)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 109, + "parameters": [ + "len", + "vals" + ], + "start_line": 3529, + "end_line": 3549, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3557, + "end_line": 3592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3598, + "end_line": 3617, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 3621, + "end_line": 3639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 3642, + "end_line": 3659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_IsWriteable", + "long_name": "_IsWriteable( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 107, + "parameters": [ + "ap" + ], + "start_line": 3662, + "end_line": 3695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_UpdateFlags", + "long_name": "PyArray_UpdateFlags( PyArrayObject * ret , int flagmask)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 11, + "token_count": 157, + "parameters": [ + "ret", + "flagmask" + ], + "start_line": 3702, + "end_line": 3729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 117, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 3749, + "end_line": 3769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 3789, + "end_line": 3813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_New", + "long_name": "PyArray_New( PyTypeObject * subtype , int nd , intp * dims , int type_num , intp * strides , * data , int itemsize , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 4, + "token_count": 128, + "parameters": [ + "subtype", + "nd", + "dims", + "type_num", + "strides", + "data", + "itemsize", + "flags", + "obj" + ], + "start_line": 3819, + "end_line": 3841, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd , int isfortran)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 10, + "token_count": 311, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd", + "isfortran" + ], + "start_line": 3852, + "end_line": 3914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 132, + "complexity": 29, + "token_count": 785, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3922, + "end_line": 4088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 167, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape , int refcheck)", + "filename": "arrayobject.c", + "nloc": 83, + "complexity": 16, + "token_count": 511, + "parameters": [ + "self", + "newshape", + "refcheck" + ], + "start_line": 4101, + "end_line": 4200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 100, + "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": 4206, + "end_line": 4223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 8, + "token_count": 279, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4227, + "end_line": 4277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 21, + "token_count": 620, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4280, + "end_line": 4411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 132, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4415, + "end_line": 4423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ndim_get", + "long_name": "array_ndim_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4429, + "end_line": 4432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flags_get", + "long_name": "array_flags_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 4435, + "end_line": 4438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_get", + "long_name": "array_shape_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4441, + "end_line": 4444, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_set", + "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4448, + "end_line": 4477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "array_strides_get", + "long_name": "array_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4481, + "end_line": 4484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 9, + "token_count": 304, + "parameters": [ + "self", + "obj" + ], + "start_line": 4487, + "end_line": 4541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4545, + "end_line": 4552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4555, + "end_line": 4561, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4565, + "end_line": 4571, + "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": 4574, + "end_line": 4588, + "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": 4591, + "end_line": 4635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_itemsize_get", + "long_name": "array_itemsize_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 4639, + "end_line": 4642, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_size_get", + "long_name": "array_size_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4645, + "end_line": 4656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nbytes_get", + "long_name": "array_nbytes_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 4659, + "end_line": 4670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4676, + "end_line": 4679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_descr_get", + "long_name": "array_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 4682, + "end_line": 4686, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "arg" + ], + "start_line": 4700, + "end_line": 4787, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 4790, + "end_line": 4808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_struct_get", + "long_name": "array_struct_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 2, + "token_count": 130, + "parameters": [ + "self" + ], + "start_line": 4811, + "end_line": 4829, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 4832, + "end_line": 4842, + "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": 4846, + "end_line": 4871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_real_set", + "long_name": "array_real_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 4, + "token_count": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 4875, + "end_line": 4908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_get", + "long_name": "array_imag_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self" + ], + "start_line": 4911, + "end_line": 4944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 4947, + "end_line": 4984, + "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": 4987, + "end_line": 4990, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flat_set", + "long_name": "array_flat_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 9, + "token_count": 348, + "parameters": [ + "self", + "val" + ], + "start_line": 4993, + "end_line": 5043, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_alloc", + "long_name": "array_alloc( PyTypeObject * type , int nitems)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 1, + "token_count": 39, + "parameters": [ + "type", + "nitems" + ], + "start_line": 5133, + "end_line": 5140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "discover_depth", + "long_name": "discover_depth( PyObject * s , int max , int stop_at_string , int stop_at_tuple)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 19, + "token_count": 243, + "parameters": [ + "s", + "max", + "stop_at_string", + "stop_at_tuple" + ], + "start_line": 5228, + "end_line": 5261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5264, + "end_line": 5286, + "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": 5293, + "end_line": 5319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_array_small_type", + "long_name": "_array_small_type( PyArray_Descr * chktype , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 169, + "parameters": [ + "chktype", + "mintype" + ], + "start_line": 5325, + "end_line": 5357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_python_scalar_type", + "long_name": "_array_find_python_scalar_type( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 8, + "token_count": 120, + "parameters": [ + "op" + ], + "start_line": 5360, + "end_line": 5383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 28, + "token_count": 634, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5395, + "end_line": 5525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "Assign_Array", + "long_name": "Assign_Array( PyArrayObject * self , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 121, + "parameters": [ + "self", + "v" + ], + "start_line": 5528, + "end_line": 5551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 189, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5556, + "end_line": 5594, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 24, + "token_count": 373, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5599, + "end_line": 5666, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 68, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 5673, + "end_line": 5682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_bufferedcast", + "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 18, + "token_count": 525, + "parameters": [ + "out", + "in" + ], + "start_line": 5688, + "end_line": 5781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5791, + "end_line": 5837, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastTo", + "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 241, + "parameters": [ + "out", + "mp" + ], + "start_line": 5847, + "end_line": 5900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 31, + "token_count": 658, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5905, + "end_line": 6031, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 501, + "parameters": [ + "str" + ], + "start_line": 6035, + "end_line": 6143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 6147, + "end_line": 6187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 6191, + "end_line": 6329, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6333, + "end_line": 6376, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 21, + "token_count": 410, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6382, + "end_line": 6466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6471, + "end_line": 6474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ObjectType", + "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 69, + "parameters": [ + "op", + "minimum_type" + ], + "start_line": 6481, + "end_line": 6494, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6540, + "end_line": 6556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 84, + "parameters": [ + "op" + ], + "start_line": 6569, + "end_line": 6585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastSafely", + "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 39, + "token_count": 444, + "parameters": [ + "fromtype", + "totype" + ], + "start_line": 6591, + "end_line": 6679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 6684, + "end_line": 6712, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastScalar", + "long_name": "PyArray_CanCastScalar( PyTypeObject * from , PyTypeObject * to)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 3, + "token_count": 68, + "parameters": [ + "from", + "to" + ], + "start_line": 6718, + "end_line": 6728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterNew", + "long_name": "PyArray_IterNew( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 269, + "parameters": [ + "obj" + ], + "start_line": 6740, + "end_line": 6778, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterAllButAxis", + "long_name": "PyArray_IterAllButAxis( PyObject * obj , int axis)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 88, + "parameters": [ + "obj", + "axis" + ], + "start_line": 6786, + "end_line": 6803, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_next", + "long_name": "arrayiter_next( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 48, + "parameters": [ + "it" + ], + "start_line": 6808, + "end_line": 6818, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_dealloc", + "long_name": "arrayiter_dealloc( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "it" + ], + "start_line": 6821, + "end_line": 6825, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 6828, + "end_line": 6831, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_Bool", + "long_name": "iter_subscript_Bool( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 7, + "token_count": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6835, + "end_line": 6885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_int", + "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 52, + "complexity": 8, + "token_count": 352, + "parameters": [ + "self", + "ind" + ], + "start_line": 6888, + "end_line": 6942, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 6946, + "end_line": 7079, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 134, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_Bool", + "long_name": "iter_ass_sub_Bool( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7083, + "end_line": 7115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_int", + "long_name": "iter_ass_sub_int( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 8, + "token_count": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7118, + "end_line": 7160, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 7163, + "end_line": 7297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "iter_array", + "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 214, + "parameters": [ + "it", + "op" + ], + "start_line": 7314, + "end_line": 7359, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "iter_copy", + "long_name": "iter_copy( PyArrayIterObject * it , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "it", + "args" + ], + "start_line": 7364, + "end_line": 7368, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7384, + "end_line": 7399, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7464, + "end_line": 7480, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Broadcast", + "long_name": "PyArray_Broadcast( PyArrayMultiIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 13, + "token_count": 464, + "parameters": [ + "mit" + ], + "start_line": 7487, + "end_line": 7556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterReset", + "long_name": "PyArray_MapIterReset( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7560, + "end_line": 7597, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7603, + "end_line": 7647, + "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": 107, + "complexity": 23, + "token_count": 715, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7665, + "end_line": 7804, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 140, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7810, + "end_line": 7882, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 7885, + "end_line": 8011, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 8015, + "end_line": 8024, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiIterNew", + "long_name": "PyArray_MultiIterNew( int n , ...)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 10, + "token_count": 231, + "parameters": [ + "n" + ], + "start_line": 8095, + "end_line": 8144, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_new", + "long_name": "arraymultiter_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 11, + "token_count": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8147, + "end_line": 8192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_next", + "long_name": "arraymultiter_next( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 111, + "parameters": [ + "multi" + ], + "start_line": 8195, + "end_line": 8214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_dealloc", + "long_name": "arraymultiter_dealloc( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 41, + "parameters": [ + "multi" + ], + "start_line": 8217, + "end_line": 8224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_size_get", + "long_name": "arraymultiter_size_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8227, + "end_line": 8237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_index_get", + "long_name": "arraymultiter_index_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8240, + "end_line": 8250, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_shape_get", + "long_name": "arraymultiter_shape_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 8253, + "end_line": 8256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_iters_get", + "long_name": "arraymultiter_iters_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 8259, + "end_line": 8271, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_reset", + "long_name": "arraymultiter_reset( PyArrayMultiIterObject * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 38, + "parameters": [ + "self", + "args" + ], + "start_line": 8301, + "end_line": 8308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewFromType", + "long_name": "PyArray_DescrNewFromType( int type_num)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 1, + "token_count": 37, + "parameters": [ + "type_num" + ], + "start_line": 8367, + "end_line": 8376, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNew", + "long_name": "PyArray_DescrNew( PyArray_Descr * base)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 151, + "parameters": [ + "base" + ], + "start_line": 8394, + "end_line": 8416, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_dealloc", + "long_name": "arraydescr_dealloc( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 8422, + "end_line": 8432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_subdescr_get", + "long_name": "arraydescr_subdescr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 8451, + "end_line": 8459, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8462, + "end_line": 8477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8480, + "end_line": 8502, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8505, + "end_line": 8513, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8516, + "end_line": 8523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 8526, + "end_line": 8545, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isbuiltin_get", + "long_name": "arraydescr_isbuiltin_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 8552, + "end_line": 8559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isnative_get", + "long_name": "arraydescr_isnative_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 8562, + "end_line": 8569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_fields_get", + "long_name": "arraydescr_fields_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 8572, + "end_line": 8579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_new", + "long_name": "arraydescr_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 272, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8627, + "end_line": 8679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 8685, + "end_line": 8746, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8754, + "end_line": 8796, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewByteorder", + "long_name": "PyArray_DescrNewByteorder( PyArray_Descr * self , char newendian)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 386, + "parameters": [ + "self", + "newendian" + ], + "start_line": 8816, + "end_line": 8882, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_newbyteorder", + "long_name": "arraydescr_newbyteorder( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 47, + "parameters": [ + "self", + "args" + ], + "start_line": 8893, + "end_line": 8901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_str", + "long_name": "arraydescr_str( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 6, + "token_count": 287, + "parameters": [ + "self" + ], + "start_line": 8916, + "end_line": 8961, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_repr", + "long_name": "arraydescr_repr( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 8964, + "end_line": 8973, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_compare", + "long_name": "arraydescr_compare( PyArray_Descr * self , PyObject * other)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "other" + ], + "start_line": 8976, + "end_line": 8986, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 8993, + "end_line": 9000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 9003, + "end_line": 9034, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFlagsObject", + "long_name": "PyArray_NewFlagsObject( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 3, + "token_count": 96, + "parameters": [ + "obj" + ], + "start_line": 9112, + "end_line": 9129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_dealloc", + "long_name": "arrayflags_dealloc( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 9132, + "end_line": 9136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_forc_get", + "long_name": "arrayflags_forc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 9160, + "end_line": 9172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_fnc_get", + "long_name": "arrayflags_fnc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9175, + "end_line": 9187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_farray_get", + "long_name": "arrayflags_farray_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 9190, + "end_line": 9203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_num_get", + "long_name": "arrayflags_num_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 9206, + "end_line": 9209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_updateifcopy_set", + "long_name": "arrayflags_updateifcopy_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9213, + "end_line": 9225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_aligned_set", + "long_name": "arrayflags_aligned_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9228, + "end_line": 9241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_writeable_set", + "long_name": "arrayflags_writeable_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9244, + "end_line": 9257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_getitem", + "long_name": "arrayflags_getitem( PyArrayFlagsObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 75, + "complexity": 31, + "token_count": 431, + "parameters": [ + "self", + "ind" + ], + "start_line": 9313, + "end_line": 9388, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_setitem", + "long_name": "arrayflags_setitem( PyArrayFlagsObject * self , PyObject * ind , PyObject * item)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 14, + "token_count": 219, + "parameters": [ + "self", + "ind", + "item" + ], + "start_line": 9391, + "end_line": 9411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_torf_", + "long_name": "_torf_( int flags , int val)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 27, + "parameters": [ + "flags", + "val" + ], + "start_line": 9414, + "end_line": 9418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_print", + "long_name": "arrayflags_print( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 1, + "token_count": 77, + "parameters": [ + "self" + ], + "start_line": 9421, + "end_line": 9433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_new", + "long_name": "arrayflags_new( PyTypeObject * self , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9448, + "end_line": 9460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "PyArray_NewCopy", + "long_name": "PyArray_NewCopy( PyArrayObject * m1 , PyArray_CONDITION fortran)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 804, + "end_line": 825, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape , int refcheck)", + "filename": "arrayobject.c", + "nloc": 83, + "complexity": 16, + "token_count": 511, + "parameters": [ + "self", + "newshape", + "refcheck" + ], + "start_line": 4101, + "end_line": 4200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 100, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewCopy", + "long_name": "PyArray_NewCopy( PyArrayObject * m1 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 804, + "end_line": 824, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape , int refcheck , PyArray_CONDITION fortran)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 17, + "token_count": 524, + "parameters": [ + "self", + "newshape", + "refcheck", + "fortran" + ], + "start_line": 4102, + "end_line": 4205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 104, + "top_nesting_level": 0 + } + ], + "nloc": 7555, + "complexity": 1630, + "token_count": 43848, + "diff_parsed": { + "added": [ + "PyArray_NewCopy(PyArrayObject *m1, PyArray_CONDITION fortran)", + "\tif (fortran == PyArray_DONTCARE)", + "\t\tfortran = PyArray_ISFORTRAN(m1);", + "PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck,", + "\t PyArray_CONDITION fortran)", + "\tif (fortran == PyArray_DONTCARE)", + "\t\tfortran = PyArray_FALSE;", + "" + ], + "deleted": [ + "PyArray_NewCopy(PyArrayObject *m1, int fortran)", + "\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);", + "PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck)" + ] + } + }, + { + "old_path": "numpy/core/src/multiarraymodule.c", + "new_path": "numpy/core/src/multiarraymodule.c", + "filename": "multiarraymodule.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -175,20 +175,21 @@ PyArray_View(PyArrayObject *self, PyArray_Descr *type, PyTypeObject *pytype)\n Ravel\n */\n static PyObject *\n-PyArray_Ravel(PyArrayObject *a, int fortran)\n+PyArray_Ravel(PyArrayObject *a, PyArray_CONDITION fortran)\n {\n \tPyArray_Dims newdim = {NULL,1};\n \tintp val[1] = {-1};\n \n-\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n-\n+\tif (fortran == PyArray_DONTCARE) \n+\t\tfortran = PyArray_ISFORTRAN(a);\n+\t\n \tnewdim.ptr = val;\n \tif (!fortran && PyArray_ISCONTIGUOUS(a)) {\n \t\tif (a->nd == 1) {\n \t\t\tPy_INCREF(a);\n \t\t\treturn (PyObject *)a;\n \t\t}\n-\t\treturn PyArray_Newshape(a, &newdim);\n+\t\treturn PyArray_Newshape(a, &newdim, PyArray_FALSE);\n \t}\n \telse\n \t return PyArray_Flatten(a, fortran);\n@@ -312,12 +313,13 @@ PyArray_Round(PyArrayObject *a, int decimals)\n Flatten\n */\n static PyObject *\n-PyArray_Flatten(PyArrayObject *a, int fortran)\n+PyArray_Flatten(PyArrayObject *a, PyArray_CONDITION fortran)\n {\n \tPyObject *ret, *new;\n \tintp size;\n \n-\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n+\tif (fortran == PyArray_DONTCARE) \n+\t\tfortran = PyArray_ISFORTRAN(a);\n \n \tsize = PyArray_SIZE(a);\n \tPy_INCREF(a->descr);\n@@ -364,7 +366,7 @@ PyArray_Reshape(PyArrayObject *self, PyObject *shape)\n PyArray_Dims newdims;\n \n if (!PyArray_IntpConverter(shape, &newdims)) return NULL;\n- ret = PyArray_Newshape(self, &newdims);\n+ ret = PyArray_Newshape(self, &newdims, PyArray_FALSE);\n PyDimMem_FREE(newdims.ptr);\n return ret;\n }\n@@ -400,14 +402,11 @@ _check_ones(PyArrayObject *self, int newnd, intp* newdims, intp *strides)\n \n /* Returns a new array \n with the new shape from the data\n- in the old array\n+ in the old array --- uses C-contiguous perspective.\n */\n \n-/*MULTIARRAY_API\n- New shape for an array\n-*/\n static PyObject * \n-PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims)\n+_old_newshape(PyArrayObject *self, PyArray_Dims *newdims)\n {\n intp i, s_original, i_unknown, s_known;\n intp *dimensions = newdims->ptr;\n@@ -496,6 +495,63 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims)\n return (PyObject *)ret;\n }\n \n+/* Used to reshape a Fortran Array */\n+static 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; ilen == 0) || (PyArray_ISCONTIGUOUS(self) && \\\n+\t\t\t\t (fortran != PyArray_TRUE))) {\n+\t\tret = _old_newshape(self, newshape);\n+\t}\n+\telse if ((fortran == PyArray_TRUE) && PyArray_ISFORTRAN(self)) {\n+\t\ttmp = PyArray_Transpose(self, NULL);\n+\t\tif (tmp == NULL) return NULL;\n+\t\t_reverse_shape(newshape);\n+\t\tret = _old_newshape((PyArrayObject *)tmp, newshape);\n+\t\tPy_DECREF(tmp);\n+\t\tif (ret == NULL) return NULL;\n+\t\ttmp = PyArray_Transpose((PyArrayObject *)ret, NULL);\n+\t\tPy_DECREF(ret);\n+\t\tif (tmp == NULL) return NULL;\n+\t\tret = tmp;\n+\t}\n+\telse {\n+\t\ttmp = PyArray_Copy(self);\n+\t\tif (tmp==NULL) return NULL;\n+\t\tret = _old_newshape((PyArrayObject *)tmp, newshape);\n+\t\tPy_DECREF(tmp);\n+\t}\n+\n+\treturn ret;\n+}\n+\n /* return a new view of the array object with all of its unit-length \n dimensions squeezed out if needed, otherwise\n return the same array.\n@@ -3244,14 +3300,32 @@ PyArray_Converter(PyObject *object, PyObject **address)\n static int\n PyArray_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+\tif (PyObject_IsTrue(object))\n+\t\t*val=TRUE;\n+\telse *val=FALSE;\n+\tif (PyErr_Occurred())\n+\t\treturn PY_FAIL;\n+\treturn PY_SUCCEED;\n }\n \n+/*MULTIARRAY_API\n+ Convert an object to true / false\n+*/\n+static int\n+PyArray_ConditionConverter(PyObject *object, PyArray_CONDITION *val)\n+{ \n+\n+\tif (object == Py_None) \n+\t\t*val = PyArray_DONTCARE;\n+\telse if (PyObject_IsTrue(object))\n+\t\t*val=PyArray_TRUE;\n+\telse *val=PyArray_FALSE;\n+\tif (PyErr_Occurred())\n+\t\treturn PY_FAIL;\n+\treturn PY_SUCCEED;\n+}\n+\n+\n \n /*MULTIARRAY_API\n Typestr converter\n@@ -4370,14 +4444,14 @@ _array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n \tint ndmin=0, nd;\n \tPyArray_Descr *type=NULL;\n \tPyArray_Descr *oldtype=NULL;\n-\tBool fortran=FALSE;\n+\tPyArray_CONDITION fortran=PyArray_DONTCARE;\n \tint flags=0;\n \n \tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&i\", kwd, &op, \n \t\t\t\t\tPyArray_DescrConverter2,\n &type, \n \t\t\t\t\tPyArray_BoolConverter, ©, \n-\t\t\t\t\tPyArray_BoolConverter, &fortran,\n+\t\t\t\t\tPyArray_ConditionConverter, &fortran,\n PyArray_BoolConverter, &subok, \n \t\t\t\t\t&ndmin)) \n \t\treturn NULL;\n@@ -4385,7 +4459,8 @@ _array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n \t/* fast exit if simple call */\n \tif (PyArray_CheckExact(op)) {\n \t\tif (type==NULL) {\n-\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n+\t\t\tif (!copy && (fortran == PyArray_DONTCARE\t\\\n+\t\t\t\t || fortran==PyArray_ISFORTRAN(op))) {\n \t\t\t\tPy_INCREF(op);\n \t\t\t\tret = op;\n \t\t\t\tgoto finish;\n@@ -4399,7 +4474,8 @@ _array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n \t\t/* One more chance */\n \t\toldtype = PyArray_DESCR(op);\n \t\tif (PyArray_EquivTypes(oldtype, type)) {\n-\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n+\t\t\tif (!copy && (fortran == PyArray_DONTCARE || \\\n+\t\t\t\t fortran==PyArray_ISFORTRAN(op))) {\n \t\t\t\tPy_INCREF(op);\n \t\t\t\tret = op;\n \t\t\t\tgoto finish;\n@@ -4419,10 +4495,12 @@ _array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n \tif (copy) {\n \t\tflags = ENSURECOPY;\n \t}\n-\tif (fortran) {\n+\tif (fortran!=PyArray_FALSE && \\\n+\t ((fortran == PyArray_TRUE) ||\n+\t (PyArray_Check(op) && PyArray_ISFORTRAN(op)))) {\n \t\tflags |= FORTRAN;\n \t}\n- if (!subok) {\n+\tif (!subok) {\n flags |= ENSUREARRAY;\n }\n \n@@ -5421,8 +5499,9 @@ array_arange(PyObject *ignored, PyObject *args, PyObject *kws) {\n \treturn PyArray_ArangeObj(o_start, o_stop, o_step, typecode);\n }\n \n-/*MULTIARRAY_API\n- GetNDArrayCVersion\n+/*\n+Included at the very first so not auto-grabbed and thus not \n+labeled.\n */\n static unsigned int\n PyArray_GetNDArrayCVersion(void)\n", + "added_lines": 105, + "deleted_lines": 26, + "source_code": "/*\n Python Multiarray Module -- A useful collection of functions for creating and\n using ndarrays\n\n Original file \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n Modified extensively for numpy in 2005 \n\n Travis E. Oliphant\n Assistant Professor at\n Brigham Young University\n \n*/\n\n/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */\n\n#include \"Python.h\"\n#include \"structmember.h\"\n/*#include \n#include \n*/\n\n#define _MULTIARRAYMODULE\n#include \"numpy/arrayobject.h\"\n\n#define PyAO PyArrayObject\n\nstatic PyObject *typeDict=NULL; /* Must be explicitly loaded */\nstatic PyObject *_numpy_internal=NULL; /* A Python module for callbacks */\nstatic int _multiarray_module_loaded=0;\n\nstatic PyArray_Descr *\n_arraydescr_fromobj(PyObject *obj)\n{\n\tPyObject *dtypedescr;\n\tPyArray_Descr *new;\n\tint ret;\n\t\n\tdtypedescr = PyObject_GetAttrString(obj, \"dtype\");\n\tPyErr_Clear();\n\tif (dtypedescr) {\n\t\tret = PyArray_DescrConverter(dtypedescr, &new);\n\t\tPy_DECREF(dtypedescr);\n\t\tif (ret) return new;\n\t\tPyErr_Clear();\n\t}\n\treturn NULL;\n}\n\n\n/* Including this file is the only way I know how to declare functions\n static in each file, and store the pointers from functions in both\n arrayobject.c and multiarraymodule.c for the C-API \n\n Declarying an external pointer-containing variable in arrayobject.c\n and trying to copy it to PyArray_API, did not work.\n\n Think about two modules with a common api that import each other...\n\n This file would just be the module calls. \n*/\n\n#include \"arrayobject.c\"\n\n\n/* An Error object -- rarely used? */\nstatic PyObject *MultiArrayError;\n\n/*MULTIARRAY_API\n Multiply a List of ints\n*/\nstatic int\nPyArray_MultiplyIntList(register int *l1, register int n) \n{\n\tregister int s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Multiply a List\n*/\nstatic intp \nPyArray_MultiplyList(register intp *l1, register int n) \n{\n\tregister intp s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Produce a pointer into array\n*/\nstatic void *\nPyArray_GetPtr(PyArrayObject *obj, register intp* ind)\n{\n\tregister int n = obj->nd;\n\tregister intp *strides = obj->strides;\n\tregister char *dptr = obj->data;\n\t\n\twhile (n--) dptr += (*strides++) * (*ind++);\n\treturn (void *)dptr;\n}\n\n/*MULTIARRAY_API\n Get axis from an object (possibly None) -- a converter function,\n*/\nstatic int \nPyArray_AxisConverter(PyObject *obj, int *axis)\n{\n\tif (obj == Py_None) {\n\t\t*axis = MAX_DIMS;\n\t}\n\telse {\n\t\t*axis = (int) PyInt_AsLong(obj);\n\t\tif (PyErr_Occurred()) {\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Compare Lists\n*/\nstatic int \nPyArray_CompareLists(intp *l1, intp *l2, int n) \n{\n int i;\n for(i=0;iob_type;\n\t\n\tPy_INCREF(self->descr);\n\tnew = PyArray_NewFromDescr(subtype,\n\t\t\t\t self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides,\n\t\t\t\t self->data,\n\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (new==NULL) return NULL;\n\tPy_INCREF(self);\n PyArray_BASE(new) = (PyObject *)self;\n\t\n\tif (type != NULL) {\n\t\tif (PyObject_SetAttrString(new, \"dtype\",\n\t\t\t\t\t (PyObject *)type) < 0) {\n\t\t\tPy_DECREF(new);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tPy_DECREF(type);\n\t}\n\treturn new;\t\n}\n\n/*MULTIARRAY_API\n Ravel\n*/\nstatic PyObject *\nPyArray_Ravel(PyArrayObject *a, PyArray_CONDITION fortran)\n{\n\tPyArray_Dims newdim = {NULL,1};\n\tintp val[1] = {-1};\n\n\tif (fortran == PyArray_DONTCARE) \n\t\tfortran = PyArray_ISFORTRAN(a);\n\t\n\tnewdim.ptr = val;\n\tif (!fortran && PyArray_ISCONTIGUOUS(a)) {\n\t\tif (a->nd == 1) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\treturn PyArray_Newshape(a, &newdim, PyArray_FALSE);\n\t}\n\telse\n\t return PyArray_Flatten(a, fortran);\n}\n\nstatic double\npower_of_ten(int n)\n{\n\tstatic const double p10[] = {1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8};\n\tdouble ret;\n\tif (n < 9)\n\t\tret = p10[n];\n\telse {\n\t\tret = 1e9;\n\t\twhile (n-- > 9)\n\t\t\tret *= 10.;\n\t}\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Round\n*/\nstatic PyObject *\nPyArray_Round(PyArrayObject *a, int decimals)\n{\n\tif (PyArray_ISCOMPLEX(a)) {\n\t\tPyObject *part;\n\t\tPyObject *round_part;\n\t\tPyObject *new;\n\t\tint res;\n\t\tnew = PyArray_Copy(a);\n\t\tif (new == NULL) return NULL;\n\n\t\t/* new.real = a.real.round(decimals) */\n\t\tpart = PyObject_GetAttrString(new, \"real\");\n\t\tif (part == NULL) {Py_DECREF(new); return NULL;}\n\t\tround_part = PyArray_Round\\\n\t\t\t((PyArrayObject *)PyArray_EnsureAnyArray(part), \n\t\t\t decimals);\n\t\tPy_DECREF(part);\n\t\tif (round_part == NULL) {Py_DECREF(new); return NULL;}\n\t\tres = PyObject_SetAttrString(new, \"real\", round_part);\n\t\tPy_DECREF(round_part);\n\t\tif (res < 0) {Py_DECREF(new); return NULL;}\n\n\t\t/* new.imag = a.imag.round(decimals) */\n\t\tpart = PyObject_GetAttrString(new, \"imag\");\n\t\tif (part == NULL) {Py_DECREF(new); return NULL;}\n\t\tround_part = PyArray_Round\\\n\t\t\t((PyArrayObject *)PyArray_EnsureAnyArray(part), \n\t\t\t decimals);\n\t\tPy_DECREF(part);\n\t\tif (round_part == NULL) {Py_DECREF(new); return NULL;}\n\t\tres = PyObject_SetAttrString(new, \"imag\", round_part);\n\t\tPy_DECREF(round_part);\n\t\tif (res < 0) {Py_DECREF(new); return NULL;}\n\t\treturn new;\n\t}\n\t/* do the most common case first */\n\tif (decimals == 0) {\n\t\tif (PyArray_ISINTEGER(a)) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\treturn PyArray_GenericUnaryFunction((PyAO *)a, n_ops.rint);\n\t}\n\tif (decimals > 0) {\n\t\tPyObject *f, *ret;\n\t\tif (PyArray_ISINTEGER(a)) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\tf = PyFloat_FromDouble(power_of_ten(decimals));\n\t\tif (f==NULL) return NULL;\n\t\tret = PyNumber_Multiply((PyObject *)a, f);\n\t\tif (ret==NULL) {Py_DECREF(f); return NULL;}\n\t\tif (PyArray_IsScalar(ret, Generic)) {\n\t\t\t/* array scalars cannot be modified inplace */\n\t\t\tPyObject *tmp;\n\t\t\ttmp = PyObject_CallFunction(n_ops.rint, \"O\", ret);\n\t\t\tPy_DECREF(ret);\n\t\t\tret = PyObject_CallFunction(n_ops.divide, \"OO\", \n\t\t\t\t\t\t tmp, f);\n\t\t\tPy_DECREF(tmp);\n\t\t} else {\n\t\t\tPyObject_CallFunction(n_ops.rint, \"OO\", ret, ret);\n\t\t\tPyObject_CallFunction(n_ops.divide, \"OOO\", ret, \n\t\t\t\t\t f, ret);\n\t\t}\n\t\tPy_DECREF(f);\n\t\treturn ret;\n\t} \n\telse {\n\t\t/* remaining case: decimals < 0 */\n\t\tPyObject *f, *ret;\n\t\tf = PyFloat_FromDouble(power_of_ten(-decimals));\n\t\tif (f==NULL) return NULL;\n\t\tret = PyNumber_Divide((PyObject *)a, f);\n\t\tif (ret==NULL) {Py_DECREF(f); return NULL;}\n\t\tif (PyArray_IsScalar(ret, Generic)) {\n\t\t\t/* array scalars cannot be modified inplace */\n\t\t\tPyObject *tmp;\n\t\t\ttmp = PyObject_CallFunction(n_ops.rint, \"O\", ret);\n\t\t\tPy_DECREF(ret);\n\t\t\tret = PyObject_CallFunction(n_ops.multiply, \"OO\", \n\t\t\t\t\t\t tmp, f);\n\t\t\tPy_DECREF(tmp);\n\t\t} else {\n\t\t\tPyObject_CallFunction(n_ops.rint, \"OO\", ret, ret);\n\t\t\tPyObject_CallFunction(n_ops.multiply, \"OOO\", ret, \n\t\t\t\t\t f, ret);\n\t\t}\n\t\tPy_DECREF(f);\n\t\treturn ret;\n\t}\n}\n\n\n/*MULTIARRAY_API\n Flatten\n*/\nstatic PyObject *\nPyArray_Flatten(PyArrayObject *a, PyArray_CONDITION fortran)\n{\n\tPyObject *ret, *new;\n\tintp size;\n\n\tif (fortran == PyArray_DONTCARE) \n\t\tfortran = PyArray_ISFORTRAN(a);\n\n\tsize = PyArray_SIZE(a);\n\tPy_INCREF(a->descr);\n\tret = PyArray_NewFromDescr(a->ob_type,\n\t\t\t\t a->descr,\n\t\t\t\t 1, &size,\n\t\t\t\t NULL,\n\t\t\t\t NULL,\n\t\t\t\t 0, (PyObject *)a);\n\t\n\tif (ret== NULL) return NULL;\n\tif (fortran) {\n\t\tnew = PyArray_Transpose(a, NULL);\n\t\tif (new == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tPy_INCREF(a);\n\t\tnew = (PyObject *)a;\n\t}\n\tif (PyArray_CopyInto((PyArrayObject *)ret, (PyArrayObject *)new) < 0) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn NULL;\n\t}\n\tPy_DECREF(new);\n\treturn ret;\n}\n\n\n/* For back-ward compatability *\n\n/ * Not recommended */\n\n/*MULTIARRAY_API\n Reshape an array\n*/\nstatic PyObject *\nPyArray_Reshape(PyArrayObject *self, PyObject *shape) \n{\n PyObject *ret;\n PyArray_Dims newdims;\n\n if (!PyArray_IntpConverter(shape, &newdims)) return NULL;\n ret = PyArray_Newshape(self, &newdims, PyArray_FALSE);\n PyDimMem_FREE(newdims.ptr);\n return ret;\n}\n\nstatic int\n_check_ones(PyArrayObject *self, int newnd, intp* newdims, intp *strides)\n{\n\tint nd;\n\tintp *dims;\n\tBool done=FALSE;\n\tint j, k;\n\n\tnd = self->nd;\n\tdims = self->dimensions;\n\n\tfor (k=0, j=0; !done && (jstrides[j];\n\t\t\tj++; k++;\n\t\t}\n\t\telse if ((kptr;\n PyArrayObject *ret;\n\tchar msg[] = \"total size of new array must be unchanged\";\n\tint n = newdims->len;\n Bool same;\n\tintp *strides = NULL;\n\tintp newstrides[MAX_DIMS];\n\n /* Quick check to make sure anything needs to be done */\n if (n == self->nd) {\n same = TRUE;\n i=0;\n while(same && i= 0) {\n\t\t\tif ((s_known == 0) || (s_original % s_known != 0)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdimensions[i_unknown] = s_original/s_known;\n\t\t} else {\n\t\t\tif (s_original != s_known) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t}\n \n\tPy_INCREF(self->descr);\n\tret = (PyAO *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t self->descr,\n\t\t\t\t\t n, dimensions,\n\t\t\t\t\t strides,\n\t\t\t\t\t self->data,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (ret== NULL) return NULL;\n\t\n Py_INCREF(self);\n ret->base = (PyObject *)self;\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\n\t\n return (PyObject *)ret;\n}\n\n/* 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; ilen == 0) || (PyArray_ISCONTIGUOUS(self) && \\\n\t\t\t\t (fortran != PyArray_TRUE))) {\n\t\tret = _old_newshape(self, newshape);\n\t}\n\telse if ((fortran == PyArray_TRUE) && PyArray_ISFORTRAN(self)) {\n\t\ttmp = PyArray_Transpose(self, NULL);\n\t\tif (tmp == NULL) return NULL;\n\t\t_reverse_shape(newshape);\n\t\tret = _old_newshape((PyArrayObject *)tmp, newshape);\n\t\tPy_DECREF(tmp);\n\t\tif (ret == NULL) return NULL;\n\t\ttmp = PyArray_Transpose((PyArrayObject *)ret, NULL);\n\t\tPy_DECREF(ret);\n\t\tif (tmp == NULL) return NULL;\n\t\tret = tmp;\n\t}\n\telse {\n\t\ttmp = PyArray_Copy(self);\n\t\tif (tmp==NULL) return NULL;\n\t\tret = _old_newshape((PyArrayObject *)tmp, newshape);\n\t\tPy_DECREF(tmp);\n\t}\n\n\treturn ret;\n}\n\n/* return a new view of the array object with all of its unit-length \n dimensions squeezed out if needed, otherwise\n return the same array.\n */\n\n/*MULTIARRAY_API*/\nstatic PyObject *\nPyArray_Squeeze(PyArrayObject *self)\n{\n\tint nd = self->nd;\n\tint newnd = nd;\n\tintp dimensions[MAX_DIMS];\n\tintp strides[MAX_DIMS];\n\tint i,j;\n\tPyObject *ret;\n\n\tif (nd == 0) {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\tfor (j=0, i=0; idimensions[i] == 1) {\n\t\t\tnewnd -= 1;\n\t\t}\n\t\telse {\n\t\t\tdimensions[j] = self->dimensions[i];\n\t\t\tstrides[j++] = self->strides[i];\n\t\t}\n\t}\n\t\n\tPy_INCREF(self->descr);\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t self->descr,\n\t\t\t\t newnd, dimensions, \n\t\t\t\t strides, self->data, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPyArray_FLAGS(ret) &= ~OWN_DATA;\n\tPyArray_BASE(ret) = (PyObject *)self;\n\tPy_INCREF(self);\n\treturn (PyObject *)ret;\n}\n\n\n/*MULTIARRAY_API\n Mean\n*/\nstatic PyObject *\nPyArray_Mean(PyArrayObject *self, int axis, int rtype)\n{\n\tPyObject *obj1=NULL, *obj2=NULL;\n\tPyObject *new, *ret;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\n\tobj1 = PyArray_GenericReduceFunction((PyAO *)new, n_ops.add, axis,\n\t\t\t\t\t rtype);\n\tobj2 = PyFloat_FromDouble((double) PyArray_DIM(new,axis));\n Py_DECREF(new);\n\tif (obj1 == NULL || obj2 == NULL) {\n\t\tPy_XDECREF(obj1);\n\t\tPy_XDECREF(obj2);\n\t\treturn NULL;\n\t}\n\n\tret = PyNumber_Divide(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n}\n\n/* Set variance to 1 to by-pass square-root calculation and return variance */\n/*MULTIARRAY_API\n Std\n*/\nstatic PyObject *\nPyArray_Std(PyArrayObject *self, int axis, int rtype, int variance)\n{\n\tPyObject *obj1=NULL, *obj2=NULL, *new=NULL;\n\tPyObject *ret=NULL, *newshape=NULL;\n\tint i, n;\n\tintp val;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\t\n\t/* Compute and reshape mean */\n\tobj1 = PyArray_EnsureArray(PyArray_Mean((PyAO *)new, axis, rtype));\n\tif (obj1 == NULL) {Py_DECREF(new); return NULL;} \n\tn = PyArray_NDIM(new);\n\tnewshape = PyTuple_New(n);\n\tif (newshape == NULL) {Py_DECREF(obj1); Py_DECREF(new); return NULL;}\n\tfor (i=0; ind != 1) {\n Py_DECREF(cond);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"condition must be 1-d array\");\n return NULL;\n }\n\n res = PyArray_Nonzero(cond);\n Py_DECREF(cond);\n\tret = PyArray_Take(self, res, axis);\n\tPy_DECREF(res);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Nonzero\n*/\nstatic PyObject *\nPyArray_Nonzero(PyArrayObject *self)\n{\n int n=self->nd, j;\n\tintp count=0, i, size;\n\tPyArrayIterObject *it=NULL;\n\tPyObject *ret=NULL, *item;\n\tintp *dptr[MAX_DIMS];\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (it==NULL) return NULL;\n\n\tsize = it->size;\n\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) count++;\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\n\tPyArray_ITER_RESET(it);\n\tif (n==1) {\n\t\tret = PyArray_New(self->ob_type, 1, &count, PyArray_INTP, \n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)self);\n\t\tif (ret == NULL) goto fail;\n\t\tdptr[0] = (intp *)PyArray_DATA(ret);\n\t\t\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\t*(dptr[0])++ = i;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\t\t\n\t}\n\telse {\n\t\tret = PyTuple_New(n);\n\t\tfor (j=0; job_type, 1, &count, \n\t\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0,\n\t\t\t\t\t (PyObject *)self);\n\t\t\tif (item == NULL) goto fail;\n\t\t\tPyTuple_SET_ITEM(ret, j, item);\n\t\t\tdptr[j] = (intp *)PyArray_DATA(item);\n\t\t}\n\t\t\n\t\t/* reset contiguous so that coordinates gets updated */\n\t\tit->contiguous = 0;\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\tfor (j=0; jcoordinates[j];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\n\n\tPy_DECREF(it);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(ret);\n\tPy_XDECREF(it);\n\treturn NULL;\n \n}\n\n/*MULTIARRAY_API\n Clip\n*/\nstatic PyObject *\nPyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max)\n{\n\tPyObject *selector=NULL, *newtup=NULL, *ret=NULL;\n\tPyObject *res1=NULL, *res2=NULL, *res3=NULL;\n\tPyObject *two;\n\n\ttwo = PyInt_FromLong((long)2);\n\tres1 = PyArray_GenericBinaryFunction(self, max, n_ops.greater);\n\tres2 = PyArray_GenericBinaryFunction(self, min, n_ops.less);\n\tif ((res1 == NULL) || (res2 == NULL)) {\n\t\tPy_DECREF(two);\n\t\tPy_XDECREF(res1);\n\t\tPy_XDECREF(res2);\n\t}\n\tres3 = PyNumber_Multiply(two, res1);\n\tPy_DECREF(two); \n\tPy_DECREF(res1); \n\tif (res3 == NULL) return NULL;\n\n\tselector = PyArray_EnsureArray(PyNumber_Add(res2, res3));\n\tPy_DECREF(res2);\n\tPy_DECREF(res3);\n\tif (selector == NULL) return NULL;\n\n\tnewtup = Py_BuildValue(\"(OOO)\", (PyObject *)self, min, max);\n\tif (newtup == NULL) {Py_DECREF(selector); return NULL;}\n\tret = PyArray_Choose((PyAO *)selector, newtup);\n\tPy_DECREF(selector);\n\tPy_DECREF(newtup);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Conjugate\n*/\nstatic PyObject *\nPyArray_Conjugate(PyArrayObject *self)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyObject *new;\n\t\tintp size, i;\n\t\t/* Make a copy */\n\t\tnew = PyArray_NewCopy(self, -1);\n\t\tif (new==NULL) return NULL;\n\t\tsize = PyArray_SIZE(new);\n\t\tif (self->descr->type_num == PyArray_CFLOAT) {\n\t\t\tcfloat *dptr = (cfloat *) PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CDOUBLE) {\n\t\t\tcdouble *dptr = (cdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CLONGDOUBLE) {\n\t\t\tclongdouble *dptr = (clongdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\t\t\t\n\t\t}\t\t\n\t\treturn new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *) self;\n\t}\n}\n\n/*MULTIARRAY_API\n Trace\n*/\nstatic PyObject *\nPyArray_Trace(PyArrayObject *self, int offset, int axis1, int axis2, \nint rtype)\n{\n\tPyObject *diag=NULL, *ret=NULL;\n\n\tdiag = PyArray_Diagonal(self, offset, axis1, axis2);\n\tif (diag == NULL) return NULL;\n\tret = PyArray_GenericReduceFunction((PyAO *)diag, n_ops.add, -1, rtype);\n\tPy_DECREF(diag);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Diagonal\n*/\nstatic PyObject *\nPyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)\n{\n\tint n = self->nd;\n\tPyObject *new;\n\tPyArray_Dims newaxes;\n\tintp dims[MAX_DIMS];\n\tint i, pos;\t\n\n\tnewaxes.ptr = dims;\n\tif (n < 2) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"array.ndim must be >= 2\");\n\t\treturn NULL;\n\t}\n\tif (axis1 < 0) axis1 += n;\n\tif (axis2 < 0) axis2 += n;\n\tif ((axis1 == axis2) || (axis1 < 0) || (axis1 >= n) ||\t\\\n\t (axis2 < 0) || (axis2 >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \"axis1(=%d) and axis2(=%d) \"\\\n\t\t\t \"must be different and within range (nd=%d)\",\n\t\t\t axis1, axis2, n);\n\t\treturn NULL;\n\t}\n \n\tnewaxes.len = n;\n\t/* insert at the end */\n\tnewaxes.ptr[n-2] = axis1;\n\tnewaxes.ptr[n-1] = axis2;\n\tpos = 0;\n\tfor (i=0; idimensions[0];\n\t\tn2 = self->dimensions[1];\n\t\tstep = n2+1;\n\t\tif (offset < 0) {\n\t\t\tstart = -n2 * offset;\n\t\t\tstop = MIN(n2, n1+offset)*(n2+1) - n2*offset;\n\t\t}\n\t\telse {\n\t\t\tstart = offset;\n\t\t\tstop = MIN(n1, n2-offset)*(n2+1) + offset;\n\t\t}\n\t\t\n\t\t/* count = ceil((stop-start)/step) */\n\t\tcount = ((stop-start) / step) + (((stop-start) % step) != 0);\n\t\t\t\n\t\tindices = PyArray_New(&PyArray_Type, 1, &count, \n\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0, NULL);\n\t\tif (indices == NULL) {\n\t\t\tPy_DECREF(self); return NULL;\n\t\t}\n\t\tdptr = (intp *)PyArray_DATA(indices);\n\t\tfor (n1=start; n1descr;\n\n\t\tmydiagonal = PyList_New(0);\n\t\tif (mydiagonal == NULL) {Py_DECREF(self); return NULL;}\n\t\tn1 = self->dimensions[0];\n\t\tfor (i=0; i 3)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"C arrays of only 1-3 dimensions available\");\n\t\tPy_XDECREF(typedescr);\n\t\treturn -1;\n\t}\n\tif ((ap = (PyArrayObject*)PyArray_FromAny(*op, typedescr, nd, nd,\n\t\t\t\t\t\t CARRAY_FLAGS, NULL)) == NULL)\n\t\treturn -1;\n\tswitch(nd) {\n\tcase 1:\n\t\t*((char **)ptr) = ap->data;\n\t\tbreak;\n\tcase 2:\n\t\tn = ap->dimensions[0];\n\t\tptr2 = (char **)_pya_malloc(n * sizeof(char *));\n\t\tif (!ptr2) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0];\n\t\t}\n\t\t*((char ***)ptr) = ptr2;\n\t\tbreak;\t\t\n\tcase 3:\n\t\tn = ap->dimensions[0];\n\t\tm = ap->dimensions[1];\n\t\tptr3 = (char ***)_pya_malloc(n*(m+1) * sizeof(char *));\n\t\tif (!ptr3) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0] + \\\n\t\t\t\t\tj*ap->strides[1];\n\t\t\t}\n\t\t}\n\t\t*((char ****)ptr) = ptr3;\n\t}\n\tmemcpy(dims, ap->dimensions, nd*sizeof(intp));\n\t*op = (PyObject *)ap;\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_MemoryError, \"no memory\");\n\treturn -1;\n}\n\n/* Deprecated --- Use PyArray_AsCArray instead */\n\n/*MULTIARRAY_API\n Convert to a 1D C-array\n*/\nstatic int \nPyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) \n{\n\tintp newd1;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, descr) == -1)\n\t\treturn -1;\t\n\t*d1 = (int) newd1;\n\treturn 0;\n}\n\n/*MULTIARRAY_API\n Convert to a 2D C-array\n*/\nstatic int \nPyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) \n{\n\tintp newdims[2];\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, newdims, 2, descr) == -1)\n\t\treturn -1;\n\n\t*d1 = (int ) newdims[0];\n\t*d2 = (int ) newdims[1];\n return 0;\n}\n\n/* End Deprecated */\n\n/*MULTIARRAY_API\n Free pointers created if As2D is called\n*/\nstatic int \nPyArray_Free(PyObject *op, void *ptr) \n{\n PyArrayObject *ap = (PyArrayObject *)op;\n\t\n if ((ap->nd < 1) || (ap->nd > 3)) \n\t\treturn -1;\n if (ap->nd >= 2) {\n\t\t_pya_free(ptr);\n }\n Py_DECREF(ap);\n return 0;\n}\n\n\nstatic PyObject *\n_swap_and_concat(PyObject *op, int axis, int n)\n{\n\tPyObject *newtup=NULL;\n\tPyObject *otmp, *arr;\n\tint i;\n\n\tnewtup = PyTuple_New(n);\n\tif (newtup==NULL) return NULL;\n\tfor (i=0; i= MAX_DIMS) {\n\t\t\totmp = PyArray_Ravel(mps[i],0);\n\t\t\tPy_DECREF(mps[i]);\n\t\t\tmps[i] = (PyArrayObject *)otmp;\n\t\t}\n\t\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\n\t\t}\n\t}\n\t\n\tnew_dim = 0;\n\tfor(i=0; ind;\n\t\telse {\n\t\t\tif (nd != mps[i]->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"arrays must have same \"\\\n\t\t\t\t\t\t\"number of dimensions\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CompareLists(mps[0]->dimensions+1, \n\t\t\t\t\t\t mps[i]->dimensions+1, \n\t\t\t\t\t\t nd-1)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"array dimensions must \"\\\n\t\t\t\t\t\t\"agree except for d_0\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (nd == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"0-d arrays can't be concatenated\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnew_dim += mps[i]->dimensions[0];\n\t}\n\t\n\ttmp = mps[0]->dimensions[0];\n\tmps[0]->dimensions[0] = new_dim;\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(subtype, \n\t\t\t\t\t\t mps[0]->descr, nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ret);\n\tmps[0]->dimensions[0] = tmp;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tdata = ret->data;\n\tfor(i=0; idata, numbytes);\n\t\tdata += numbytes;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; ind;\n\tif (n <= 1) {\n\t\tPy_INCREF(ap);\n\t\treturn (PyObject *)ap;\n\t}\n\n\tif (a1 < 0) a1 += n;\n\tif (a2 < 0) a2 += n;\n\tif ((a1 < 0) || (a1 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis1 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tif ((a2 < 0) || (a2 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis2 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tnew_axes.ptr = dims;\n\tnew_axes.len = n;\n\n\tfor (i=0; ind;\n\t\tfor(i=0; ilen;\n\t\taxes = permute->ptr;\n\t\tif (n > ap->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many axes for this array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tfor(i=0; ind+axis;\n\t\t\tif (axis < 0 || axis >= ap->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"invalid axis for this array\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tpermutation[i] = axis;\n\t\t}\n\t}\n\t\n\t/* this allocates memory for dimensions and strides (but fills them\n\t incorrectly), sets up descr, and points data at ap->data. */\n\tPy_INCREF(ap->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t ap->descr, \n\t\t\t\t n, permutation, \n\t\t\t\t NULL, ap->data, ap->flags,\n\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) return NULL;\n\t\n\t/* point at true owner of memory: */\n\tret->base = (PyObject *)ap;\n\tPy_INCREF(ap);\n\t\n\tfor(i=0; idimensions[i] = ap->dimensions[permutation[i]];\n\t\tret->strides[i] = ap->strides[permutation[i]];\n\t}\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\t\n\n\treturn (PyObject *)ret;\t\n}\n\n/*MULTIARRAY_API\n Repeat the array.\n*/\nstatic PyObject *\nPyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis)\n{\n\tintp *counts;\n\tintp n, n_outer, i, j, k, chunk, total;\n\tintp tmp;\n\tint nd;\n\tPyArrayObject *repeats=NULL;\n\tPyObject *ap=NULL;\n\tPyArrayObject *ret=NULL;\n\tchar *new_data, *old_data;\n\n\trepeats = (PyAO *)PyArray_ContiguousFromAny(op, PyArray_INTP, 0, 1);\n\tif (repeats == NULL) return NULL;\n\tnd = repeats->nd;\n\tcounts = (intp *)repeats->data;\n\n\tif ((ap=_check_axis(aop, &axis, CARRAY_FLAGS))==NULL) {\n\t\tPy_DECREF(repeats);\n\t\treturn NULL;\n\t}\n\n\taop = (PyAO *)ap;\n\n\tif (nd == 1)\n\t\tn = repeats->dimensions[0];\n\telse /* nd == 0 */\n\t\tn = aop->dimensions[axis];\n\n\tif (aop->dimensions[axis] != n) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"a.shape[axis] != len(repeats)\");\n\t\tgoto fail;\n\t}\n\n\t\n\tif (nd == 0) \n\t\ttotal = counts[0]*n;\n\telse {\n\t\t\n\t\ttotal = 0;\n\t\tfor(j=0; jdimensions[axis] = total;\n\tPy_INCREF(aop->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(aop->ob_type, \n\t\t\t\t\t\t aop->descr,\n\t\t\t\t\t\t aop->nd,\n\t\t\t\t\t\t aop->dimensions,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)aop);\n\taop->dimensions[axis] = n;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tnew_data = ret->data;\n\told_data = aop->data;\n\t\n\tchunk = aop->descr->elsize;\n\tfor(i=axis+1; ind; i++) {\n\t\tchunk *= aop->dimensions[i];\n\t}\n\t\n\tn_outer = 1;\n\tfor(i=0; idimensions[i];\n\n\tfor(i=0; idescr->elsize;\n\tbyteorder = arr->descr->byteorder;\n\tptr = arr->data;\n\tif (elsize > 1 && \\\n\t (byteorder == PyArray_LITTLE ||\t\\\n\t (byteorder == PyArray_NATIVE &&\n\t PyArray_ISNBO(PyArray_LITTLE))))\n\t\tptr += elsize-1;\n\t\n\treturn ((*ptr & bitmask) != 0);\t\n}\n\n\n/*OBJECT_API*/\nstatic PyArray_SCALARKIND\nPyArray_ScalarKind(int typenum, PyArrayObject **arr) \n{\n\tif (PyTypeNum_ISSIGNED(typenum)) {\n\t\tif (arr && _signbit_set(*arr)) return PyArray_INTNEG_SCALAR;\n\t\telse return PyArray_INTPOS_SCALAR;\n\t}\n\tif (PyTypeNum_ISFLOAT(typenum)) return PyArray_FLOAT_SCALAR;\n\tif (PyTypeNum_ISUNSIGNED(typenum)) return PyArray_INTPOS_SCALAR;\n\tif (PyTypeNum_ISCOMPLEX(typenum)) return PyArray_COMPLEX_SCALAR;\n\tif (PyTypeNum_ISBOOL(typenum)) return PyArray_BOOL_SCALAR;\n\n\treturn PyArray_OBJECT_SCALAR;\n}\n\n/*OBJECT_API*/\nstatic int \nPyArray_CanCoerceScalar(char thistype, char neededtype, \n\t\t\tPyArray_SCALARKIND scalar) \n{\n\n\tswitch(scalar) {\n\tcase PyArray_NOSCALAR:\n\tcase PyArray_BOOL_SCALAR:\n\tcase PyArray_OBJECT_SCALAR:\n\t\treturn PyArray_CanCastSafely(thistype, neededtype);\n\tcase PyArray_INTPOS_SCALAR:\n\t\treturn (neededtype >= PyArray_UBYTE);\n\tcase PyArray_INTNEG_SCALAR:\n\t\treturn (neededtype >= PyArray_BYTE) &&\t\t\\\n\t\t\t!(PyTypeNum_ISUNSIGNED(neededtype));\n\tcase PyArray_FLOAT_SCALAR:\n\t\treturn (neededtype >= PyArray_FLOAT);\n\tcase PyArray_COMPLEX_SCALAR:\n\t\treturn (neededtype >= PyArray_CFLOAT);\n\t}\n\tfprintf(stderr, \"\\n**Error** coerce fall through: %d %d %d\\n\\n\", \n\t\tthistype, neededtype, scalar);\n\treturn 1; /* should never get here... */ \n}\n\n\n/* This needs to change to allow scalars of a different \"kind\" to alter the input type\n */\n\n/*OBJECT_API*/\nstatic PyArrayObject **\nPyArray_ConvertToCommonType(PyObject *op, int *retn)\n{\n\tint i, n, allscalars=0; \n\tPyArrayObject **mps=NULL;\n\tPyObject *otmp;\n\tPyArray_Descr *intype=NULL, *stype=NULL;\n\tPyArray_Descr *newtype=NULL;\n\tchar scalarkind;\n\n\t\n\t*retn = n = PySequence_Length(op);\n\tif (PyErr_Occurred()) {*retn = 0; return NULL;}\n\t\n\tmps = (PyArrayObject **)PyDataMem_NEW(n*sizeof(PyArrayObject *));\n\tif (mps == NULL) {\n\t\t*retn = 0;\n\t\treturn (void*)PyErr_NoMemory();\n\t}\n\t\n\tfor(i=0; itype_num, NULL);\n\t\t\tif (intype && !PyArray_CanCoerceScalar(newtype->type_num,\n\t\t\t\t\t\t\t intype->type_num, \n\t\t\t\t\t\t\t scalarkind)) {\n\t\t\t\tPy_XDECREF(intype);\n\t\t\t\tintype = stype;\n\t\t\t}\n\t\t\tmps[i] = (PyArrayObject *)Py_None;\n\t\t\tPy_INCREF(Py_None);\n\t\t}\n\t\tPy_XDECREF(otmp);\n\t}\n\tif (intype==NULL) { /* all scalars */\n\t\tallscalars = 1;\n\t\tintype = stype;\n\t\tPy_INCREF(intype);\n\t\tfor (i=0; ind < mps[i]->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many dimensions\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (!PyArray_CompareLists(ap->dimensions+(ap->nd-mps[i]->nd),\n\t\t\t\t mps[i]->dimensions, mps[i]->nd)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"array dimensions must agree\");\n\t\t\tgoto fail;\n\t\t}\n\t\tsizes[i] = PyArray_NBYTES(mps[i]);\n\t}\n\t\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t\t\t mps[0]->descr,\n\t\t\t\t\t\t ap->nd,\n\t\t\t\t\t\t ap->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\telsize = ret->descr->elsize;\n\tm = PyArray_SIZE(ret);\n\tself_data = (intp *)ap->data;\n\tret_data = ret->data;\n\t\n\tfor (i=0; i= n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid entry in choice array\");\n\t\t\tgoto fail;\n\t\t}\n\t\toffset = i*elsize;\n\t\tif (offset >= sizes[mi]) {offset = offset % sizes[mi]; }\n\t\tmemmove(ret_data, mps[mi]->data+offset, elsize);\n\t\tret_data += elsize; self_data++;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; idescr->f->sort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize);\n\n\tif (needcopy) {\n\t\tchar *buffer;\n\t\tbuffer = PyDataMem_NEW(N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(buffer, (intp) elsize, it->dataptr, \n\t\t\t\t astride, N, elsize);\n\t\t\tif (sort(buffer, N, op) < 0) {\n\t\t\t\tPyDataMem_FREE(buffer); goto fail;\n\t\t\t}\n\t\t\t_strided_copy(it->dataptr, astride, buffer, \n\t\t\t\t (intp) elsize, N, elsize);\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyDataMem_FREE(buffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tif (sort(it->dataptr, N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\t\n\t\n\tEND_THREADS\n\t\n\tPy_DECREF(it);\n\treturn 0;\n\n fail:\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nstatic PyObject*\n_new_argsort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\n\tPyArrayIterObject *it=NULL;\n\tPyArrayIterObject *rit=NULL;\n\tPyObject *ret;\n\tint needcopy=0, i;\n\tintp N, size;\n\tint elsize;\n\tintp astride, rstride, *iptr;\n\tPyArray_ArgSortFunc *argsort;\n\tBEGIN_THREADS_DEF \n\n\tret = PyArray_New(op->ob_type, op->nd,\n\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) return NULL;\n\n\tit = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)op, axis);\n\trit = (PyArrayIterObject *)PyArray_IterAllButAxis(ret, axis);\n\tif (rit == NULL || it == NULL) goto fail;\n\n\tBEGIN_THREADS\n\n\targsort = op->descr->f->argsort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize) || \\\n\t\t(rstride != sizeof(intp));\n\t\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(elsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(valbuffer, (intp) elsize, it->dataptr,\n\t\t\t\t astride, N, elsize);\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idataptr, rstride, indbuffer, \n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idataptr, (intp *)rit->dataptr, \n\t\t\t\t N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\t\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\tPy_DECREF(rit);\n\treturn ret;\n\n fail:\n\n\tEND_THREADS\n\n\tPy_DECREF(ret);\n\tPy_XDECREF(it);\n\tPy_XDECREF(rit);\n\treturn NULL;\n}\n\n\n/* Be sure to save this global_compare when necessary */\n\nstatic PyArrayObject *global_obj;\n\nstatic int \nqsortCompare (const void *a, const void *b) \n{\n\treturn global_obj->descr->f->compare(a,b,global_obj);\n}\n\n/* Consumes reference to ap (op gets it)\n op contains a version of the array with axes swapped if\n local variable axis is not the last dimension.\n orign must be defined locally. \n*/\n\n#define SWAPAXES(op, ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* Consumes reference to ap (op gets it)\n origin must be previously defined locally. \n SWAPAXES must have been called previously. \n op contains the swapped version of the array. \n*/\n#define SWAPBACK(op, ap) {\t \\\n\t\tif (axis != orign) { \\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* These swap axes in-place if necessary */\n#define SWAPINTP(a,b) {intp c; c=(a); (a) = (b); (b) = c;}\n#define SWAPAXES2(ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN); \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define SWAPBACK2(ap) {\t\t \\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n/*MULTIARRAY_API\n Sort an array in-place\n*/\nstatic int\nPyArray_Sort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *store_arr=NULL;\n\tchar *ip;\n\tint i, n, m, elsize, orign;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) return 0;\n\n\tif (axis < 0) axis += n;\n\tif ((axis < 0) || (axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\treturn -1;\n\t}\n\tif (!PyArray_ISWRITEABLE(op)) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"attempted sort on unwriteable array.\");\n\t\treturn -1;\n\t}\n\n\t/* Determine if we should use type-specific algorithm or not */\n\tif (op->descr->f->sort[which] != NULL) {\n\t\treturn _new_sort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || \\\n\t op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"desired sort not supported for this type\");\n\t\treturn -1;\n\t}\n\n\tSWAPAXES2(op);\n\n ap = (PyArrayObject *)PyArray_FromAny((PyObject *)op, \n\t\t\t\t\t NULL, 1, 0, \n\t\t\t\t\t DEFAULT_FLAGS | UPDATEIFCOPY, NULL);\t\n\tif (ap == NULL) goto fail;\n\t\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(ap)/m;\n\n\t/* Store global -- allows re-entry -- restore before leaving*/\n\tstore_arr = global_obj; \n\tglobal_obj = ap;\n\t\n\tfor (ip=ap->data, i=0; idescr->elsize;\n\tconst intp *ipa = ip1;\n\tconst intp *ipb = ip2;\t\n\treturn global_obj->descr->f->compare(global_data + (isize * *ipa),\n global_data + (isize * *ipb), \n\t\t\t\t\t global_obj);\n}\n\n/*MULTIARRAY_API\n ArgSort an array\n*/\nstatic PyObject *\nPyArray_ArgSort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *ret=NULL, *store;\n\tintp *ip;\n\tintp i, j, n, m, orign;\n\tint argsort_elsize;\n\tchar *store_ptr;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t\t op->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, \n\t\t\t\t\t\t (PyObject *)op);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)ret->data) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += n;\n\tif ((axis < 0) || (axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\treturn NULL;\n\t}\n\n\t/* Determine if we should use new algorithm or not */\n\tif (op->descr->f->argsort[which] != NULL) {\n\t\treturn _new_argsort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"requested sort not available for type\");\n\t\tgoto fail;\n\t}\n\n\tSWAPAXES(ap, op);\n\n\top = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ap, \n\t\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t\t 1, 0);\n\n\tif (op == NULL) return NULL;\n\t\n\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) goto fail;\n\t\n\t\n\tip = (intp *)ret->data;\n\targsort_elsize = op->descr->elsize;\n\tm = op->dimensions[op->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(op)/m;\n\tstore_ptr = global_data;\n\tglobal_data = op->data;\n\tstore = global_obj;\n\tglobal_obj = op;\n\tfor (i=0; i 0 in lexsort\");\n\t\treturn NULL;\n\t}\n\tmps = (PyArrayObject **) _pya_malloc(n*sizeof(PyArrayObject));\n\tif (mps==NULL) return PyErr_NoMemory();\n\tits = (PyArrayIterObject **) _pya_malloc(n*sizeof(PyArrayIterObject));\n\tif (its == NULL) {_pya_free(mps); return PyErr_NoMemory();}\n\tfor (i=0; i0) {\n\t\t\tif ((mps[i]->nd != mps[0]->nd) ||\t\\\n\t\t\t (!PyArray_CompareLists(mps[i]->dimensions,\n\t\t\t\t\t\t mps[0]->dimensions,\n\t\t\t\t\t\t mps[0]->nd))) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"all keys need to be the same shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (!mps[i]->descr->f->argsort[PyArray_MERGESORT]) {\n\t\t\tPyErr_Format(PyExc_TypeError, \n\t\t\t\t \"merge sort not available for item %d\", i);\n\t\t\tgoto fail;\n\t\t}\n\t\tits[i] = (PyArrayIterObject *)PyArray_IterAllButAxis\t\\\n\t\t\t((PyObject *)mps[i], axis);\n\t\tif (its[i]==NULL) goto fail;\n\t}\n\n\t/* Now we can check the axis */\n\tnd = mps[0]->nd;\n\tif ((nd==0) || (PyArray_SIZE(mps[0])==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)(ret->data)) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += nd;\n\tif ((axis < 0) || (axis >= nd)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\tgoto fail;\n\t}\n\n\t/* Now do the sorting */\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t mps[0]->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (ret == NULL) goto fail;\n\n\trit = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ret, axis);\n\tif (rit == NULL) goto fail;\n\n\tsize = rit->size;\n\tN = mps[0]->dimensions[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n maxelsize = mps[0]->descr->elsize;\n\tneedcopy = (rstride != sizeof(intp));\n\tfor (j=0; jflags & ALIGNED) || \\\n\t\t\t(mps[j]->strides[axis] != (intp)mps[j]->descr->elsize);\n if (mps[j]->descr->elsize > maxelsize) \n maxelsize = mps[j]->descr->elsize;\n\t}\n\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(maxelsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*maxelsize);\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idescr->elsize;\n\t\t\t\tastride = mps[j]->strides[axis];\t\n\t\t\t\targsort = mps[j]->descr->f->argsort[PyArray_MERGESORT];\n\t\t\t\t_strided_copy(valbuffer, (intp) elsize, its[j]->dataptr,\n\t\t\t\t\t astride, N, elsize);\n\t\t\t\tif (argsort(valbuffer, (intp *)indbuffer, N, mps[j]) < 0) {\n\t\t\t\t\tPyDataMem_FREE(valbuffer); goto fail;\n\t\t\t\t}\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\t_strided_copy(rit->dataptr, rstride, indbuffer,\n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idescr->f->argsort[PyArray_MERGESORT];\n\t\t\t\tif (argsort(its[j]->dataptr, (intp *)rit->dataptr,\n\t\t\t\t\t N, mps[j]) < 0) goto fail;\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\n\tfor (i=0; idescr->f->compare;\n\tintp min_i, max_i, i, j;\n\tint location, elsize = ap1->descr->elsize;\n\tintp elements = ap1->dimensions[ap1->nd-1];\n\tintp n = PyArray_SIZE(ap2);\n\tintp *rp = (intp *)ret->data;\n\tchar *ip = ap2->data;\n\tchar *vp = ap1->data;\n\n\tfor (j=0; j 0) {\n\t\t\t\t\tif (compare(ip, vp+elsize*(--i), ap2) \\\n\t\t\t\t\t != 0) {\n\t\t\t\t\t\ti = i+1; break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmin_i = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (location < 0) {\n\t\t\t\tmax_i = i;\n\t\t\t} else {\n\t\t\t\tmin_i = i+1;\n\t\t\t}\n\t\t}\n\t\t*rp = min_i;\n\t}\n}\n\n/*MULTIARRAY_API\n Numeric.searchsorted(a,v)\n*/\nstatic PyObject *\nPyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n\tint typenum = 0;\n\n\t/* \n PyObject *args;\n args = Py_BuildValue(\"O\",op2);\n\tPy_DELEGATE_ARGS(((PyObject *)op1), searchsorted, args);\n Py_XDECREF(args);\n\t*/\n\n\ttypenum = PyArray_ObjectType((PyObject *)op1, 0);\n\ttypenum = PyArray_ObjectType(op2, typenum);\n\tret = NULL;\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op1, \n\t\t\t\t\t\t\t typenum, \n\t\t\t\t\t\t\t 1, 1);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tret = (PyArrayObject *)PyArray_New(ap2->ob_type, ap2->nd, \n\t\t\t\t\t ap2->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap2);\n\tif (ret == NULL) goto fail;\n\n\tif (ap2->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tgoto fail;\n\t}\n\t\n\tlocal_where(ap1, ap2, ret); \n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n/*\n Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\treturn ret;\n}\n\n/* Could perhaps be redone to not make contiguous arrays \n */\n\n/*MULTIARRAY_API\n Numeric.innerproduct(a,v)\n*/\nstatic PyObject *\nPyArray_InnerProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tPyArray_Descr *typec;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\tdot = (ret->descr->f->dotfunc);\n\t\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[ap1->nd-1]; \n\tis2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, ap2->nd-1);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\n\tif (PyErr_Occurred()) goto fail;\n\t\t\n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n\n/* just like inner product but does the swapaxes stuff on the fly */\n/*MULTIARRAY_API\n Numeric.matrixproduct(a,v)\n*/\nstatic PyObject *\nPyArray_MatrixProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tintp matchDim;\n\tPyArray_Descr *typec;\n\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\t\n\t\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t}\n\telse {\n\t\tmatchDim = 0;\n\t}\n\n\tif (ap2->dimensions[matchDim] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"objects are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-2; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\tif(ap2->nd > 1) {\n\t\tdimensions[j++] = ap2->dimensions[ap2->nd-1];\n\t}\n\t/*\n\tfprintf(stderr, \"nd=%d dimensions=\", nd);\n\t for(i=0; istrides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\n /* Choose which subtype to return */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\n\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\t\t\n\top = ret->data; os = ret->descr->elsize;\n\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, matchDim);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\tif (PyErr_Occurred()) goto fail; /* only for OBJECT arrays */\n\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n/*MULTIARRAY_API\n Fast Copy and Transpose\n*/\nstatic PyObject *\nPyArray_CopyAndTranspose(PyObject *op) \n{\n\tPyObject *ret, *arr;\n\tint nd;\n\tintp dims[2];\n\tintp i,j;\n\tint elsize, str2;\n\tchar *iptr;\n\tchar *optr;\n\n\t/* make sure it is well-behaved */\n\tarr = PyArray_FromAny(op, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\tnd = PyArray_NDIM(arr);\n\tif (nd == 1) { /* we will give in to old behavior */\n\t\tret = PyArray_Copy((PyArrayObject *)arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\t\t\n\t}\n\telse if (nd != 2) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"only 2-d arrays are allowed\");\n\t\treturn NULL;\n\t}\n\n\t/* Now construct output array */\n\tdims[0] = PyArray_DIM(arr,1);\n\tdims[1] = PyArray_DIM(arr,0);\n\telsize = PyArray_ITEMSIZE(arr);\n\t\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(arr->ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t 2, dims, \n\t\t\t\t NULL, NULL, 0, arr);\n\n\tif (ret == NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn NULL;\n\t}\n\t/* do 2-d loop */\n\toptr = PyArray_DATA(ret);\n\tstr2 = elsize*dims[0];\n\tfor (i=0; idimensions[0];\n\tn2 = ap2->dimensions[0];\n\n\tif (n1 < n2) { \n\t\tret = ap1; ap1 = ap2; ap2 = ret; \n\t\tret = NULL; i = n1;n1=n2;n2=i;\n\t}\n\tlength = n1;\n\tn = n2;\n\tswitch(mode) {\n\tcase 0:\t\n\t\tlength = length-n+1;\n\t\tn_left = n_right = 0;\n\t\tbreak;\n\tcase 1:\n\t\tn_left = (intp)(n/2);\n\t\tn_right = n-n_left-1;\n\t\tbreak;\n\tcase 2:\n\t\tn_right = n-1;\n\t\tn_left = n-1;\n\t\tlength = length+n-1;\n\t\tbreak;\n\tdefault:\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mode must be 0, 1, or 2\");\n\t\tgoto fail;\n\t}\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\n\tif (ret == NULL) goto fail;\n\t\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"function not available for this data type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[0]; is2 = ap2->strides[0];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data; ip2 = ap2->data+n_left*is2;\n\tn = n-n_left;\n\tfor(i=0; idescr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Min\n*/\nstatic PyObject *\nPyArray_Min(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tret = PyArray_GenericReduceFunction(arr, n_ops.minimum, axis,\n\t\t\t\t\t arr->descr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Ptp\n*/\nstatic PyObject *\nPyArray_Ptp(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\tPyObject *obj1=NULL, *obj2=NULL;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tobj1 = PyArray_Max(arr, axis);\n\tif (obj1 == NULL) goto fail;\n\tobj2 = PyArray_Min(arr, axis);\n\tif (obj2 == NULL) goto fail;\n\tPy_DECREF(arr);\n\tret = PyNumber_Subtract(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(obj1);\n\tPy_XDECREF(obj2);\n\treturn NULL;\n}\n\n\n/*MULTIARRAY_API\n ArgMax\n*/\nstatic PyObject *\nPyArray_ArgMax(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap=NULL, *rp=NULL;\n\tPyArray_ArgFunc* arg_func;\n\tchar *ip;\n\tintp *rptr;\n\tintp i, n, orign, m;\n\tint elsize;\n\t\n\tif ((ap=(PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny((PyObject *)op, \n\t\t\t\t\t PyArray_NOTYPE, 1, 0);\n\n\tPy_DECREF(op);\n\tif (ap == NULL) return NULL;\n\t\n\targ_func = ap->descr->f->argmax;\n\tif (arg_func == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"data type not ordered\");\n\t\tgoto fail;\n\t}\n\n\trp = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd-1,\n\t\t\t\t\t ap->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)ap);\n\tif (rp == NULL) goto fail;\n\n\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) {\n\t\tPyErr_SetString(MultiArrayError, \n\t\t\t\t\"attempt to get argmax/argmin \"\\\n\t\t\t\t\"of an empty sequence??\");\n\t\tgoto fail;\n\t}\n\tn = PyArray_SIZE(ap)/m;\n\trptr = (intp *)rp->data;\n\tfor (ip = ap->data, i=0; ind + indices->nd - 1;\n for (i=0; i< nd; i++) {\n if (i < axis) {\n shape[i] = self->dimensions[i];\n n *= shape[i];\n } else {\n if (i < axis+indices->nd) {\n shape[i] = indices->dimensions[i-axis];\n m *= shape[i];\n } else {\n shape[i] = self->dimensions[i-indices->nd+1];\n chunk *= shape[i];\n }\n }\n }\n\tPy_INCREF(self->descr);\n ret = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t nd, shape, \n\t\t\t\t\t\t NULL, NULL, 0, \n\t\t\t\t\t\t (PyObject *)self);\n\t\n if (ret == NULL) goto fail;\n\t\n max_item = self->dimensions[axis];\n chunk = chunk * ret->descr->elsize;\n src = self->data;\n dest = ret->data;\n\t\n for(i=0; idata))[j];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\t\"index out of range for \"\\\n\t\t\t\t\t\t\"array\");\n goto fail;\n }\n memmove(dest, src+tmp*chunk, chunk);\n dest += chunk;\n }\n src += chunk*max_item;\n }\n\t\n PyArray_INCREF(ret);\n\n Py_XDECREF(indices);\n Py_XDECREF(self);\n\n return (PyObject *)ret;\n\t\n\t\n fail:\n Py_XDECREF(ret);\n Py_XDECREF(indices);\n Py_XDECREF(self);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array\n*/\nstatic PyObject *\nPyArray_Put(PyArrayObject *self, PyObject* values0, PyObject *indices0) \n{\n PyArrayObject *indices, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype; \n char *src, *dest;\n\n indices = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \"put: first argument must be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \"put: first argument must be contiguous\");\n return NULL;\n }\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0);\n if (indices == NULL) goto fail;\n ni = PyArray_SIZE(indices);\n\n\tthistype = self->descr->type_num;\n Py_INCREF(self->descr); \n\tvalues = (PyArrayObject *)PyArray_FromAny(values0, self->descr, 0, 0, \n\t\t\t\t\t\t DEFAULT_FLAGS | FORCECAST, NULL); \n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\n if (thistype == PyArray_OBJECT) { \n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n Py_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+tmp*chunk)));\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n\n }\n\n Py_XDECREF(values);\n Py_XDECREF(indices);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(indices);\n Py_XDECREF(values);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array according to a mask.\n*/\nstatic PyObject *\nPyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) \n{\n PyArrayObject *mask, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype;\n char *src, *dest;\n\n mask = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"putmask: first argument must \"\\\n\t\t\t\t\"be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: first argument must be contiguous\");\n return NULL;\n }\n\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n mask = (PyArrayObject *)\\\n\t\tPyArray_FROM_OTF(mask0, PyArray_BOOL, CARRAY_FLAGS | FORCECAST);\n\tif (mask == NULL) goto fail;\n ni = PyArray_SIZE(mask);\n if (ni != max_item) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: mask and data must be \"\\\n\t\t\t\t\"the same size\");\n goto fail;\n }\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n\tif (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\t /* zero if null array */\n if (nv > 0) {\n if (thistype == PyArray_OBJECT) {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) {\n\t\t\t\t\tPy_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+i*chunk)));\n memmove(dest + i * chunk, src, chunk);\n }\n\t\t\t}\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) memmove(dest + i * chunk, src, chunk);\n\t\t\t}\n\t\t}\n }\n\n Py_XDECREF(values);\n Py_XDECREF(mask);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(mask);\n Py_XDECREF(values);\n return NULL;\n}\n\n\n/* This conversion function can be used with the \"O&\" argument for\n PyArg_ParseTuple. It will immediately return an object of array type\n or will convert to a CARRAY any other object. \n\n If you use PyArray_Converter, you must DECREF the array when finished\n as you get a new reference to it.\n*/\n \n/*MULTIARRAY_API\n Useful to pass as converter function for O& processing in\n PyArgs_ParseTuple.\n*/\nstatic int \nPyArray_Converter(PyObject *object, PyObject **address) \n{\n if (PyArray_Check(object)) {\n *address = object;\n\t\tPy_INCREF(object);\n return PY_SUCCEED;\n }\n else {\n\t\t*address = PyArray_FromAny(object, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\t\tif (*address == NULL) return PY_FAIL;\n\t\treturn PY_SUCCEED;\n }\n}\n\n/*MULTIARRAY_API\n Convert an object to true / false\n*/\nstatic int\nPyArray_BoolConverter(PyObject *object, Bool *val)\n{ \n\tif (PyObject_IsTrue(object))\n\t\t*val=TRUE;\n\telse *val=FALSE;\n\tif (PyErr_Occurred())\n\t\treturn PY_FAIL;\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Convert an object to true / false\n*/\nstatic int\nPyArray_ConditionConverter(PyObject *object, PyArray_CONDITION *val)\n{ \n\n\tif (object == Py_None) \n\t\t*val = PyArray_DONTCARE;\n\telse if (PyObject_IsTrue(object))\n\t\t*val=PyArray_TRUE;\n\telse *val=PyArray_FALSE;\n\tif (PyErr_Occurred())\n\t\treturn PY_FAIL;\n\treturn PY_SUCCEED;\n}\n\n\n\n/*MULTIARRAY_API\n Typestr converter\n*/\nstatic int\nPyArray_TypestrConvert(int itemsize, int gentype)\n{\n\tregister int newtype = gentype;\n\t\n\tif (gentype == PyArray_GENBOOLLTR) {\n\t\tif (itemsize == 1)\n\t\t\tnewtype = PyArray_BOOL;\n\t\telse \n\t\t\tnewtype = PyArray_NOTYPE;\n\t}\n\telse if (gentype == PyArray_SIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_INT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_INT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_INT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_INT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_INT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\n\t}\n\n\telse if (gentype == PyArray_UNSIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_UINT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_UINT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_UINT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_UINT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_UINT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t\tbreak;\n\t\t}\n\t}\n\telse if (gentype == PyArray_FLOATINGLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 4:\n\t\t\tnewtype = PyArray_FLOAT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_FLOAT64;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 10:\n\t\t\tnewtype = PyArray_FLOAT80;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 12:\n\t\t\tnewtype = PyArray_FLOAT96;\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_FLOAT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\t\n\telse if (gentype == PyArray_COMPLEXLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 8:\n\t\t\tnewtype = PyArray_COMPLEX64;\n\t\t\tbreak;\n\t\tcase 16:\n\t\t\tnewtype = PyArray_COMPLEX128;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 20:\n\t\t\tnewtype = PyArray_COMPLEX160;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 24:\n\t\t\tnewtype = PyArray_COMPLEX192;\t\t\t\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 32:\n\t\t\tnewtype = PyArray_COMPLEX256;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\n\treturn newtype;\n}\n\n\n/* this function takes a Python object which exposes the (single-segment)\n buffer interface and returns a pointer to the data segment\n \n You should increment the reference count by one of buf->base\n if you will hang on to a reference\n\n You only get a borrowed reference to the object. Do not free the\n memory...\n*/\n\n\n/*MULTIARRAY_API\n Get buffer chunk from object\n*/\nstatic int\nPyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)\n{\n int buflen;\n\n buf->ptr = NULL;\n buf->flags = BEHAVED_FLAGS;\n buf->base = NULL;\n\n\tif (obj == Py_None)\n\t\treturn PY_SUCCEED;\n\n if (PyObject_AsWriteBuffer(obj, &(buf->ptr), &buflen) < 0) {\n PyErr_Clear();\n buf->flags &= ~WRITEABLE;\n if (PyObject_AsReadBuffer(obj, (const void **)&(buf->ptr), \n &buflen) < 0)\n return PY_FAIL;\n }\n buf->len = (intp) buflen;\n \n /* Point to the base of the buffer object if present */\n if (PyBuffer_Check(obj)) buf->base = ((PyArray_Chunk *)obj)->base;\n if (buf->base == NULL) buf->base = obj;\n \n return PY_SUCCEED; \n}\n\n\n\n/* This function takes a Python sequence object and allocates and\n fills in an intp array with the converted values.\n\n **Remember to free the pointer seq.ptr when done using\n PyDimMem_FREE(seq.ptr)**\n*/\n\n/*MULTIARRAY_API\n Get intp chunk from sequence\n*/\nstatic int\nPyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)\n{\n int len;\n int nd;\n\n seq->ptr = NULL;\n if (obj == Py_None) return PY_SUCCEED;\n len = PySequence_Size(obj);\n if (len == -1) { /* Check to see if it is a number */\n if (PyNumber_Check(obj)) len = 1;\n }\n if (len < 0) {\n PyErr_SetString(PyExc_TypeError, \n \"expected sequence object with len >= 0\");\n return PY_FAIL;\n }\n if (len > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError, \"sequence too large; \" \\\n \"must be smaller than %d\", MAX_DIMS);\n return PY_FAIL;\n }\n\tif (len > 0) {\n\t\tseq->ptr = PyDimMem_NEW(len);\n\t\tif (seq->ptr == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n seq->len = len;\n nd = PyArray_IntpFromSequence(obj, (intp *)seq->ptr, len);\n if (nd == -1 || nd != len) {\n\t\tPyDimMem_FREE(seq->ptr);\n\t\tseq->ptr=NULL;\n\t\treturn PY_FAIL;\n\t}\n return PY_SUCCEED;\n}\n\n\n/* A tuple type would be either (generic typeobject, typesize) \n or (fixed-length data-type, shape) \n\n or (inheriting data-type, new-data-type)\n The new data-type must have the same itemsize as the inheriting data-type\n unless the latter is 0 \n \n Thus (int32, {'real':(int16,0),'imag',(int16,2)})\n\n is one way to specify a descriptor that will give \n a['real'] and a['imag'] to an int32 array.\n*/\n\n/* leave type reference alone */\nstatic PyArray_Descr *\n_use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) \n{\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n\t\n\t*errflag = 0;\n\tif (!PyArray_DescrConverter(newobj, &conv)) {\n\t\treturn NULL;\n\t}\n\t*errflag = 1;\n\tif (type == &OBJECT_Descr) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"cannot base a new descriptor on an\"\\\n\t\t\t\t\" OBJECT descriptor.\");\n\t\tgoto fail;\n\t}\n\tnew = PyArray_DescrNew(type);\n\tif (new == NULL) goto fail;\n\n\tif (new->elsize && new->elsize != conv->elsize) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mismatch in size of old\"\\\n\t\t\t\t\"and new data-descriptor\");\n\t\tgoto fail;\n\t}\n\tnew->elsize = conv->elsize;\n\tif (conv->fields != Py_None) {\n\t\tnew->fields = conv->fields;\n\t\tPy_XINCREF(new->fields);\n\t}\n\tPy_DECREF(conv);\n\t*errflag = 0;\n\treturn new;\n\n fail:\n\tPy_DECREF(conv);\n\treturn NULL;\n\n}\n\nstatic PyArray_Descr *\n_convert_from_tuple(PyObject *obj) \n{\n\tPyArray_Descr *type, *res;\n\tPyObject *val;\n\tint errflag;\n\t\n\tif (PyTuple_GET_SIZE(obj) != 2) return NULL;\n\n\tif (!PyArray_DescrConverter(PyTuple_GET_ITEM(obj,0), &type)) \n\t\treturn NULL;\n\tval = PyTuple_GET_ITEM(obj,1);\n\t/* try to interpret next item as a type */\n\tres = _use_inherit(type, val, &errflag);\n\tif (res || errflag) {\n\t\tPy_DECREF(type);\n\t\tif (res) return res;\n\t\telse return NULL;\n\t}\n\tPyErr_Clear();\n\t/* We get here if res was NULL but errflag wasn't set\n\t --- i.e. the conversion to a data-descr failed in _use_inherit\n\t*/\n\n\tif (type->elsize == 0) { /* interpret next item as a typesize */\n\t\tint itemsize;\n\t\titemsize = PyArray_PyIntAsInt(PyTuple_GET_ITEM(obj,1));\n\t\tif (error_converting(itemsize)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid itemsize in generic type \"\\\n\t\t\t\t\t\"tuple\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(type);\n\t\tif (type->type_num == PyArray_UNICODE)\n\t\t\ttype->elsize = itemsize << 2; \n\t\telse\n\t\t\ttype->elsize = itemsize;\n\t}\n\telse {\n\t\t/* interpret next item as shape (if it's a tuple)\n\t\t and reset the type to PyArray_VOID with \n\t\t a new fields attribute. \n\t */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyArray_Descr *newdescr;\n\t\tif (!(PyArray_IntpConverter(val, &shape)) || \n\t\t (shape.len > MAX_DIMS)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n\t\t\tgoto fail;\n\t\t}\n\t\t/* If (type, 1) was given, it is equivalent to type... */\n\t\tif (shape.len == 1 && shape.ptr[0] == 1 && \\\n\t\t PyNumber_Check(val)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\treturn type;\n\t\t}\n\t\tnewdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tif (newdescr == NULL) {PyDimMem_FREE(shape.ptr); goto fail;}\n\t\tnewdescr->elsize = type->elsize;\n\t\tnewdescr->elsize *= PyArray_MultiplyList(shape.ptr, \n\t\t\t\t\t\t\t shape.len);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tnewdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tnewdescr->subarray->base = type;\n\t\tif (type->hasobject) newdescr->hasobject = 1;\n\t\tPy_INCREF(val);\n\t\tnewdescr->subarray->shape = val;\n\t\tPy_XDECREF(newdescr->fields);\n\t\tnewdescr->fields = NULL;\n\t\ttype = newdescr;\n\t}\n\treturn type;\n\n fail:\n\tPy_XDECREF(type);\n\treturn NULL;\n}\n\n/* obj is a list. Each item is a tuple with\n\n(field-name, data-type (either a list or a string), and an optional \n shape parameter).\n*/\nstatic PyArray_Descr *\n_convert_from_array_descr(PyObject *obj)\n{\n\tint n, i, totalsize;\n\tint ret;\n\tPyObject *fields, *item, *newobj;\n\tPyObject *name, *key, *tup, *title;\n\tPyObject *nameslist;\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n int hasobject=0;\n\t\n\tn = PyList_GET_SIZE(obj);\t\n\tnameslist = PyTuple_New(n);\n\tif (!nameslist) return NULL;\n\ttotalsize = 0;\n\tfields = PyDict_New();\n\tfor (i=0; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New((title == NULL ? 2 : 3));\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\tif (title != NULL) {\t\t\t\n\t\t\tPy_INCREF(title);\n\t\t\tPyTuple_SET_ITEM(tup, 2, title);\n\t\t\tPyDict_SetItem(fields, title, tup);\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\ttotalsize += conv->elsize;\n\t\tPy_DECREF(tup);\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n\tnew->elsize = totalsize;\n new->hasobject=hasobject;\n\treturn new;\n \n fail:\n\tPy_DECREF(fields);\n\tPy_DECREF(nameslist);\n\treturn NULL;\n\n}\n\n/* a list specifying a data-type can just be\n a list of formats. The names for the fields\n will default to f1, f2, f3, and so forth.\n\n or it can be an array_descr format string -- in which case\n align must be 0. \n*/\n\nstatic PyArray_Descr *\n_convert_from_list(PyObject *obj, int align, int try_descr)\n{\n\tint n, i;\n\tint totalsize;\n\tPyObject *fields;\n\tPyArray_Descr *conv=NULL;\n\tPyArray_Descr *new;\n\tPyObject *key, *tup;\n\tPyObject *nameslist=NULL;\n \tint ret;\n\tint maxalign=0;\n int hasobject=0;\n\t\n\tn = PyList_GET_SIZE(obj);\n\ttotalsize = 0;\n\tif (n==0) return NULL;\n\tnameslist = PyTuple_New(n);\n\tif (!nameslist) return NULL;\n\tfields = PyDict_New();\n\tfor (i=0; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tif (align) {\n\t\t\tint _align;\n\t\t\t_align = conv->alignment;\n\t\t\tif (_align > 1) totalsize =\t\t\t\\\n\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\tmaxalign = MAX(maxalign, _align);\n\t\t}\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\tPyDict_SetItem(fields, key, tup);\n\t\tPy_DECREF(tup);\n\t\tPyTuple_SET_ITEM(nameslist, i, key);\n\t\ttotalsize += conv->elsize;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n new->hasobject=hasobject;\n\tif (maxalign > 1) {\n\t\ttotalsize = ((totalsize+maxalign-1)/maxalign)*maxalign;\n\t}\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\treturn new;\n\n fail:\n\tPy_DECREF(nameslist);\n\tPy_DECREF(fields);\n\tif (!try_descr) return NULL;\n\tif (align) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"failed to convert from list of formats \"\\\n\t\t\t\t\"and align cannot be 1 for conversion from \"\\\n\t\t\t\t\"array_descr structure\");\n\t\treturn NULL;\n\t}\n\tPyErr_Clear();\n\treturn _convert_from_array_descr(obj);\n}\n\n\n/* comma-separated string */\n/* this is the format developed by the numarray records module */\n/* and implemented by the format parser in that module */\n/* this is an alternative implementation found in the _internal.py \n file patterned after that one -- the approach is to try to convert \n to a list (with tuples if any repeat information is present) \n and then call the _convert_from_list)\n*/\n\nstatic PyArray_Descr *\n_convert_from_commastring(PyObject *obj, int align)\n{\n\tPyObject *listobj;\n\tPyArray_Descr *res;\n\n\tif (!PyString_Check(obj)) return NULL;\n listobj = PyObject_CallMethod(_numpy_internal, \"_commastring\",\n\t\t\t\t \"O\", obj);\n\tif (!listobj) return NULL;\n\tres = _convert_from_list(listobj, align, 0);\n\tPy_DECREF(listobj);\n\tif (!res && !PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_ValueError, \"invalid data-type\");\n\t\treturn NULL;\n\t}\n\treturn res;\n}\n\n\n\n/* a dictionary specifying a data-type\n must have at least two and up to four\n keys These must all be sequences of the same length.\n\n \"names\" --- field names \n \"formats\" --- the data-type descriptors for the field.\n \n Optional:\n\n \"offsets\" --- integers indicating the offset into the \n record of the start of the field.\n\t\t if not given, then \"consecutive offsets\" \n\t\t will be assumed and placed in the dictionary.\n \n \"titles\" --- Allows the use of an additional key\n for the fields dictionary.\n \nAttribute-lookup-based field names merely has to query the fields \ndictionary of the data-descriptor. Any result present can be used\nto return the correct field.\n\nSo, the notion of what is a name and what is a title is really quite\narbitrary. \n\nWhat does distinguish a title, however, is that if it is not None, \nit will be placed at the end of the tuple inserted into the \nfields dictionary.\n\nIf the dictionary does not have \"names\" and \"formats\" entries,\nthen it will be checked for conformity and used directly. \n*/\n\nstatic PyArray_Descr *\n_use_fields_dict(PyObject *obj, int align)\n{\n return (PyArray_Descr *)PyObject_CallMethod(_numpy_internal, \n\t\t\t\t\t\t \"_usefields\", \n\t\t\t\t\t\t \"Oi\", obj, align);\n}\n\nstatic PyArray_Descr *\n_convert_from_dict(PyObject *obj, int align)\n{\n\tPyArray_Descr *new;\n\tPyObject *fields=NULL;\n\tPyObject *names, *offsets, *descrs, *titles, *key;\n\tint n, i;\n\tint totalsize;\n\tint maxalign=0;\n int hasobject=0;\n\t\n\tfields = PyDict_New();\n\tif (fields == NULL) return (PyArray_Descr *)PyErr_NoMemory();\n\t\n\tnames = PyDict_GetItemString(obj, \"names\");\n\tdescrs = PyDict_GetItemString(obj, \"formats\");\n\n\tif (!names || !descrs) {\n\t\tPy_DECREF(fields);\n\t\treturn _use_fields_dict(obj, align);\n\t}\n\tn = PyObject_Length(names);\n\toffsets = PyDict_GetItemString(obj, \"offsets\");\n\ttitles = PyDict_GetItemString(obj, \"titles\");\n\tif ((n > PyObject_Length(descrs)) ||\t\t\t\\\n\t (offsets && (n > PyObject_Length(offsets))) ||\t\\\n\t (titles && (n > PyObject_Length(titles)))) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"all items in the dictionary must have\" \\\n\t\t\t\t\" the same length.\");\n\t\tgoto fail;\n\t}\n\n\ttotalsize = 0;\n\tfor(i=0; i totalsize) totalsize = offset;\n\t\t}\n\t\telse {\n\t\t\tif (align) {\n\t\t\t\tint _align = newdescr->alignment;\n\t\t\t\tif (_align > 1) totalsize =\t\t\\\n\t\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\t\tmaxalign = MAX(maxalign,_align);\n\t\t\t}\n\t\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\n\t\t}\n\t\tif (len == 3) PyTuple_SET_ITEM(tup, 2, item);\n\t\tname = PyObject_GetItem(names, index);\n\t\tPy_DECREF(index);\n\n\t\t/* Insert into dictionary */\n\t\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"name already used as a name or title\");\n\t\t\tret = PY_FAIL;\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) {\n\t\t\tif (PyDict_GetItem(fields, item) != NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"title already used as a name or \" \\\n\t\t\t\t\t\t\" title.\");\n\t\t\t\tret=PY_FAIL;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyDict_SetItem(fields, item, tup);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n if (!hasobject && newdescr->hasobject)\n hasobject = 1;\n\t\ttotalsize += newdescr->elsize;\n\t}\n\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tif (new == NULL) goto fail;\n\tif (maxalign > 1)\n\t\ttotalsize = ((totalsize + maxalign - 1)/maxalign)*maxalign;\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\tkey = PyInt_FromLong(-1);\n if (!PyTuple_Check(names)) {\n names = PySequence_Tuple(names);\n PyDict_SetItem(fields, key, names);\n Py_DECREF(names);\n }\n else PyDict_SetItem(fields, key, names);\n\tPy_DECREF(key);\n\tnew->fields = fields;\n new->hasobject=hasobject;\n\treturn new;\n\n fail:\n\tPy_XDECREF(fields);\n\treturn NULL;\n}\n\n/* \n any object with \n the .fields attribute and/or .itemsize attribute \n (if the .fields attribute does not give\n the total size -- i.e. a partial record naming).\n If itemsize is given it must be >= size computed from fields\n \n The .fields attribute must return a convertible dictionary if \n present. Result inherits from PyArray_VOID.\n*/\n\n\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to NULL\n*/\nstatic int\nPyArray_DescrConverter2(PyObject *obj, PyArray_Descr **at)\n{\n\tif (obj == Py_None) {\n\t\t*at = NULL;\n\t\treturn PY_SUCCEED;\n\t}\n\telse return PyArray_DescrConverter(obj, at);\n}\n\n/* This function takes a Python object representing a type and converts it \n to a the correct PyArray_Descr * structure to describe the type.\n \n Many objects can be used to represent a data-type which in NumPy is\n quite a flexible concept. \n\n This is the central code that converts Python objects to \n Type-descriptor objects that are used throughout numpy.\n */\n\n/* new reference in *at */\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to &LONG_descr\n*/\nstatic int\nPyArray_DescrConverter(PyObject *obj, PyArray_Descr **at)\n{\n char *type;\n int check_num=PyArray_NOTYPE+10;\n\tint len;\n\tPyObject *item;\n\tint elsize = 0;\n\tchar endian = '=';\n\n\t*at=NULL;\n\t\n\t/* default */\n if (obj == Py_None) {\n\t\t*at = PyArray_DescrFromType(PyArray_LONG);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n\tif (PyArray_DescrCheck(obj)) {\n\t\t*at = (PyArray_Descr *)obj;\n\t\tPy_INCREF(*at);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n if (PyType_Check(obj)) {\n\t\tif (PyType_IsSubtype((PyTypeObject *)obj, \n\t\t\t\t &PyGenericArrType_Type)) {\n\t\t\t*at = PyArray_DescrFromTypeObject(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t\telse return PY_FAIL;\n\t\t}\n\t\tcheck_num = PyArray_OBJECT;\n\t\tif (obj == (PyObject *)(&PyInt_Type))\n\t\t\tcheck_num = PyArray_LONG;\n\t\telse if (obj == (PyObject *)(&PyLong_Type))\n\t\t\tcheck_num = PyArray_LONGLONG;\n\t\telse if (obj == (PyObject *)(&PyFloat_Type)) \n\t\t\tcheck_num = PyArray_DOUBLE;\n\t\telse if (obj == (PyObject *)(&PyComplex_Type)) \n\t\t\tcheck_num = PyArray_CDOUBLE;\n\t\telse if (obj == (PyObject *)(&PyBool_Type))\n\t\t\tcheck_num = PyArray_BOOL;\n else if (obj == (PyObject *)(&PyString_Type))\n check_num = PyArray_STRING;\n else if (obj == (PyObject *)(&PyUnicode_Type))\n check_num = PyArray_UNICODE;\n\t\telse if (obj == (PyObject *)(&PyBuffer_Type))\n\t\t\tcheck_num = PyArray_VOID;\n\t\telse {\n\t\t\t*at = _arraydescr_fromobj(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* or a typecode string */\n\n\tif (PyString_Check(obj)) {\n\t\t/* Check for a string typecode. */\n\t\ttype = PyString_AS_STRING(obj);\n\t\tlen = PyString_GET_SIZE(obj);\n\t\tif (len <= 0) goto fail;\n\t\tcheck_num = (int) type[0];\n\t\tif ((char) check_num == '>' || (char) check_num == '<' || \\\n\t\t (char) check_num == '|' || (char) check_num == '=') {\n\t\t\tif (len <= 1) goto fail;\n\t\t\tendian = (char) check_num;\n\t\t\ttype++; len--;\n\t\t\tcheck_num = (int) type[0];\n\t\t\tif (endian == '|') endian = '=';\n\t\t}\n\t\tif (len > 1) {\n\t\t\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\t\t\tfor (i=1;ielsize == 0) && (elsize != 0)) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->elsize = elsize;\n\t}\n\tif (endian != '=' && PyArray_ISNBO(endian)) endian = '='; \n\t\n\tif (endian != '=' && (*at)->byteorder != '|' &&\t\\\n\t (*at)->byteorder != endian) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->byteorder = endian;\n\t}\n\t\n return PY_SUCCEED;\n\n fail:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"data type not understood\");\n\t*at=NULL;\n\treturn PY_FAIL;\n}\t\n\n/*MULTIARRAY_API\n Convert object to endian\n*/\nstatic int\nPyArray_ByteorderConverter(PyObject *obj, char *endian)\n{\n\tchar *str;\n\t*endian = PyArray_SWAP;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Byteorder string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\t*endian = str[0];\n\tif (str[0] != PyArray_BIG && str[0] != PyArray_LITTLE &&\t\\\n\t str[0] != PyArray_NATIVE) {\n\t\tif (str[0] == 'b' || str[0] == 'B')\n\t\t\t*endian = PyArray_BIG;\n\t\telse if (str[0] == 'l' || str[0] == 'L')\n\t\t\t*endian = PyArray_LITTLE;\n\t\telse if (str[0] == 'n' || str[0] == 'N')\n\t\t\t*endian = PyArray_NATIVE;\n\t\telse if (str[0] == 'i' || str[0] == 'I')\n\t\t\t*endian = PyArray_IGNORE;\n\t\telse if (str[0] == 's' || str[0] == 'S')\n\t\t\t*endian = PyArray_SWAP;\n\t\telse {\n\t\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t\t \"%s is an unrecognized byteorder\",\n\t\t\t\t str);\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Convert object to sort kind \n*/\nstatic int\nPyArray_SortkindConverter(PyObject *obj, PyArray_SORTKIND *sortkind)\n{\n\tchar *str;\n\t*sortkind = PyArray_QUICKSORT;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Sort kind string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\tif (str[0] == 'q' || str[0] == 'Q')\n\t\t*sortkind = PyArray_QUICKSORT;\n\telse if (str[0] == 'h' || str[0] == 'H')\n\t\t*sortkind = PyArray_HEAPSORT;\n\telse if (str[0] == 'm' || str[0] == 'M')\n\t\t*sortkind = PyArray_MERGESORT;\n\telse if (str[0] == 't' || str[0] == 'T')\n\t\t*sortkind = PyArray_TIMSORT;\n\telse {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"%s is an unrecognized kind of sort\",\n\t\t\t str);\n\t\treturn PY_FAIL;\n\t}\n\treturn PY_SUCCEED;\n}\n\n\n/* This function returns true if the two typecodes are \n equivalent (same basic kind and same itemsize).\n*/\n\n/*MULTIARRAY_API*/\nstatic Bool\nPyArray_EquivTypes(PyArray_Descr *typ1, PyArray_Descr *typ2)\n{\n\tregister int typenum1=typ1->type_num;\n\tregister int typenum2=typ2->type_num;\n\tregister int size1=typ1->elsize;\n\tregister int size2=typ2->elsize;\n\n\tif (size1 != size2) return FALSE;\n\tif (typ1->fields != typ2->fields) return FALSE;\n\tif (PyArray_ISNBO(typ1->byteorder) != PyArray_ISNBO(typ2->byteorder))\n\t\treturn FALSE;\n\n\tif (typenum1 == PyArray_VOID || \\\n\t typenum2 == PyArray_VOID) {\n\t\treturn ((typenum1 == typenum2) && \n\t\t\t(typ1->typeobj == typ2->typeobj) &&\n\t\t\t(typ1->fields == typ2->fields));\n\t}\n\treturn (typ1->kind == typ2->kind);\n}\n\n/*** END C-API FUNCTIONS **/\n\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\n\n\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_fromobject[] = \"array(object, dtype=None, copy=1, fortran=0, \"\\\n \"subok=0,ndmin=0)\\n\"\\\n \"will return a new array formed from the given object type given.\\n\"\\\n \"Object can be anything with an __array__ method, or any object\\n\"\\\n \"exposing the array interface, or any (nested) sequence.\\n\"\\\n \"If no type is given, then the type will be determined as the\\n\"\\\n \"minimum type required to hold the objects in the sequence.\\n\"\\\n \"If copy is zero and sequence is already an array with the right \\n\"\\\n \"type, a reference will be returned. If the sequence is an array,\\n\"\\\n \"type can be used only to upcast the array. For downcasting \\n\"\\\n \"use .astype(t) method. If subok is true, then subclasses of the\\n\"\\\n \"array may be returned. Otherwise, a base-class ndarray is returned\\n\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\n\nstatic PyObject *\n_array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n{\n\tPyObject *op, *ret=NULL;\n\tstatic char *kwd[]= {\"object\", \"dtype\", \"copy\", \"fortran\", \"subok\", \n\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\n\tPyArray_Descr *type=NULL;\n\tPyArray_Descr *oldtype=NULL;\n\tPyArray_CONDITION fortran=PyArray_DONTCARE;\n\tint flags=0;\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&i\", kwd, &op, \n\t\t\t\t\tPyArray_DescrConverter2,\n &type, \n\t\t\t\t\tPyArray_BoolConverter, ©, \n\t\t\t\t\tPyArray_ConditionConverter, &fortran,\n PyArray_BoolConverter, &subok, \n\t\t\t\t\t&ndmin)) \n\t\treturn NULL;\n\n\t/* fast exit if simple call */\n\tif (PyArray_CheckExact(op)) {\n\t\tif (type==NULL) {\n\t\t\tif (!copy && (fortran == PyArray_DONTCARE\t\\\n\t\t\t\t || fortran==PyArray_ISFORTRAN(op))) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\tret = op;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op, \n\t\t\t\t\t\t fortran);\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\t/* One more chance */\n\t\toldtype = PyArray_DESCR(op);\n\t\tif (PyArray_EquivTypes(oldtype, type)) {\n\t\t\tif (!copy && (fortran == PyArray_DONTCARE || \\\n\t\t\t\t fortran==PyArray_ISFORTRAN(op))) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\tret = op;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op,\n\t\t\t\t\t\t fortran);\n\t\t\t\tif (oldtype == type) return ret;\n\t\t\t\tPy_INCREF(oldtype);\n\t\t\t\tPy_DECREF(PyArray_DESCR(ret));\n\t\t\t\tPyArray_DESCR(ret) = oldtype;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (copy) {\n\t\tflags = ENSURECOPY;\n\t}\n\tif (fortran!=PyArray_FALSE && \\\n\t ((fortran == PyArray_TRUE) ||\n\t (PyArray_Check(op) && PyArray_ISFORTRAN(op)))) {\n\t\tflags |= FORTRAN;\n\t}\n\tif (!subok) {\n flags |= ENSUREARRAY;\n }\n\n\tif ((ret = PyArray_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\n}\n\n/* accepts NULL type */\n/* steals referenct to type */\n/*MULTIARRAY_API\n Empty\n*/\nstatic PyObject *\nPyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n \n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type, nd, dims, \n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n PyArray_FillObjectArray(ret, Py_None);\n\t}\n\treturn (PyObject *)ret;\n}\n\n\nstatic char doc_empty[] = \"empty((d1,...,dn),dtype=int,fortran=0) will return a new array\\n of shape (d1,...,dn) and given type with all its entries uninitialized. This can be faster than zeros.\";\n\nstatic PyObject *\narray_empty(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter, &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Empty(shape.len, shape.ptr, typecode, fortran); \n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_scalar[] = \"scalar(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype corresponds to an OBJECT descriptor, then obj can be any object, otherwise obj must be a string. If obj is not given it will be interpreted as None for object type and zeros for all other types.\";\n\nstatic PyObject *\narray_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"dtype\",\"obj\", NULL};\n\tPyArray_Descr *typecode;\n\tPyObject *obj=NULL;\n\tint alloc=0;\n\tvoid *dptr;\n\tPyObject *ret;\n\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|O\",\n\t\t\t\t\t kwlist, &PyArrayDescr_Type, \n\t\t\t\t\t &typecode,\n\t\t\t\t\t &obj)) \n\t\treturn NULL;\n\t\t\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\t\t\\\n\t\t\t\t\"itemsize cannot be zero\");\n\t\treturn NULL;\n\t}\n\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (obj == NULL) obj = Py_None;\n\t\tdptr = &obj;\n\t}\n\telse {\n\t\tif (obj == NULL) {\n\t\t\tdptr = _pya_malloc(typecode->elsize);\n\t\t\tif (dptr == NULL) {\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemset(dptr, '\\0', typecode->elsize);\n\t\t\talloc = 1;\n\t\t}\n\t\telse {\n\t\t\tif (!PyString_Check(obj)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"initializing object must \"\\\n\t\t\t\t\t\t\"be a string\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tif (PyString_GET_SIZE(obj) < typecode->elsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"initialization string is too\"\\\n\t\t\t\t\t\t\" small\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdptr = PyString_AS_STRING(obj);\n\t\t}\n\t}\n\n\tret = PyArray_Scalar(dptr, typecode, NULL);\n\t\n\t/* free dptr which contains zeros */\n\tif (alloc) _pya_free(dptr);\n\treturn ret;\n}\n\n\n/* steal a reference */\n/* accepts NULL type */\n/*MULTIARRAY_API\n Zeros\n*/\nstatic PyObject *\nPyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n\tintp n;\n\n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type,\n\t\t\t\t\t\t nd, dims, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n\t\tPyObject *zero = PyInt_FromLong(0);\n PyArray_FillObjectArray(ret, zero);\n Py_DECREF(zero);\n\t}\n\telse {\n\t\tn = PyArray_NBYTES(ret);\n\t\tmemset(ret->data, 0, n);\n\t}\n\treturn (PyObject *)ret;\n\n}\n\nstatic char doc_zeros[] = \"zeros((d1,...,dn),dtype=int,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.\";\n\n\nstatic PyObject *\narray_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL}; /* XXX ? */\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Zeros(shape.len, shape.ptr, typecode, (int) fortran);\n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_set_typeDict[] = \"set_typeDict(dict) set the internal \"\\\n\t\"dictionary that can look up an array type using a registered \"\\\n\t\"code\";\n\nstatic PyObject *\narray_set_typeDict(PyObject *ignored, PyObject *args)\n{\n\tPyObject *dict;\n\tif (!PyArg_ParseTuple(args, \"O\", &dict)) return NULL;\n\tPy_XDECREF(typeDict); /* Decrement old reference (if any)*/\n\ttypeDict = dict;\n\tPy_INCREF(dict); /* Create an internal reference to it */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\n\t\n\titemsize = dtype->elsize;\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"zero-valued itemsize\");\n\t\tPy_DECREF(dtype);\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_fromString[] = \"fromstring(string, dtype=int, count=-1, sep='') returns a new 1d array initialized from the raw binary data in string. If count is positive, the new array will have count elements, otherwise it's size is determined by the size of string. If sep is not empty then the string is interpreted in ASCII mode and converted to the desired number type using sep as the separator between elements (extra whitespace is ignored).\";\n\nstatic PyObject *\narray_fromString(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tchar *data;\n\tlonglong nin=-1;\n\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", kwlist, \n\t\t\t\t\t &data, &s, \n\t\t\t\t\t PyArray_DescrConverter, &descr,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\n}\n\n/* This needs an open file object and reads it in directly. \n memory-mapped files handled differently through buffer interface.\n\nfile pointer number in resulting 1d array \n(can easily reshape later, -1 for to end of file)\ntype of array\nsep is a separator string for character-based data (or NULL for binary)\n \" \" means whitespace\n*/\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep)\n{\n\tPyArrayObject *r;\n\tsize_t nread = 0;\n\tPyArray_ScanFunc *scan;\n\tBool binary;\n\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"0-sized elements.\");\n\t\tPy_DECREF(typecode);\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\n\tif (num == -1 && binary) { /* Get size for binary file*/\n\t\tintp start, numbytes;\n\t\tstart = (intp )ftell(fp);\n\t\tfseek(fp, 0, SEEK_END);\n\t\tnumbytes = (intp )ftell(fp) - start;\n\t\trewind(fp);\n\t\tif (numbytes == -1) {\n\t\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\t\"could not seek in file\");\n\t\t\tPy_DECREF(typecode);\n\t\t\treturn NULL;\n\t\t}\n\t\tnum = numbytes / typecode->elsize;\n\t}\n\t\n\tif (binary) { /* binary data */\n\t\tr = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t 0, NULL);\n\t\tif (r==NULL) return NULL;\n\t\tnread = fread(r->data, typecode->elsize, num, fp);\n\t}\n\telse { /* character reading */\n\t\tintp i;\n\t\tchar *dptr;\n\t\tint done=0;\n\n\t\tscan = typecode->f->scanfunc;\n\t\tif (scan == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character files with that \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(typecode);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (num != -1) { /* number to read is known */\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode, \n\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\tdptr = r->data;\n\t\t\tfor (i=0; i < num; i++) {\n\t\t\t\tif (done) break;\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\t\t\t\tif (done < -2) break;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\telse { /* we have to watch for the end of the file and \n\t\t\t reallocate at the end */\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * typecode->elsize;\n\t\t\tdptr = r->data;\n\t\t\twhile (!done) {\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\n\t\t\t\t/* end of file reached trying to \n\t\t\t\t scan value. done is 1 or 2\n\t\t\t\t if end of file reached trying to\n\t\t\t\t scan separator. Still good value.\n\t\t\t\t*/\n\t\t\t\tif (done < -2) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t\tif (!done && thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tr->data = PyDataMem_RENEW(r->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = r->data + (totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tr->data = PyDataMem_RENEW(r->data, nread*r->descr->elsize);\n\t\t\tPyArray_DIM(r,0) = nread;\n\t\t\tnum = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\tif (nread < num) {\n\t\tfprintf(stderr, \"%ld items requested but only %ld read\\n\", \n\t\t\t(long) num, (long) nread);\n\t\tr->data = PyDataMem_RENEW(r->data, nread * r->descr->elsize);\n\t\tPyArray_DIM(r,0) = nread;\n\t}\n\treturn (PyObject *)r;\n}\n\nstatic char doc_fromfile[] = \\\n\t\"fromfile(file=, dtype=int, count=-1, sep='')\\n\"\t\\\n\t\"\\n\"\\\n\t\" Return an array of the given data type from a \\n\"\\\n\t\" (text or binary) file. The file argument can be an open file\\n\"\\\n\t\" or a string with the name of a file to read from. If\\n\"\\\n\t\" count==-1, then the entire file is read, otherwise count is\\n\"\\\n\t\" the number of items of the given type read in. If sep is ''\\n\"\\\n\t\" then read a binary file, otherwise it gives the separator\\n\"\\\n\t\" between elements in a text file.\\n\"\\\n\t\"\\n\"\\\n\t\" WARNING: This function should be used sparingly, as it is not\\n\"\\\n\t\" a platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to read in simply-formatted or binary data quickly.\";\n\nstatic PyObject *\narray_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *file=NULL, *ret;\n\tFILE *fp;\n\tchar *sep=\"\";\n\tchar *mode=NULL;\n\tlonglong nin=-1;\n\tstatic char *kwlist[] = {\"file\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *type=NULL;\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Ls\", kwlist, \n\t\t\t\t\t &file,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\tif (type == NULL) type = PyArray_DescrFromType(PyArray_LONG);\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"rb\";\n\t\telse mode=\"r\";\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), mode);\n\t\tif (file==NULL) return NULL;\n\t}\n\telse {\n\t\tPy_INCREF(file);\n\t}\n\tfp = PyFile_AsFile(file);\n\tif (fp == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\"first argument must be an open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_FromFile(fp, type, (intp) nin, sep);\n\tPy_DECREF(file);\n\treturn ret;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, \n\t\t intp count, intp offset) \n{\n\tPyArrayObject *ret;\n\tchar *data;\n\tint ts;\n\tintp s, n;\n\tint itemsize;\n\tint write=1;\n\n\n\tif (type->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot create an OBJECT array from memory\"\\\n\t\t\t\t\" buffer\");\n\t\tPy_DECREF(type);\n\t\treturn NULL;\n\t}\n\tif (type->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"itemsize cannot be zero in type\");\n\t\tPy_DECREF(type);\n\t\treturn NULL; \t\t\n\t}\n\n\tif (buf->ob_type->tp_as_buffer == NULL || \\\n\t (buf->ob_type->tp_as_buffer->bf_getwritebuffer == NULL &&\t\\\n\t buf->ob_type->tp_as_buffer->bf_getreadbuffer == NULL)) {\n\t\tPyObject *newbuf;\n\t\tnewbuf = PyObject_GetAttrString(buf, \"__buffer__\");\n\t\tif (newbuf == NULL) {Py_DECREF(type); return NULL;}\n\t\tbuf = newbuf;\n\t}\n\telse {Py_INCREF(buf);}\n\n\tif (PyObject_AsWriteBuffer(buf, (void *)&data, &ts)==-1) {\n\t\twrite = 0;\n\t\tPyErr_Clear();\n\t\tif (PyObject_AsReadBuffer(buf, (void *)&data, &ts)==-1) {\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((offset < 0) || (offset >= ts)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"offset must be positive and smaller than %\"\n\t\t\t INTP_FMT, (intp)ts);\n\t}\n\n\tdata += offset;\n\ts = (intp)ts - offset;\n\tn = (intp)count;\n\titemsize = type->elsize;\n\t\n\tif (n < 0 ) {\n\t\tif (s % itemsize != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tn = s/itemsize;\n\t} else {\n\t\tif (s < n*itemsize) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t type, \n\t\t\t\t\t\t\t 1, &n, \n\t\t\t\t\t\t\t NULL, data, \n\t\t\t\t\t\t\t DEFAULT_FLAGS,\n\t\t\t\t\t\t\t NULL)) == NULL) {\n\t\tPy_DECREF(buf);\n\t\treturn NULL;\n\t}\n\t\n\tif (!write) ret->flags &= ~WRITEABLE;\n\n\t/* Store a reference for decref on deallocation */\n\tret->base = buf;\n\tPyArray_UpdateFlags(ret, ALIGNED);\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_frombuffer[] = \\\n\t\"frombuffer(buffer=, dtype=int, count=-1, offset=0)\\n\"\\\n\t\"\\n\"\t\t\t\t\t\t\t\t\\\n\t\" Returns a 1-d array of data type dtype from buffer. The buffer\\n\"\\\n\t\" argument must be an object that exposes the buffer interface.\\n\"\\\n\t\" If count is -1 then the entire buffer is used, otherwise, count\\n\"\\\n\t\" is the size of the output. If offset is given then jump that\\n\"\\\n\t\" far into the buffer. If the buffer has data that is out\\n\" \\\n\t\" not in machine byte-order, than use a propert data type\\n\"\\\n\t\" descriptor. The data will not\\n\" \\\n\t\" be byteswapped, but the array will manage it in future\\n\"\\\n\t\" operations.\\n\";\n\nstatic PyObject *\narray_frombuffer(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *obj=NULL;\n\tlonglong nin=-1, offset=0;\n\tstatic char *kwlist[] = {\"buffer\", \"dtype\", \"count\", \"offset\", NULL};\n\tPyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&LL\", kwlist, \n\t\t\t\t\t &obj,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &offset)) {\n\t\treturn NULL;\n\t}\n\tif (type==NULL)\n\t\ttype = PyArray_DescrFromType(PyArray_LONG);\n\t\n\treturn PyArray_FromBuffer(obj, type, (intp)nin, (intp)offset);\n}\n\n\nstatic char doc_concatenate[] = \"concatenate((a1,a2,...),axis=None).\";\n\nstatic PyObject *\narray_concatenate(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *a0;\n\tint axis=0;\n\tstatic char *kwlist[] = {\"seq\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist,\n\t\t\t\t\t &a0,\n\t\t\t\t\t PyArray_AxisConverter, &axis))\n\t\treturn NULL;\n\treturn PyArray_Concatenate(a0, axis);\n}\n\nstatic char doc_innerproduct[] = \\\n\t\"inner(a,b) returns the dot product of two arrays, which has\\n\"\\\n\t\"shape a.shape[:-1] + b.shape[:-1] with elements computed by\\n\" \\\n\t\"the product of the elements from the last dimensions of a and b.\";\n\nstatic PyObject *array_innerproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *b0, *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a0, &b0)) return NULL;\n\t\n\treturn _ARET(PyArray_InnerProduct(a0, b0));\n}\n\nstatic char doc_matrixproduct[] = \\\n\t\"dot(a,v) returns matrix-multiplication between a and b. \\n\"\\\n\t\"The product-sum is over the last dimension of a and the \\n\"\\\n\t\"second-to-last dimension of b.\";\n\nstatic PyObject *array_matrixproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *v, *a;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a, &v)) return NULL;\n\t\n\treturn _ARET(PyArray_MatrixProduct(a, v));\n}\n\nstatic char doc_fastCopyAndTranspose[] = \"_fastCopyAndTranspose(a)\";\n\nstatic PyObject *array_fastCopyAndTranspose(PyObject *dummy, PyObject *args) {\n\tPyObject *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &a0)) return NULL;\n\t\n\treturn _ARET(PyArray_CopyAndTranspose(a0));\n}\n\nstatic char doc_correlate[] = \"cross_correlate(a,v, mode=0)\";\n\nstatic PyObject *array_correlate(PyObject *dummy, PyObject *args, PyObject *kwds) {\n\tPyObject *shape, *a0;\n\tint mode=0;\n\tstatic char *kwlist[] = {\"a\", \"v\", \"mode\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO|i\", kwlist, \n\t\t\t\t\t &a0, &shape, &mode)) return NULL;\n\t\n\treturn PyArray_Correlate(a0, shape, mode);\n}\n\n\n/*MULTIARRAY_API\n Arange, \n*/\nstatic PyObject *\nPyArray_Arange(double start, double stop, double step, int type_num)\n{\n\tintp length;\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *obj;\n\tint ret;\n\n\tlength = (intp ) ceil((stop - start)/step);\n \n\tif (length <= 0) {\n\t\tlength = 0;\n\t\treturn PyArray_New(&PyArray_Type, 1, &length, type_num,\n\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t}\n\n\trange = PyArray_New(&PyArray_Type, 1, &length, type_num, \n\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (range == NULL) return NULL;\n\n\tfuncs = PyArray_DESCR(range)->f; \n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tobj = PyFloat_FromDouble(start);\n\tret = funcs->setitem(obj, PyArray_DATA(range), (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 1) return range;\n\n\tobj = PyFloat_FromDouble(start + step);\n\tret = funcs->setitem(obj, PyArray_BYTES(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 2) return range;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\treturn NULL;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\t\n\treturn range;\n\n fail:\n\tPy_DECREF(range);\n\treturn NULL;\n}\n\n/* the formula is \n len = (intp) ceil((start - stop) / step);\n*/\nstatic intp\n_calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, int cmplx)\n{\n\tintp len;\n\tPyObject *val;\n\tdouble value;\n\t\n\t*next = PyNumber_Subtract(stop, start);\n\tif (!(*next)) return -1;\n\tval = PyNumber_TrueDivide(*next, step);\n\tPy_DECREF(*next); *next=NULL;\n\tif (!val) return -1;\n\tif (cmplx && PyComplex_Check(val)) {\n\t\tvalue = PyComplex_RealAsDouble(val);\n\t\tif (error_converting(value)) {Py_DECREF(val); return -1;}\n\t\tlen = (intp) ceil(value);\n\t\tvalue = PyComplex_ImagAsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = MIN(len, (intp) ceil(value));\n\t}\n\telse {\n\t\tvalue = PyFloat_AsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = (intp) ceil(value);\n\t}\n\t\n\tif (len > 0) {\n\t\t*next = PyNumber_Add(start, step);\n\t\tif (!next) return -1;\n\t}\n\treturn len;\n}\n\n/* this doesn't change the references */\n/*MULTIARRAY_API\n ArangeObj,\n*/\nstatic PyObject *\nPyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr *dtype) \n{\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *next;\n\tintp length;\n\n\tif (!dtype) {\n\t\tPyArray_Descr *deftype;\n\t\tPyArray_Descr *newtype;\n\t\tdeftype = PyArray_DescrFromType(PyArray_LONG);\n\t\tnewtype = PyArray_DescrFromObject(start, deftype);\n\t\tPy_DECREF(deftype);\n\t\tdeftype = newtype;\n\t\tif (stop && stop != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(stop, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tif (step && step != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(step, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tdtype = deftype;\n\t}\n\telse Py_INCREF(dtype);\n\n\tif (!step || step == Py_None) {\n\t\tstep = PyInt_FromLong(1);\n\t}\n\telse Py_XINCREF(step);\n\n\tif (!stop || stop == Py_None) {\n\t\tstop = start;\n\t\tstart = PyInt_FromLong(0);\n\t}\n\telse Py_INCREF(start);\n\n\t/* calculate the length and next = start + step*/\n\tlength = _calc_length(start, stop, step, &next, \n\t\t\t PyTypeNum_ISCOMPLEX(dtype->type_num));\n\n\tif (PyErr_Occurred()) {Py_DECREF(dtype); goto fail;}\n\tif (length <= 0) {\n\t\tlength = 0;\n\t\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\t\tPy_DECREF(step); Py_DECREF(start); return range;\n\t}\n\n\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\tif (range == NULL) goto fail;\n\n\tfuncs = PyArray_DESCR(range)->f;\n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tif (funcs->setitem(start, PyArray_DATA(range), (PyArrayObject *)range) < 0)\n\t\tgoto fail;\n\tif (length == 1) goto finish;\n\tif (funcs->setitem(next, PyArray_BYTES(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range) < 0) goto fail;\n\tif (length == 2) goto finish;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\tgoto fail;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\n finish:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_DECREF(next);\n\treturn range;\n\t\n fail:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_XDECREF(next);\n\treturn NULL;\n}\n\n\nstatic char doc_arange[] = \n\"arange([start,] stop[, step,], dtype=None)\\n\\n\"\n\"For integer arguments, just like range() except it returns an array whose type can\\n\"\n\"be specified by the keyword argument dtype.\\n\\n\"\n\"If dtype is not specified, the type of the result is deduced from the type of the\\n\"\n\"arguments.\\n\\n\"\n\"For floating point arguments, the length of the result is ceil((stop - start)/step).\\n\"\n\"This rule may result in the last element of the result be greater than stop.\";\n\nstatic PyObject *\narray_arange(PyObject *ignored, PyObject *args, PyObject *kws) {\n\tPyObject *o_start=NULL, *o_stop=NULL, *o_step=NULL;\n\tstatic char *kwd[]= {\"start\", \"stop\", \"step\", \"dtype\", NULL};\n\tPyArray_Descr *typecode=NULL;\n\t\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|OOO&\", kwd, &o_start,\n\t\t\t\t\t&o_stop, &o_step, \n\t\t\t\t\tPyArray_DescrConverter2,\n\t\t\t\t\t&typecode)) \n\t\treturn NULL;\n\n\treturn PyArray_ArangeObj(o_start, o_stop, o_step, typecode);\n}\n\n/*\nIncluded at the very first so not auto-grabbed and thus not \nlabeled.\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\n}\n\nstatic char \ndoc_set_string_function[] = \"set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.\";\n\nstatic PyObject *\narray_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *op;\n\tint repr=1;\n\tstatic char *kwlist[] = {\"f\", \"repr\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|i\", kwlist, \n\t\t\t\t\t&op, &repr)) return NULL; \n\tif (!PyCallable_Check(op)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"Argument must be callable.\");\n\t\treturn NULL;\n\t}\n\tPyArray_SetStringFunction(op, repr);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char \ndoc_set_ops_function[] = \"set_numeric_ops(op=func, ...) sets some or all of the number methods for all array objects. Don't forget **dict can be used as the argument list. Returns the functions that were replaced -- can be stored and set later.\";\n\nstatic PyObject *\narray_set_ops_function(PyObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *oldops=NULL;\n\t\n\tif ((oldops = PyArray_GetNumericOps())==NULL) return NULL;\n\n\t/* Should probably ensure that objects are at least callable */\n\t/* Leave this to the caller for now --- error will be raised\n\t later when use is attempted \n\t*/\n\tif (kwds && PyArray_SetNumericOps(kwds) == -1) {\n\t\tPy_DECREF(oldops);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"one or more objects not callable\");\n\t\treturn NULL;\n\t}\n\treturn oldops;\n}\n\n\n/*MULTIARRAY_API\n Where\n*/\nstatic PyObject *\nPyArray_Where(PyObject *condition, PyObject *x, PyObject *y)\n{\n\tPyArrayObject *arr;\n\tPyObject *tup=NULL, *obj=NULL;\n\tPyObject *ret=NULL, *zero=NULL;\n\n\n\tarr = (PyArrayObject *)PyArray_FromAny(condition, NULL, 0, 0, 0, NULL);\n\tif (arr == NULL) return NULL;\n\n\tif ((x==NULL) && (y==NULL)) {\n\t\tret = PyArray_Nonzero(arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\n\tif ((x==NULL) || (y==NULL)) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \"either both or neither \"\n\t\t\t\t\"of x and y should be given\");\n\t\treturn NULL;\n\t}\n\n\n\tzero = PyInt_FromLong((long) 0);\n\n\tobj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, \n\t\t\t\t\t\t\t\tn_ops.not_equal));\n\tPy_DECREF(zero);\n\tPy_DECREF(arr);\n\tif (obj == NULL) return NULL;\n\n\ttup = Py_BuildValue(\"(OO)\", y, x);\n\tif (tup == NULL) {Py_DECREF(obj); return NULL;}\n\n\tret = PyArray_Choose((PyAO *)obj, tup);\n\n\tPy_DECREF(obj);\n\tPy_DECREF(tup);\n\treturn ret;\n}\n\nstatic char doc_where[] = \"where(condition, | x, y) is shaped like condition\"\\\n\t\" and has elements of x and y where condition is respectively true or\"\\\n\t\" false. If x or y are not given, then it is equivalent to\"\\\n\t\" nonzero(condition).\";\n\nstatic PyObject *\narray_where(PyObject *ignored, PyObject *args)\n{\n\tPyObject *obj=NULL, *x=NULL, *y=NULL;\n\t\n\tif (!PyArg_ParseTuple(args, \"O|OO\", &obj, &x, &y)) return NULL;\n\n\treturn PyArray_Where(obj, x, y);\n\n}\n\nstatic char doc_lexsort[] = \"lexsort(keys=, axis=-1) returns an array of indexes\"\\\n\t\" similar to argsort except the sorting is done using the provided sorting\"\\\n\t\" keys. First the sort is done using key[0], then the resulting list of\"\\\n\t\" indexes is further manipulated by sorting on key[0]. And so forth\"\\\n\t\" The result is a sort on multiple keys. If the keys represented columns\" \\\n\t\" of a spread-sheet, for example, this would sort using multiple columns.\"\\\n\t\" The keys argument must be a tuple of things that can be converted to \"\\\n\t\" arrays of the same shape.\";\n\nstatic PyObject *\narray_lexsort(PyObject *ignored, PyObject *args, PyObject *kwds)\n{\n\tint axis=-1;\n\tPyObject *obj;\n\tstatic char *kwlist[] = {\"keys\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|i\", kwlist, \n\t\t\t\t\t &PyTuple_Type, &obj, &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_LexSort(obj, axis));\n}\n\n#undef _ARET\n\n\nstatic char doc_register_dtype[] = \\\n\t\"register_dtype(a) registers a new type object -- gives it a typenum\";\n\nstatic PyObject *\narray_register_dtype(PyObject *dummy, PyObject *args)\n{\n\tPyObject *dtype;\n\tint ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &dtype)) return NULL;\n\t\n\tret = PyArray_RegisterDataType((PyTypeObject *)dtype);\n\tif (ret < 0)\n\t\treturn NULL;\n\treturn PyInt_FromLong((long) ret);\n}\n\nstatic char doc_can_cast_safely[] = \\\n\t\"can_cast_safely(from=d1, to=d2) returns True if data type d1 \"\\\n\t\"can be cast to data type d2 without losing precision.\";\n\nstatic PyObject *\narray_can_cast_safely(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *d1=NULL;\n\tPyArray_Descr *d2=NULL;\n\tBool ret;\n\tPyObject *retobj;\n\tstatic char *kwlist[] = {\"from\", \"to\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O&O&\", kwlist, \n\t\t\t\t\tPyArray_DescrConverter, &d1,\n\t\t\t\t\tPyArray_DescrConverter, &d2))\n\t\treturn NULL;\n\tif (d1 == NULL || d2 == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"did not understand one of the types; \"\t\\\n\t\t\t\t\"'None' not accepted\");\n\t\treturn NULL;\n\t}\n\t\t\n\tret = PyArray_CanCastTo(d1, d2);\n\tretobj = (ret ? Py_True : Py_False);\n\tPy_INCREF(retobj);\n\treturn retobj;\n}\n\nstatic char doc_new_buffer[] = \\\n\t\"newbuffer(size) return a new uninitialized buffer object of size \"\n\t\"bytes\";\n\nstatic PyObject *\nnew_buffer(PyObject *dummy, PyObject *args)\n{\n\tint size;\n\n\tif(!PyArg_ParseTuple(args, \"i\", &size))\n\t\treturn NULL;\n\t\n\treturn PyBuffer_New(size);\n}\n\nstatic char doc_buffer_buffer[] = \\\n\t\"getbuffer(obj [,offset[, size]]) create a buffer object from the \"\\\n\t\"given object\\n referencing a slice of length size starting at \"\\\n\t\"offset. Default\\n is the entire buffer. A read-write buffer is \"\\\n\t\"attempted followed by a read-only buffer.\";\n\nstatic PyObject *\nbuffer_buffer(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj;\n\tint offset=0, size=Py_END_OF_BUFFER, n;\n\tvoid *unused;\n\tstatic char *kwlist[] = {\"object\", \"offset\", \"size\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ii\", kwlist, \n\t\t\t\t\t &obj, &offset, &size))\n\t\treturn NULL;\n\n\n\tif (PyObject_AsWriteBuffer(obj, &unused, &n) < 0) {\n\t\tPyErr_Clear();\n\t\treturn PyBuffer_FromObject(obj, offset, size);\t\t\n\t}\n\telse\n\t\treturn PyBuffer_FromReadWriteObject(obj, offset, size);\n}\n\n\nstatic struct PyMethodDef array_module_methods[] = {\n\t{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\n\t{\"set_string_function\", (PyCFunction)array_set_string_function, \n\t METH_VARARGS|METH_KEYWORDS, doc_set_string_function},\n\t{\"set_numeric_ops\", (PyCFunction)array_set_ops_function,\n\t METH_VARARGS|METH_KEYWORDS, doc_set_ops_function},\n\t{\"set_typeDict\", (PyCFunction)array_set_typeDict,\n\t METH_VARARGS, doc_set_typeDict},\n\n\t{\"array\",\t(PyCFunction)_array_fromobject, \n\t METH_VARARGS|METH_KEYWORDS, doc_fromobject},\n\t{\"arange\", (PyCFunction)array_arange, \n\t METH_VARARGS|METH_KEYWORDS, doc_arange},\n\t{\"zeros\",\t(PyCFunction)array_zeros, \n\t METH_VARARGS|METH_KEYWORDS, doc_zeros},\n\t{\"empty\",\t(PyCFunction)array_empty, \n\t METH_VARARGS|METH_KEYWORDS, doc_empty},\n\t{\"scalar\", (PyCFunction)array_scalar,\n\t METH_VARARGS|METH_KEYWORDS, doc_scalar},\n\t{\"where\", (PyCFunction)array_where,\n\t METH_VARARGS, doc_where},\n\t{\"lexsort\", (PyCFunction)array_lexsort,\n\t METH_VARARGS | METH_KEYWORDS, doc_lexsort},\n\t{\"fromstring\",(PyCFunction)array_fromString,\n\t METH_VARARGS|METH_KEYWORDS, doc_fromString},\n\t{\"concatenate\", (PyCFunction)array_concatenate, \n\t METH_VARARGS|METH_KEYWORDS, doc_concatenate},\n\t{\"inner\", (PyCFunction)array_innerproduct, \n\t METH_VARARGS, doc_innerproduct}, \n\t{\"dot\", (PyCFunction)array_matrixproduct, \n\t METH_VARARGS, doc_matrixproduct}, \n\t{\"_fastCopyAndTranspose\", (PyCFunction)array_fastCopyAndTranspose, \n\t METH_VARARGS, doc_fastCopyAndTranspose},\n\t{\"correlate\", (PyCFunction)array_correlate, \n\t METH_VARARGS | METH_KEYWORDS, doc_correlate},\n\t{\"frombuffer\", (PyCFunction)array_frombuffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_frombuffer},\n\t{\"fromfile\", (PyCFunction)array_fromfile,\n\t METH_VARARGS | METH_KEYWORDS, doc_fromfile},\n\t{\"register_dtype\", (PyCFunction)array_register_dtype,\n\t METH_VARARGS, doc_register_dtype},\n\t{\"can_cast\", (PyCFunction)array_can_cast_safely,\n\t METH_VARARGS | METH_KEYWORDS, doc_can_cast_safely},\t\t\n\t{\"newbuffer\", (PyCFunction)new_buffer,\n\t METH_VARARGS, doc_new_buffer},\t\n\t{\"getbuffer\", (PyCFunction)buffer_buffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_buffer_buffer},\t\n\t{NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n#include \"__multiarray_api.c\"\n\n/* Establish scalar-type hierarchy */\n\n/* For dual inheritance we need to make sure that the objects being\n inherited from have the tp->mro object initialized. This is\n not necessarily true for the basic type objects of Python (it is \n checked for single inheritance but not dual in PyType_Ready).\n\n Thus, we call PyType_Ready on the standard Python Types, here.\n*/ \nstatic int\nsetup_scalartypes(PyObject *dict)\n{\n\n\tinitialize_numeric_types();\n\n if (PyType_Ready(&PyBool_Type) < 0) return -1;\n if (PyType_Ready(&PyInt_Type) < 0) return -1;\n if (PyType_Ready(&PyFloat_Type) < 0) return -1;\n if (PyType_Ready(&PyComplex_Type) < 0) return -1;\n if (PyType_Ready(&PyString_Type) < 0) return -1;\n if (PyType_Ready(&PyUnicode_Type) < 0) return -1;\n\n#define SINGLE_INHERIT(child, parent) \\\n Py##child##ArrType_Type.tp_base = &Py##parent##ArrType_Type;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) {\t\t\\\n PyErr_Print(); \\\n PyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1;\t\t\t\t\t\t\\\n }\n \n if (PyType_Ready(&PyGenericArrType_Type) < 0)\n return -1;\n\n SINGLE_INHERIT(Number, Generic);\n SINGLE_INHERIT(Integer, Number);\n SINGLE_INHERIT(Inexact, Number);\n SINGLE_INHERIT(SignedInteger, Integer);\n SINGLE_INHERIT(UnsignedInteger, Integer);\n SINGLE_INHERIT(Floating, Inexact);\n SINGLE_INHERIT(ComplexFloating, Inexact);\n SINGLE_INHERIT(Flexible, Generic);\n SINGLE_INHERIT(Character, Flexible);\n\t\n#define DUAL_INHERIT(child, parent1, parent2) \\\n Py##child##ArrType_Type.tp_base = &Py##parent2##ArrType_Type;\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent2##ArrType_Type,\t\\\n\t\t\t &Py##parent1##_Type);\t\t\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\n\n#define DUAL_INHERIT2(child, parent1, parent2)\t\t\t\t\\\n Py##child##ArrType_Type.tp_base = &Py##parent1##_Type;\t\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent1##_Type,\t\t\\\n\t\t\t &Py##parent2##ArrType_Type);\t\t\\\n\tPy##child##ArrType_Type.tp_richcompare =\t\t\t\\\n\t\tPy##parent1##_Type.tp_richcompare;\t\t\t\\\n\tPy##child##ArrType_Type.tp_compare =\t\t\t\t\\\n\t\tPy##parent1##_Type.tp_compare;\t\t\t\t\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\n\n SINGLE_INHERIT(Bool, Generic);\n SINGLE_INHERIT(Byte, SignedInteger);\n SINGLE_INHERIT(Short, SignedInteger);\n#if SIZEOF_INT == SIZEOF_LONG\n DUAL_INHERIT(Int, Int, SignedInteger);\n#else\n SINGLE_INHERIT(Int, SignedInteger);\n#endif\n DUAL_INHERIT(Long, Int, SignedInteger);\n#if SIZEOF_LONGLONG == SIZEOF_LONG\n DUAL_INHERIT(LongLong, Int, SignedInteger);\n#else\n SINGLE_INHERIT(LongLong, SignedInteger);\n#endif\n\n /* fprintf(stderr, \"tp_free = %p, PyObject_Del = %p, int_tp_free = %p, base.tp_free = %p\\n\", PyIntArrType_Type.tp_free, PyObject_Del, PyInt_Type.tp_free, PySignedIntegerArrType_Type.tp_free);\n\t */\n\tSINGLE_INHERIT(UByte, UnsignedInteger);\n SINGLE_INHERIT(UShort, UnsignedInteger);\n SINGLE_INHERIT(UInt, UnsignedInteger);\n SINGLE_INHERIT(ULong, UnsignedInteger);\n SINGLE_INHERIT(ULongLong, UnsignedInteger);\n\n SINGLE_INHERIT(Float, Floating);\n DUAL_INHERIT(Double, Float, Floating);\n SINGLE_INHERIT(LongDouble, Floating);\n\n SINGLE_INHERIT(CFloat, ComplexFloating);\n DUAL_INHERIT(CDouble, Complex, ComplexFloating);\n SINGLE_INHERIT(CLongDouble, ComplexFloating);\n\n DUAL_INHERIT2(String, String, Character);\n DUAL_INHERIT2(Unicode, Unicode, Character);\n\t\n SINGLE_INHERIT(Void, Flexible);\n \n SINGLE_INHERIT(Object, Generic);\n\n return 0;\n\n#undef SINGLE_INHERIT\n#undef DUAL_INHERIT\n\n\t/* Clean up string and unicode array types so they act more like\n\t strings -- get their tables from the standard types.\n\t*/\n}\n\n/* place a flag dictionary in d */\n\nstatic void\nset_flaginfo(PyObject *d)\n{\n PyObject *s;\n PyObject *newd;\n \n newd = PyDict_New();\n\n PyDict_SetItemString(newd, \"OWNDATA\", s=PyInt_FromLong(OWNDATA));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"FORTRAN\", s=PyInt_FromLong(FORTRAN));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"CONTIGUOUS\", s=PyInt_FromLong(CONTIGUOUS));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"ALIGNED\", s=PyInt_FromLong(ALIGNED));\n Py_DECREF(s);\n\n PyDict_SetItemString(newd, \"UPDATEIFCOPY\", s=PyInt_FromLong(UPDATEIFCOPY));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"WRITEABLE\", s=PyInt_FromLong(WRITEABLE));\n Py_DECREF(s);\n \n PyDict_SetItemString(d, \"_flagdict\", newd);\n Py_DECREF(newd);\n return;\n}\n\n\n/* Initialization function for the module */\n\nDL_EXPORT(void) initmultiarray(void) {\n\tPyObject *m, *d, *s;\n\tPyObject *c_api;\n\n\tif (_multiarray_module_loaded) return;\n\t_multiarray_module_loaded = 1;\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\tif (PyType_Ready(&PyArray_Type) < 0)\n return;\n\n if (setup_scalartypes(d) < 0) goto err;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMultiIter_Type.tp_iter = PyObject_SelfIter;\n\tif (PyType_Ready(&PyArrayIter_Type) < 0)\n\t\treturn; \n \n\tif (PyType_Ready(&PyArrayMapIter_Type) < 0)\n return; \n\n\tif (PyType_Ready(&PyArrayMultiIter_Type) < 0)\n\t\treturn;\n\n\tif (PyType_Ready(&PyArrayDescr_Type) < 0)\n\t\treturn;\n\n\tif (PyType_Ready(&PyArrayFlags_Type) < 0)\n\t\treturn;\n\n\tc_api = PyCObject_FromVoidPtr((void *)PyArray_API, NULL);\n\tif (PyErr_Occurred()) goto err;\n\tPyDict_SetItemString(d, \"_ARRAY_API\", c_api);\n\tPy_DECREF(c_api);\n\tif (PyErr_Occurred()) goto err;\n\n\tMultiArrayError = PyString_FromString (\"multiarray.error\");\n\tPyDict_SetItemString (d, \"error\", MultiArrayError);\n\t\n\ts = PyString_FromString(\"3.0\");\n\tPyDict_SetItemString(d, \"__version__\", s);\n\tPy_DECREF(s);\n Py_INCREF(&PyArray_Type);\n\tPyDict_SetItemString(d, \"ndarray\", (PyObject *)&PyArray_Type);\n Py_INCREF(&PyArrayIter_Type);\n\tPyDict_SetItemString(d, \"flatiter\", (PyObject *)&PyArrayIter_Type);\n Py_INCREF(&PyArrayMultiIter_Type);\n\tPyDict_SetItemString(d, \"broadcast\", \n\t\t\t (PyObject *)&PyArrayMultiIter_Type);\n\tPy_INCREF(&PyArrayDescr_Type);\n\tPyDict_SetItemString(d, \"dtype\", (PyObject *)&PyArrayDescr_Type);\n\n\tPy_INCREF(&PyArrayFlags_Type);\n\tPyDict_SetItemString(d, \"flagsobj\", (PyObject *)&PyArrayFlags_Type);\n\n set_flaginfo(d);\n\n\tif (set_typeinfo(d) != 0) goto err;\n\n\t_numpy_internal =\t\t\t\t\t\t\\\n\t\tPyImport_ImportModule(\"numpy.core._internal\");\n\tif (_numpy_internal != NULL) return;\n\n err:\t\n\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\n\treturn;\n}\n\n", + "source_code_before": "/*\n Python Multiarray Module -- A useful collection of functions for creating and\n using ndarrays\n\n Original file \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n Modified extensively for numpy in 2005 \n\n Travis E. Oliphant\n Assistant Professor at\n Brigham Young University\n \n*/\n\n/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */\n\n#include \"Python.h\"\n#include \"structmember.h\"\n/*#include \n#include \n*/\n\n#define _MULTIARRAYMODULE\n#include \"numpy/arrayobject.h\"\n\n#define PyAO PyArrayObject\n\nstatic PyObject *typeDict=NULL; /* Must be explicitly loaded */\nstatic PyObject *_numpy_internal=NULL; /* A Python module for callbacks */\nstatic int _multiarray_module_loaded=0;\n\nstatic PyArray_Descr *\n_arraydescr_fromobj(PyObject *obj)\n{\n\tPyObject *dtypedescr;\n\tPyArray_Descr *new;\n\tint ret;\n\t\n\tdtypedescr = PyObject_GetAttrString(obj, \"dtype\");\n\tPyErr_Clear();\n\tif (dtypedescr) {\n\t\tret = PyArray_DescrConverter(dtypedescr, &new);\n\t\tPy_DECREF(dtypedescr);\n\t\tif (ret) return new;\n\t\tPyErr_Clear();\n\t}\n\treturn NULL;\n}\n\n\n/* Including this file is the only way I know how to declare functions\n static in each file, and store the pointers from functions in both\n arrayobject.c and multiarraymodule.c for the C-API \n\n Declarying an external pointer-containing variable in arrayobject.c\n and trying to copy it to PyArray_API, did not work.\n\n Think about two modules with a common api that import each other...\n\n This file would just be the module calls. \n*/\n\n#include \"arrayobject.c\"\n\n\n/* An Error object -- rarely used? */\nstatic PyObject *MultiArrayError;\n\n/*MULTIARRAY_API\n Multiply a List of ints\n*/\nstatic int\nPyArray_MultiplyIntList(register int *l1, register int n) \n{\n\tregister int s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Multiply a List\n*/\nstatic intp \nPyArray_MultiplyList(register intp *l1, register int n) \n{\n\tregister intp s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Produce a pointer into array\n*/\nstatic void *\nPyArray_GetPtr(PyArrayObject *obj, register intp* ind)\n{\n\tregister int n = obj->nd;\n\tregister intp *strides = obj->strides;\n\tregister char *dptr = obj->data;\n\t\n\twhile (n--) dptr += (*strides++) * (*ind++);\n\treturn (void *)dptr;\n}\n\n/*MULTIARRAY_API\n Get axis from an object (possibly None) -- a converter function,\n*/\nstatic int \nPyArray_AxisConverter(PyObject *obj, int *axis)\n{\n\tif (obj == Py_None) {\n\t\t*axis = MAX_DIMS;\n\t}\n\telse {\n\t\t*axis = (int) PyInt_AsLong(obj);\n\t\tif (PyErr_Occurred()) {\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Compare Lists\n*/\nstatic int \nPyArray_CompareLists(intp *l1, intp *l2, int n) \n{\n int i;\n for(i=0;iob_type;\n\t\n\tPy_INCREF(self->descr);\n\tnew = PyArray_NewFromDescr(subtype,\n\t\t\t\t self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides,\n\t\t\t\t self->data,\n\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (new==NULL) return NULL;\n\tPy_INCREF(self);\n PyArray_BASE(new) = (PyObject *)self;\n\t\n\tif (type != NULL) {\n\t\tif (PyObject_SetAttrString(new, \"dtype\",\n\t\t\t\t\t (PyObject *)type) < 0) {\n\t\t\tPy_DECREF(new);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tPy_DECREF(type);\n\t}\n\treturn new;\t\n}\n\n/*MULTIARRAY_API\n Ravel\n*/\nstatic PyObject *\nPyArray_Ravel(PyArrayObject *a, int fortran)\n{\n\tPyArray_Dims newdim = {NULL,1};\n\tintp val[1] = {-1};\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tnewdim.ptr = val;\n\tif (!fortran && PyArray_ISCONTIGUOUS(a)) {\n\t\tif (a->nd == 1) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\treturn PyArray_Newshape(a, &newdim);\n\t}\n\telse\n\t return PyArray_Flatten(a, fortran);\n}\n\nstatic double\npower_of_ten(int n)\n{\n\tstatic const double p10[] = {1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8};\n\tdouble ret;\n\tif (n < 9)\n\t\tret = p10[n];\n\telse {\n\t\tret = 1e9;\n\t\twhile (n-- > 9)\n\t\t\tret *= 10.;\n\t}\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Round\n*/\nstatic PyObject *\nPyArray_Round(PyArrayObject *a, int decimals)\n{\n\tif (PyArray_ISCOMPLEX(a)) {\n\t\tPyObject *part;\n\t\tPyObject *round_part;\n\t\tPyObject *new;\n\t\tint res;\n\t\tnew = PyArray_Copy(a);\n\t\tif (new == NULL) return NULL;\n\n\t\t/* new.real = a.real.round(decimals) */\n\t\tpart = PyObject_GetAttrString(new, \"real\");\n\t\tif (part == NULL) {Py_DECREF(new); return NULL;}\n\t\tround_part = PyArray_Round\\\n\t\t\t((PyArrayObject *)PyArray_EnsureAnyArray(part), \n\t\t\t decimals);\n\t\tPy_DECREF(part);\n\t\tif (round_part == NULL) {Py_DECREF(new); return NULL;}\n\t\tres = PyObject_SetAttrString(new, \"real\", round_part);\n\t\tPy_DECREF(round_part);\n\t\tif (res < 0) {Py_DECREF(new); return NULL;}\n\n\t\t/* new.imag = a.imag.round(decimals) */\n\t\tpart = PyObject_GetAttrString(new, \"imag\");\n\t\tif (part == NULL) {Py_DECREF(new); return NULL;}\n\t\tround_part = PyArray_Round\\\n\t\t\t((PyArrayObject *)PyArray_EnsureAnyArray(part), \n\t\t\t decimals);\n\t\tPy_DECREF(part);\n\t\tif (round_part == NULL) {Py_DECREF(new); return NULL;}\n\t\tres = PyObject_SetAttrString(new, \"imag\", round_part);\n\t\tPy_DECREF(round_part);\n\t\tif (res < 0) {Py_DECREF(new); return NULL;}\n\t\treturn new;\n\t}\n\t/* do the most common case first */\n\tif (decimals == 0) {\n\t\tif (PyArray_ISINTEGER(a)) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\treturn PyArray_GenericUnaryFunction((PyAO *)a, n_ops.rint);\n\t}\n\tif (decimals > 0) {\n\t\tPyObject *f, *ret;\n\t\tif (PyArray_ISINTEGER(a)) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\tf = PyFloat_FromDouble(power_of_ten(decimals));\n\t\tif (f==NULL) return NULL;\n\t\tret = PyNumber_Multiply((PyObject *)a, f);\n\t\tif (ret==NULL) {Py_DECREF(f); return NULL;}\n\t\tif (PyArray_IsScalar(ret, Generic)) {\n\t\t\t/* array scalars cannot be modified inplace */\n\t\t\tPyObject *tmp;\n\t\t\ttmp = PyObject_CallFunction(n_ops.rint, \"O\", ret);\n\t\t\tPy_DECREF(ret);\n\t\t\tret = PyObject_CallFunction(n_ops.divide, \"OO\", \n\t\t\t\t\t\t tmp, f);\n\t\t\tPy_DECREF(tmp);\n\t\t} else {\n\t\t\tPyObject_CallFunction(n_ops.rint, \"OO\", ret, ret);\n\t\t\tPyObject_CallFunction(n_ops.divide, \"OOO\", ret, \n\t\t\t\t\t f, ret);\n\t\t}\n\t\tPy_DECREF(f);\n\t\treturn ret;\n\t} \n\telse {\n\t\t/* remaining case: decimals < 0 */\n\t\tPyObject *f, *ret;\n\t\tf = PyFloat_FromDouble(power_of_ten(-decimals));\n\t\tif (f==NULL) return NULL;\n\t\tret = PyNumber_Divide((PyObject *)a, f);\n\t\tif (ret==NULL) {Py_DECREF(f); return NULL;}\n\t\tif (PyArray_IsScalar(ret, Generic)) {\n\t\t\t/* array scalars cannot be modified inplace */\n\t\t\tPyObject *tmp;\n\t\t\ttmp = PyObject_CallFunction(n_ops.rint, \"O\", ret);\n\t\t\tPy_DECREF(ret);\n\t\t\tret = PyObject_CallFunction(n_ops.multiply, \"OO\", \n\t\t\t\t\t\t tmp, f);\n\t\t\tPy_DECREF(tmp);\n\t\t} else {\n\t\t\tPyObject_CallFunction(n_ops.rint, \"OO\", ret, ret);\n\t\t\tPyObject_CallFunction(n_ops.multiply, \"OOO\", ret, \n\t\t\t\t\t f, ret);\n\t\t}\n\t\tPy_DECREF(f);\n\t\treturn ret;\n\t}\n}\n\n\n/*MULTIARRAY_API\n Flatten\n*/\nstatic PyObject *\nPyArray_Flatten(PyArrayObject *a, int fortran)\n{\n\tPyObject *ret, *new;\n\tintp size;\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tsize = PyArray_SIZE(a);\n\tPy_INCREF(a->descr);\n\tret = PyArray_NewFromDescr(a->ob_type,\n\t\t\t\t a->descr,\n\t\t\t\t 1, &size,\n\t\t\t\t NULL,\n\t\t\t\t NULL,\n\t\t\t\t 0, (PyObject *)a);\n\t\n\tif (ret== NULL) return NULL;\n\tif (fortran) {\n\t\tnew = PyArray_Transpose(a, NULL);\n\t\tif (new == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tPy_INCREF(a);\n\t\tnew = (PyObject *)a;\n\t}\n\tif (PyArray_CopyInto((PyArrayObject *)ret, (PyArrayObject *)new) < 0) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn NULL;\n\t}\n\tPy_DECREF(new);\n\treturn ret;\n}\n\n\n/* For back-ward compatability *\n\n/ * Not recommended */\n\n/*MULTIARRAY_API\n Reshape an array\n*/\nstatic PyObject *\nPyArray_Reshape(PyArrayObject *self, PyObject *shape) \n{\n PyObject *ret;\n PyArray_Dims newdims;\n\n if (!PyArray_IntpConverter(shape, &newdims)) return NULL;\n ret = PyArray_Newshape(self, &newdims);\n PyDimMem_FREE(newdims.ptr);\n return ret;\n}\n\nstatic int\n_check_ones(PyArrayObject *self, int newnd, intp* newdims, intp *strides)\n{\n\tint nd;\n\tintp *dims;\n\tBool done=FALSE;\n\tint j, k;\n\n\tnd = self->nd;\n\tdims = self->dimensions;\n\n\tfor (k=0, j=0; !done && (jstrides[j];\n\t\t\tj++; k++;\n\t\t}\n\t\telse if ((kptr;\n PyArrayObject *ret;\n\tchar msg[] = \"total size of new array must be unchanged\";\n\tint n = newdims->len;\n Bool same;\n\tintp *strides = NULL;\n\tintp newstrides[MAX_DIMS];\n\n /* Quick check to make sure anything needs to be done */\n if (n == self->nd) {\n same = TRUE;\n i=0;\n while(same && i= 0) {\n\t\t\tif ((s_known == 0) || (s_original % s_known != 0)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdimensions[i_unknown] = s_original/s_known;\n\t\t} else {\n\t\t\tif (s_original != s_known) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t}\n \n\tPy_INCREF(self->descr);\n\tret = (PyAO *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t self->descr,\n\t\t\t\t\t n, dimensions,\n\t\t\t\t\t strides,\n\t\t\t\t\t self->data,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (ret== NULL) return NULL;\n\t\n Py_INCREF(self);\n ret->base = (PyObject *)self;\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\n\t\n return (PyObject *)ret;\n}\n\n/* return a new view of the array object with all of its unit-length \n dimensions squeezed out if needed, otherwise\n return the same array.\n */\n\n/*MULTIARRAY_API*/\nstatic PyObject *\nPyArray_Squeeze(PyArrayObject *self)\n{\n\tint nd = self->nd;\n\tint newnd = nd;\n\tintp dimensions[MAX_DIMS];\n\tintp strides[MAX_DIMS];\n\tint i,j;\n\tPyObject *ret;\n\n\tif (nd == 0) {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\tfor (j=0, i=0; idimensions[i] == 1) {\n\t\t\tnewnd -= 1;\n\t\t}\n\t\telse {\n\t\t\tdimensions[j] = self->dimensions[i];\n\t\t\tstrides[j++] = self->strides[i];\n\t\t}\n\t}\n\t\n\tPy_INCREF(self->descr);\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t self->descr,\n\t\t\t\t newnd, dimensions, \n\t\t\t\t strides, self->data, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPyArray_FLAGS(ret) &= ~OWN_DATA;\n\tPyArray_BASE(ret) = (PyObject *)self;\n\tPy_INCREF(self);\n\treturn (PyObject *)ret;\n}\n\n\n/*MULTIARRAY_API\n Mean\n*/\nstatic PyObject *\nPyArray_Mean(PyArrayObject *self, int axis, int rtype)\n{\n\tPyObject *obj1=NULL, *obj2=NULL;\n\tPyObject *new, *ret;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\n\tobj1 = PyArray_GenericReduceFunction((PyAO *)new, n_ops.add, axis,\n\t\t\t\t\t rtype);\n\tobj2 = PyFloat_FromDouble((double) PyArray_DIM(new,axis));\n Py_DECREF(new);\n\tif (obj1 == NULL || obj2 == NULL) {\n\t\tPy_XDECREF(obj1);\n\t\tPy_XDECREF(obj2);\n\t\treturn NULL;\n\t}\n\n\tret = PyNumber_Divide(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n}\n\n/* Set variance to 1 to by-pass square-root calculation and return variance */\n/*MULTIARRAY_API\n Std\n*/\nstatic PyObject *\nPyArray_Std(PyArrayObject *self, int axis, int rtype, int variance)\n{\n\tPyObject *obj1=NULL, *obj2=NULL, *new=NULL;\n\tPyObject *ret=NULL, *newshape=NULL;\n\tint i, n;\n\tintp val;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\t\n\t/* Compute and reshape mean */\n\tobj1 = PyArray_EnsureArray(PyArray_Mean((PyAO *)new, axis, rtype));\n\tif (obj1 == NULL) {Py_DECREF(new); return NULL;} \n\tn = PyArray_NDIM(new);\n\tnewshape = PyTuple_New(n);\n\tif (newshape == NULL) {Py_DECREF(obj1); Py_DECREF(new); return NULL;}\n\tfor (i=0; ind != 1) {\n Py_DECREF(cond);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"condition must be 1-d array\");\n return NULL;\n }\n\n res = PyArray_Nonzero(cond);\n Py_DECREF(cond);\n\tret = PyArray_Take(self, res, axis);\n\tPy_DECREF(res);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Nonzero\n*/\nstatic PyObject *\nPyArray_Nonzero(PyArrayObject *self)\n{\n int n=self->nd, j;\n\tintp count=0, i, size;\n\tPyArrayIterObject *it=NULL;\n\tPyObject *ret=NULL, *item;\n\tintp *dptr[MAX_DIMS];\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (it==NULL) return NULL;\n\n\tsize = it->size;\n\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) count++;\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\n\tPyArray_ITER_RESET(it);\n\tif (n==1) {\n\t\tret = PyArray_New(self->ob_type, 1, &count, PyArray_INTP, \n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)self);\n\t\tif (ret == NULL) goto fail;\n\t\tdptr[0] = (intp *)PyArray_DATA(ret);\n\t\t\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\t*(dptr[0])++ = i;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\t\t\n\t}\n\telse {\n\t\tret = PyTuple_New(n);\n\t\tfor (j=0; job_type, 1, &count, \n\t\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0,\n\t\t\t\t\t (PyObject *)self);\n\t\t\tif (item == NULL) goto fail;\n\t\t\tPyTuple_SET_ITEM(ret, j, item);\n\t\t\tdptr[j] = (intp *)PyArray_DATA(item);\n\t\t}\n\t\t\n\t\t/* reset contiguous so that coordinates gets updated */\n\t\tit->contiguous = 0;\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\tfor (j=0; jcoordinates[j];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\n\n\tPy_DECREF(it);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(ret);\n\tPy_XDECREF(it);\n\treturn NULL;\n \n}\n\n/*MULTIARRAY_API\n Clip\n*/\nstatic PyObject *\nPyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max)\n{\n\tPyObject *selector=NULL, *newtup=NULL, *ret=NULL;\n\tPyObject *res1=NULL, *res2=NULL, *res3=NULL;\n\tPyObject *two;\n\n\ttwo = PyInt_FromLong((long)2);\n\tres1 = PyArray_GenericBinaryFunction(self, max, n_ops.greater);\n\tres2 = PyArray_GenericBinaryFunction(self, min, n_ops.less);\n\tif ((res1 == NULL) || (res2 == NULL)) {\n\t\tPy_DECREF(two);\n\t\tPy_XDECREF(res1);\n\t\tPy_XDECREF(res2);\n\t}\n\tres3 = PyNumber_Multiply(two, res1);\n\tPy_DECREF(two); \n\tPy_DECREF(res1); \n\tif (res3 == NULL) return NULL;\n\n\tselector = PyArray_EnsureArray(PyNumber_Add(res2, res3));\n\tPy_DECREF(res2);\n\tPy_DECREF(res3);\n\tif (selector == NULL) return NULL;\n\n\tnewtup = Py_BuildValue(\"(OOO)\", (PyObject *)self, min, max);\n\tif (newtup == NULL) {Py_DECREF(selector); return NULL;}\n\tret = PyArray_Choose((PyAO *)selector, newtup);\n\tPy_DECREF(selector);\n\tPy_DECREF(newtup);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Conjugate\n*/\nstatic PyObject *\nPyArray_Conjugate(PyArrayObject *self)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyObject *new;\n\t\tintp size, i;\n\t\t/* Make a copy */\n\t\tnew = PyArray_NewCopy(self, -1);\n\t\tif (new==NULL) return NULL;\n\t\tsize = PyArray_SIZE(new);\n\t\tif (self->descr->type_num == PyArray_CFLOAT) {\n\t\t\tcfloat *dptr = (cfloat *) PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CDOUBLE) {\n\t\t\tcdouble *dptr = (cdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CLONGDOUBLE) {\n\t\t\tclongdouble *dptr = (clongdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\t\t\t\n\t\t}\t\t\n\t\treturn new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *) self;\n\t}\n}\n\n/*MULTIARRAY_API\n Trace\n*/\nstatic PyObject *\nPyArray_Trace(PyArrayObject *self, int offset, int axis1, int axis2, \nint rtype)\n{\n\tPyObject *diag=NULL, *ret=NULL;\n\n\tdiag = PyArray_Diagonal(self, offset, axis1, axis2);\n\tif (diag == NULL) return NULL;\n\tret = PyArray_GenericReduceFunction((PyAO *)diag, n_ops.add, -1, rtype);\n\tPy_DECREF(diag);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Diagonal\n*/\nstatic PyObject *\nPyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)\n{\n\tint n = self->nd;\n\tPyObject *new;\n\tPyArray_Dims newaxes;\n\tintp dims[MAX_DIMS];\n\tint i, pos;\t\n\n\tnewaxes.ptr = dims;\n\tif (n < 2) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"array.ndim must be >= 2\");\n\t\treturn NULL;\n\t}\n\tif (axis1 < 0) axis1 += n;\n\tif (axis2 < 0) axis2 += n;\n\tif ((axis1 == axis2) || (axis1 < 0) || (axis1 >= n) ||\t\\\n\t (axis2 < 0) || (axis2 >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \"axis1(=%d) and axis2(=%d) \"\\\n\t\t\t \"must be different and within range (nd=%d)\",\n\t\t\t axis1, axis2, n);\n\t\treturn NULL;\n\t}\n \n\tnewaxes.len = n;\n\t/* insert at the end */\n\tnewaxes.ptr[n-2] = axis1;\n\tnewaxes.ptr[n-1] = axis2;\n\tpos = 0;\n\tfor (i=0; idimensions[0];\n\t\tn2 = self->dimensions[1];\n\t\tstep = n2+1;\n\t\tif (offset < 0) {\n\t\t\tstart = -n2 * offset;\n\t\t\tstop = MIN(n2, n1+offset)*(n2+1) - n2*offset;\n\t\t}\n\t\telse {\n\t\t\tstart = offset;\n\t\t\tstop = MIN(n1, n2-offset)*(n2+1) + offset;\n\t\t}\n\t\t\n\t\t/* count = ceil((stop-start)/step) */\n\t\tcount = ((stop-start) / step) + (((stop-start) % step) != 0);\n\t\t\t\n\t\tindices = PyArray_New(&PyArray_Type, 1, &count, \n\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0, NULL);\n\t\tif (indices == NULL) {\n\t\t\tPy_DECREF(self); return NULL;\n\t\t}\n\t\tdptr = (intp *)PyArray_DATA(indices);\n\t\tfor (n1=start; n1descr;\n\n\t\tmydiagonal = PyList_New(0);\n\t\tif (mydiagonal == NULL) {Py_DECREF(self); return NULL;}\n\t\tn1 = self->dimensions[0];\n\t\tfor (i=0; i 3)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"C arrays of only 1-3 dimensions available\");\n\t\tPy_XDECREF(typedescr);\n\t\treturn -1;\n\t}\n\tif ((ap = (PyArrayObject*)PyArray_FromAny(*op, typedescr, nd, nd,\n\t\t\t\t\t\t CARRAY_FLAGS, NULL)) == NULL)\n\t\treturn -1;\n\tswitch(nd) {\n\tcase 1:\n\t\t*((char **)ptr) = ap->data;\n\t\tbreak;\n\tcase 2:\n\t\tn = ap->dimensions[0];\n\t\tptr2 = (char **)_pya_malloc(n * sizeof(char *));\n\t\tif (!ptr2) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0];\n\t\t}\n\t\t*((char ***)ptr) = ptr2;\n\t\tbreak;\t\t\n\tcase 3:\n\t\tn = ap->dimensions[0];\n\t\tm = ap->dimensions[1];\n\t\tptr3 = (char ***)_pya_malloc(n*(m+1) * sizeof(char *));\n\t\tif (!ptr3) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0] + \\\n\t\t\t\t\tj*ap->strides[1];\n\t\t\t}\n\t\t}\n\t\t*((char ****)ptr) = ptr3;\n\t}\n\tmemcpy(dims, ap->dimensions, nd*sizeof(intp));\n\t*op = (PyObject *)ap;\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_MemoryError, \"no memory\");\n\treturn -1;\n}\n\n/* Deprecated --- Use PyArray_AsCArray instead */\n\n/*MULTIARRAY_API\n Convert to a 1D C-array\n*/\nstatic int \nPyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) \n{\n\tintp newd1;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, descr) == -1)\n\t\treturn -1;\t\n\t*d1 = (int) newd1;\n\treturn 0;\n}\n\n/*MULTIARRAY_API\n Convert to a 2D C-array\n*/\nstatic int \nPyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) \n{\n\tintp newdims[2];\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, newdims, 2, descr) == -1)\n\t\treturn -1;\n\n\t*d1 = (int ) newdims[0];\n\t*d2 = (int ) newdims[1];\n return 0;\n}\n\n/* End Deprecated */\n\n/*MULTIARRAY_API\n Free pointers created if As2D is called\n*/\nstatic int \nPyArray_Free(PyObject *op, void *ptr) \n{\n PyArrayObject *ap = (PyArrayObject *)op;\n\t\n if ((ap->nd < 1) || (ap->nd > 3)) \n\t\treturn -1;\n if (ap->nd >= 2) {\n\t\t_pya_free(ptr);\n }\n Py_DECREF(ap);\n return 0;\n}\n\n\nstatic PyObject *\n_swap_and_concat(PyObject *op, int axis, int n)\n{\n\tPyObject *newtup=NULL;\n\tPyObject *otmp, *arr;\n\tint i;\n\n\tnewtup = PyTuple_New(n);\n\tif (newtup==NULL) return NULL;\n\tfor (i=0; i= MAX_DIMS) {\n\t\t\totmp = PyArray_Ravel(mps[i],0);\n\t\t\tPy_DECREF(mps[i]);\n\t\t\tmps[i] = (PyArrayObject *)otmp;\n\t\t}\n\t\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\n\t\t}\n\t}\n\t\n\tnew_dim = 0;\n\tfor(i=0; ind;\n\t\telse {\n\t\t\tif (nd != mps[i]->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"arrays must have same \"\\\n\t\t\t\t\t\t\"number of dimensions\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CompareLists(mps[0]->dimensions+1, \n\t\t\t\t\t\t mps[i]->dimensions+1, \n\t\t\t\t\t\t nd-1)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"array dimensions must \"\\\n\t\t\t\t\t\t\"agree except for d_0\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (nd == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"0-d arrays can't be concatenated\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnew_dim += mps[i]->dimensions[0];\n\t}\n\t\n\ttmp = mps[0]->dimensions[0];\n\tmps[0]->dimensions[0] = new_dim;\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(subtype, \n\t\t\t\t\t\t mps[0]->descr, nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ret);\n\tmps[0]->dimensions[0] = tmp;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tdata = ret->data;\n\tfor(i=0; idata, numbytes);\n\t\tdata += numbytes;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; ind;\n\tif (n <= 1) {\n\t\tPy_INCREF(ap);\n\t\treturn (PyObject *)ap;\n\t}\n\n\tif (a1 < 0) a1 += n;\n\tif (a2 < 0) a2 += n;\n\tif ((a1 < 0) || (a1 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis1 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tif ((a2 < 0) || (a2 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis2 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tnew_axes.ptr = dims;\n\tnew_axes.len = n;\n\n\tfor (i=0; ind;\n\t\tfor(i=0; ilen;\n\t\taxes = permute->ptr;\n\t\tif (n > ap->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many axes for this array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tfor(i=0; ind+axis;\n\t\t\tif (axis < 0 || axis >= ap->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"invalid axis for this array\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tpermutation[i] = axis;\n\t\t}\n\t}\n\t\n\t/* this allocates memory for dimensions and strides (but fills them\n\t incorrectly), sets up descr, and points data at ap->data. */\n\tPy_INCREF(ap->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t ap->descr, \n\t\t\t\t n, permutation, \n\t\t\t\t NULL, ap->data, ap->flags,\n\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) return NULL;\n\t\n\t/* point at true owner of memory: */\n\tret->base = (PyObject *)ap;\n\tPy_INCREF(ap);\n\t\n\tfor(i=0; idimensions[i] = ap->dimensions[permutation[i]];\n\t\tret->strides[i] = ap->strides[permutation[i]];\n\t}\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\t\n\n\treturn (PyObject *)ret;\t\n}\n\n/*MULTIARRAY_API\n Repeat the array.\n*/\nstatic PyObject *\nPyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis)\n{\n\tintp *counts;\n\tintp n, n_outer, i, j, k, chunk, total;\n\tintp tmp;\n\tint nd;\n\tPyArrayObject *repeats=NULL;\n\tPyObject *ap=NULL;\n\tPyArrayObject *ret=NULL;\n\tchar *new_data, *old_data;\n\n\trepeats = (PyAO *)PyArray_ContiguousFromAny(op, PyArray_INTP, 0, 1);\n\tif (repeats == NULL) return NULL;\n\tnd = repeats->nd;\n\tcounts = (intp *)repeats->data;\n\n\tif ((ap=_check_axis(aop, &axis, CARRAY_FLAGS))==NULL) {\n\t\tPy_DECREF(repeats);\n\t\treturn NULL;\n\t}\n\n\taop = (PyAO *)ap;\n\n\tif (nd == 1)\n\t\tn = repeats->dimensions[0];\n\telse /* nd == 0 */\n\t\tn = aop->dimensions[axis];\n\n\tif (aop->dimensions[axis] != n) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"a.shape[axis] != len(repeats)\");\n\t\tgoto fail;\n\t}\n\n\t\n\tif (nd == 0) \n\t\ttotal = counts[0]*n;\n\telse {\n\t\t\n\t\ttotal = 0;\n\t\tfor(j=0; jdimensions[axis] = total;\n\tPy_INCREF(aop->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(aop->ob_type, \n\t\t\t\t\t\t aop->descr,\n\t\t\t\t\t\t aop->nd,\n\t\t\t\t\t\t aop->dimensions,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)aop);\n\taop->dimensions[axis] = n;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tnew_data = ret->data;\n\told_data = aop->data;\n\t\n\tchunk = aop->descr->elsize;\n\tfor(i=axis+1; ind; i++) {\n\t\tchunk *= aop->dimensions[i];\n\t}\n\t\n\tn_outer = 1;\n\tfor(i=0; idimensions[i];\n\n\tfor(i=0; idescr->elsize;\n\tbyteorder = arr->descr->byteorder;\n\tptr = arr->data;\n\tif (elsize > 1 && \\\n\t (byteorder == PyArray_LITTLE ||\t\\\n\t (byteorder == PyArray_NATIVE &&\n\t PyArray_ISNBO(PyArray_LITTLE))))\n\t\tptr += elsize-1;\n\t\n\treturn ((*ptr & bitmask) != 0);\t\n}\n\n\n/*OBJECT_API*/\nstatic PyArray_SCALARKIND\nPyArray_ScalarKind(int typenum, PyArrayObject **arr) \n{\n\tif (PyTypeNum_ISSIGNED(typenum)) {\n\t\tif (arr && _signbit_set(*arr)) return PyArray_INTNEG_SCALAR;\n\t\telse return PyArray_INTPOS_SCALAR;\n\t}\n\tif (PyTypeNum_ISFLOAT(typenum)) return PyArray_FLOAT_SCALAR;\n\tif (PyTypeNum_ISUNSIGNED(typenum)) return PyArray_INTPOS_SCALAR;\n\tif (PyTypeNum_ISCOMPLEX(typenum)) return PyArray_COMPLEX_SCALAR;\n\tif (PyTypeNum_ISBOOL(typenum)) return PyArray_BOOL_SCALAR;\n\n\treturn PyArray_OBJECT_SCALAR;\n}\n\n/*OBJECT_API*/\nstatic int \nPyArray_CanCoerceScalar(char thistype, char neededtype, \n\t\t\tPyArray_SCALARKIND scalar) \n{\n\n\tswitch(scalar) {\n\tcase PyArray_NOSCALAR:\n\tcase PyArray_BOOL_SCALAR:\n\tcase PyArray_OBJECT_SCALAR:\n\t\treturn PyArray_CanCastSafely(thistype, neededtype);\n\tcase PyArray_INTPOS_SCALAR:\n\t\treturn (neededtype >= PyArray_UBYTE);\n\tcase PyArray_INTNEG_SCALAR:\n\t\treturn (neededtype >= PyArray_BYTE) &&\t\t\\\n\t\t\t!(PyTypeNum_ISUNSIGNED(neededtype));\n\tcase PyArray_FLOAT_SCALAR:\n\t\treturn (neededtype >= PyArray_FLOAT);\n\tcase PyArray_COMPLEX_SCALAR:\n\t\treturn (neededtype >= PyArray_CFLOAT);\n\t}\n\tfprintf(stderr, \"\\n**Error** coerce fall through: %d %d %d\\n\\n\", \n\t\tthistype, neededtype, scalar);\n\treturn 1; /* should never get here... */ \n}\n\n\n/* This needs to change to allow scalars of a different \"kind\" to alter the input type\n */\n\n/*OBJECT_API*/\nstatic PyArrayObject **\nPyArray_ConvertToCommonType(PyObject *op, int *retn)\n{\n\tint i, n, allscalars=0; \n\tPyArrayObject **mps=NULL;\n\tPyObject *otmp;\n\tPyArray_Descr *intype=NULL, *stype=NULL;\n\tPyArray_Descr *newtype=NULL;\n\tchar scalarkind;\n\n\t\n\t*retn = n = PySequence_Length(op);\n\tif (PyErr_Occurred()) {*retn = 0; return NULL;}\n\t\n\tmps = (PyArrayObject **)PyDataMem_NEW(n*sizeof(PyArrayObject *));\n\tif (mps == NULL) {\n\t\t*retn = 0;\n\t\treturn (void*)PyErr_NoMemory();\n\t}\n\t\n\tfor(i=0; itype_num, NULL);\n\t\t\tif (intype && !PyArray_CanCoerceScalar(newtype->type_num,\n\t\t\t\t\t\t\t intype->type_num, \n\t\t\t\t\t\t\t scalarkind)) {\n\t\t\t\tPy_XDECREF(intype);\n\t\t\t\tintype = stype;\n\t\t\t}\n\t\t\tmps[i] = (PyArrayObject *)Py_None;\n\t\t\tPy_INCREF(Py_None);\n\t\t}\n\t\tPy_XDECREF(otmp);\n\t}\n\tif (intype==NULL) { /* all scalars */\n\t\tallscalars = 1;\n\t\tintype = stype;\n\t\tPy_INCREF(intype);\n\t\tfor (i=0; ind < mps[i]->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many dimensions\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (!PyArray_CompareLists(ap->dimensions+(ap->nd-mps[i]->nd),\n\t\t\t\t mps[i]->dimensions, mps[i]->nd)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"array dimensions must agree\");\n\t\t\tgoto fail;\n\t\t}\n\t\tsizes[i] = PyArray_NBYTES(mps[i]);\n\t}\n\t\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t\t\t mps[0]->descr,\n\t\t\t\t\t\t ap->nd,\n\t\t\t\t\t\t ap->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\telsize = ret->descr->elsize;\n\tm = PyArray_SIZE(ret);\n\tself_data = (intp *)ap->data;\n\tret_data = ret->data;\n\t\n\tfor (i=0; i= n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid entry in choice array\");\n\t\t\tgoto fail;\n\t\t}\n\t\toffset = i*elsize;\n\t\tif (offset >= sizes[mi]) {offset = offset % sizes[mi]; }\n\t\tmemmove(ret_data, mps[mi]->data+offset, elsize);\n\t\tret_data += elsize; self_data++;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; idescr->f->sort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize);\n\n\tif (needcopy) {\n\t\tchar *buffer;\n\t\tbuffer = PyDataMem_NEW(N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(buffer, (intp) elsize, it->dataptr, \n\t\t\t\t astride, N, elsize);\n\t\t\tif (sort(buffer, N, op) < 0) {\n\t\t\t\tPyDataMem_FREE(buffer); goto fail;\n\t\t\t}\n\t\t\t_strided_copy(it->dataptr, astride, buffer, \n\t\t\t\t (intp) elsize, N, elsize);\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyDataMem_FREE(buffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tif (sort(it->dataptr, N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\t\n\t\n\tEND_THREADS\n\t\n\tPy_DECREF(it);\n\treturn 0;\n\n fail:\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nstatic PyObject*\n_new_argsort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\n\tPyArrayIterObject *it=NULL;\n\tPyArrayIterObject *rit=NULL;\n\tPyObject *ret;\n\tint needcopy=0, i;\n\tintp N, size;\n\tint elsize;\n\tintp astride, rstride, *iptr;\n\tPyArray_ArgSortFunc *argsort;\n\tBEGIN_THREADS_DEF \n\n\tret = PyArray_New(op->ob_type, op->nd,\n\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) return NULL;\n\n\tit = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)op, axis);\n\trit = (PyArrayIterObject *)PyArray_IterAllButAxis(ret, axis);\n\tif (rit == NULL || it == NULL) goto fail;\n\n\tBEGIN_THREADS\n\n\targsort = op->descr->f->argsort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize) || \\\n\t\t(rstride != sizeof(intp));\n\t\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(elsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(valbuffer, (intp) elsize, it->dataptr,\n\t\t\t\t astride, N, elsize);\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idataptr, rstride, indbuffer, \n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idataptr, (intp *)rit->dataptr, \n\t\t\t\t N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\t\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\tPy_DECREF(rit);\n\treturn ret;\n\n fail:\n\n\tEND_THREADS\n\n\tPy_DECREF(ret);\n\tPy_XDECREF(it);\n\tPy_XDECREF(rit);\n\treturn NULL;\n}\n\n\n/* Be sure to save this global_compare when necessary */\n\nstatic PyArrayObject *global_obj;\n\nstatic int \nqsortCompare (const void *a, const void *b) \n{\n\treturn global_obj->descr->f->compare(a,b,global_obj);\n}\n\n/* Consumes reference to ap (op gets it)\n op contains a version of the array with axes swapped if\n local variable axis is not the last dimension.\n orign must be defined locally. \n*/\n\n#define SWAPAXES(op, ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* Consumes reference to ap (op gets it)\n origin must be previously defined locally. \n SWAPAXES must have been called previously. \n op contains the swapped version of the array. \n*/\n#define SWAPBACK(op, ap) {\t \\\n\t\tif (axis != orign) { \\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* These swap axes in-place if necessary */\n#define SWAPINTP(a,b) {intp c; c=(a); (a) = (b); (b) = c;}\n#define SWAPAXES2(ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN); \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define SWAPBACK2(ap) {\t\t \\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n/*MULTIARRAY_API\n Sort an array in-place\n*/\nstatic int\nPyArray_Sort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *store_arr=NULL;\n\tchar *ip;\n\tint i, n, m, elsize, orign;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) return 0;\n\n\tif (axis < 0) axis += n;\n\tif ((axis < 0) || (axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\treturn -1;\n\t}\n\tif (!PyArray_ISWRITEABLE(op)) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"attempted sort on unwriteable array.\");\n\t\treturn -1;\n\t}\n\n\t/* Determine if we should use type-specific algorithm or not */\n\tif (op->descr->f->sort[which] != NULL) {\n\t\treturn _new_sort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || \\\n\t op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"desired sort not supported for this type\");\n\t\treturn -1;\n\t}\n\n\tSWAPAXES2(op);\n\n ap = (PyArrayObject *)PyArray_FromAny((PyObject *)op, \n\t\t\t\t\t NULL, 1, 0, \n\t\t\t\t\t DEFAULT_FLAGS | UPDATEIFCOPY, NULL);\t\n\tif (ap == NULL) goto fail;\n\t\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(ap)/m;\n\n\t/* Store global -- allows re-entry -- restore before leaving*/\n\tstore_arr = global_obj; \n\tglobal_obj = ap;\n\t\n\tfor (ip=ap->data, i=0; idescr->elsize;\n\tconst intp *ipa = ip1;\n\tconst intp *ipb = ip2;\t\n\treturn global_obj->descr->f->compare(global_data + (isize * *ipa),\n global_data + (isize * *ipb), \n\t\t\t\t\t global_obj);\n}\n\n/*MULTIARRAY_API\n ArgSort an array\n*/\nstatic PyObject *\nPyArray_ArgSort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *ret=NULL, *store;\n\tintp *ip;\n\tintp i, j, n, m, orign;\n\tint argsort_elsize;\n\tchar *store_ptr;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t\t op->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, \n\t\t\t\t\t\t (PyObject *)op);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)ret->data) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += n;\n\tif ((axis < 0) || (axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\treturn NULL;\n\t}\n\n\t/* Determine if we should use new algorithm or not */\n\tif (op->descr->f->argsort[which] != NULL) {\n\t\treturn _new_argsort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"requested sort not available for type\");\n\t\tgoto fail;\n\t}\n\n\tSWAPAXES(ap, op);\n\n\top = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ap, \n\t\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t\t 1, 0);\n\n\tif (op == NULL) return NULL;\n\t\n\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) goto fail;\n\t\n\t\n\tip = (intp *)ret->data;\n\targsort_elsize = op->descr->elsize;\n\tm = op->dimensions[op->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(op)/m;\n\tstore_ptr = global_data;\n\tglobal_data = op->data;\n\tstore = global_obj;\n\tglobal_obj = op;\n\tfor (i=0; i 0 in lexsort\");\n\t\treturn NULL;\n\t}\n\tmps = (PyArrayObject **) _pya_malloc(n*sizeof(PyArrayObject));\n\tif (mps==NULL) return PyErr_NoMemory();\n\tits = (PyArrayIterObject **) _pya_malloc(n*sizeof(PyArrayIterObject));\n\tif (its == NULL) {_pya_free(mps); return PyErr_NoMemory();}\n\tfor (i=0; i0) {\n\t\t\tif ((mps[i]->nd != mps[0]->nd) ||\t\\\n\t\t\t (!PyArray_CompareLists(mps[i]->dimensions,\n\t\t\t\t\t\t mps[0]->dimensions,\n\t\t\t\t\t\t mps[0]->nd))) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"all keys need to be the same shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (!mps[i]->descr->f->argsort[PyArray_MERGESORT]) {\n\t\t\tPyErr_Format(PyExc_TypeError, \n\t\t\t\t \"merge sort not available for item %d\", i);\n\t\t\tgoto fail;\n\t\t}\n\t\tits[i] = (PyArrayIterObject *)PyArray_IterAllButAxis\t\\\n\t\t\t((PyObject *)mps[i], axis);\n\t\tif (its[i]==NULL) goto fail;\n\t}\n\n\t/* Now we can check the axis */\n\tnd = mps[0]->nd;\n\tif ((nd==0) || (PyArray_SIZE(mps[0])==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)(ret->data)) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += nd;\n\tif ((axis < 0) || (axis >= nd)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\tgoto fail;\n\t}\n\n\t/* Now do the sorting */\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t mps[0]->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (ret == NULL) goto fail;\n\n\trit = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ret, axis);\n\tif (rit == NULL) goto fail;\n\n\tsize = rit->size;\n\tN = mps[0]->dimensions[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n maxelsize = mps[0]->descr->elsize;\n\tneedcopy = (rstride != sizeof(intp));\n\tfor (j=0; jflags & ALIGNED) || \\\n\t\t\t(mps[j]->strides[axis] != (intp)mps[j]->descr->elsize);\n if (mps[j]->descr->elsize > maxelsize) \n maxelsize = mps[j]->descr->elsize;\n\t}\n\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(maxelsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*maxelsize);\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idescr->elsize;\n\t\t\t\tastride = mps[j]->strides[axis];\t\n\t\t\t\targsort = mps[j]->descr->f->argsort[PyArray_MERGESORT];\n\t\t\t\t_strided_copy(valbuffer, (intp) elsize, its[j]->dataptr,\n\t\t\t\t\t astride, N, elsize);\n\t\t\t\tif (argsort(valbuffer, (intp *)indbuffer, N, mps[j]) < 0) {\n\t\t\t\t\tPyDataMem_FREE(valbuffer); goto fail;\n\t\t\t\t}\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\t_strided_copy(rit->dataptr, rstride, indbuffer,\n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idescr->f->argsort[PyArray_MERGESORT];\n\t\t\t\tif (argsort(its[j]->dataptr, (intp *)rit->dataptr,\n\t\t\t\t\t N, mps[j]) < 0) goto fail;\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\n\tfor (i=0; idescr->f->compare;\n\tintp min_i, max_i, i, j;\n\tint location, elsize = ap1->descr->elsize;\n\tintp elements = ap1->dimensions[ap1->nd-1];\n\tintp n = PyArray_SIZE(ap2);\n\tintp *rp = (intp *)ret->data;\n\tchar *ip = ap2->data;\n\tchar *vp = ap1->data;\n\n\tfor (j=0; j 0) {\n\t\t\t\t\tif (compare(ip, vp+elsize*(--i), ap2) \\\n\t\t\t\t\t != 0) {\n\t\t\t\t\t\ti = i+1; break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmin_i = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (location < 0) {\n\t\t\t\tmax_i = i;\n\t\t\t} else {\n\t\t\t\tmin_i = i+1;\n\t\t\t}\n\t\t}\n\t\t*rp = min_i;\n\t}\n}\n\n/*MULTIARRAY_API\n Numeric.searchsorted(a,v)\n*/\nstatic PyObject *\nPyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n\tint typenum = 0;\n\n\t/* \n PyObject *args;\n args = Py_BuildValue(\"O\",op2);\n\tPy_DELEGATE_ARGS(((PyObject *)op1), searchsorted, args);\n Py_XDECREF(args);\n\t*/\n\n\ttypenum = PyArray_ObjectType((PyObject *)op1, 0);\n\ttypenum = PyArray_ObjectType(op2, typenum);\n\tret = NULL;\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op1, \n\t\t\t\t\t\t\t typenum, \n\t\t\t\t\t\t\t 1, 1);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tret = (PyArrayObject *)PyArray_New(ap2->ob_type, ap2->nd, \n\t\t\t\t\t ap2->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap2);\n\tif (ret == NULL) goto fail;\n\n\tif (ap2->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tgoto fail;\n\t}\n\t\n\tlocal_where(ap1, ap2, ret); \n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n/*\n Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\treturn ret;\n}\n\n/* Could perhaps be redone to not make contiguous arrays \n */\n\n/*MULTIARRAY_API\n Numeric.innerproduct(a,v)\n*/\nstatic PyObject *\nPyArray_InnerProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tPyArray_Descr *typec;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\tdot = (ret->descr->f->dotfunc);\n\t\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[ap1->nd-1]; \n\tis2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, ap2->nd-1);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\n\tif (PyErr_Occurred()) goto fail;\n\t\t\n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n\n/* just like inner product but does the swapaxes stuff on the fly */\n/*MULTIARRAY_API\n Numeric.matrixproduct(a,v)\n*/\nstatic PyObject *\nPyArray_MatrixProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tintp matchDim;\n\tPyArray_Descr *typec;\n\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\t\n\t\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t}\n\telse {\n\t\tmatchDim = 0;\n\t}\n\n\tif (ap2->dimensions[matchDim] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"objects are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-2; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\tif(ap2->nd > 1) {\n\t\tdimensions[j++] = ap2->dimensions[ap2->nd-1];\n\t}\n\t/*\n\tfprintf(stderr, \"nd=%d dimensions=\", nd);\n\t for(i=0; istrides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\n /* Choose which subtype to return */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\n\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\t\t\n\top = ret->data; os = ret->descr->elsize;\n\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, matchDim);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\tif (PyErr_Occurred()) goto fail; /* only for OBJECT arrays */\n\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n/*MULTIARRAY_API\n Fast Copy and Transpose\n*/\nstatic PyObject *\nPyArray_CopyAndTranspose(PyObject *op) \n{\n\tPyObject *ret, *arr;\n\tint nd;\n\tintp dims[2];\n\tintp i,j;\n\tint elsize, str2;\n\tchar *iptr;\n\tchar *optr;\n\n\t/* make sure it is well-behaved */\n\tarr = PyArray_FromAny(op, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\tnd = PyArray_NDIM(arr);\n\tif (nd == 1) { /* we will give in to old behavior */\n\t\tret = PyArray_Copy((PyArrayObject *)arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\t\t\n\t}\n\telse if (nd != 2) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"only 2-d arrays are allowed\");\n\t\treturn NULL;\n\t}\n\n\t/* Now construct output array */\n\tdims[0] = PyArray_DIM(arr,1);\n\tdims[1] = PyArray_DIM(arr,0);\n\telsize = PyArray_ITEMSIZE(arr);\n\t\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(arr->ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t 2, dims, \n\t\t\t\t NULL, NULL, 0, arr);\n\n\tif (ret == NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn NULL;\n\t}\n\t/* do 2-d loop */\n\toptr = PyArray_DATA(ret);\n\tstr2 = elsize*dims[0];\n\tfor (i=0; idimensions[0];\n\tn2 = ap2->dimensions[0];\n\n\tif (n1 < n2) { \n\t\tret = ap1; ap1 = ap2; ap2 = ret; \n\t\tret = NULL; i = n1;n1=n2;n2=i;\n\t}\n\tlength = n1;\n\tn = n2;\n\tswitch(mode) {\n\tcase 0:\t\n\t\tlength = length-n+1;\n\t\tn_left = n_right = 0;\n\t\tbreak;\n\tcase 1:\n\t\tn_left = (intp)(n/2);\n\t\tn_right = n-n_left-1;\n\t\tbreak;\n\tcase 2:\n\t\tn_right = n-1;\n\t\tn_left = n-1;\n\t\tlength = length+n-1;\n\t\tbreak;\n\tdefault:\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mode must be 0, 1, or 2\");\n\t\tgoto fail;\n\t}\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\n\tif (ret == NULL) goto fail;\n\t\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"function not available for this data type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[0]; is2 = ap2->strides[0];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data; ip2 = ap2->data+n_left*is2;\n\tn = n-n_left;\n\tfor(i=0; idescr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Min\n*/\nstatic PyObject *\nPyArray_Min(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tret = PyArray_GenericReduceFunction(arr, n_ops.minimum, axis,\n\t\t\t\t\t arr->descr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Ptp\n*/\nstatic PyObject *\nPyArray_Ptp(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\tPyObject *obj1=NULL, *obj2=NULL;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tobj1 = PyArray_Max(arr, axis);\n\tif (obj1 == NULL) goto fail;\n\tobj2 = PyArray_Min(arr, axis);\n\tif (obj2 == NULL) goto fail;\n\tPy_DECREF(arr);\n\tret = PyNumber_Subtract(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(obj1);\n\tPy_XDECREF(obj2);\n\treturn NULL;\n}\n\n\n/*MULTIARRAY_API\n ArgMax\n*/\nstatic PyObject *\nPyArray_ArgMax(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap=NULL, *rp=NULL;\n\tPyArray_ArgFunc* arg_func;\n\tchar *ip;\n\tintp *rptr;\n\tintp i, n, orign, m;\n\tint elsize;\n\t\n\tif ((ap=(PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny((PyObject *)op, \n\t\t\t\t\t PyArray_NOTYPE, 1, 0);\n\n\tPy_DECREF(op);\n\tif (ap == NULL) return NULL;\n\t\n\targ_func = ap->descr->f->argmax;\n\tif (arg_func == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"data type not ordered\");\n\t\tgoto fail;\n\t}\n\n\trp = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd-1,\n\t\t\t\t\t ap->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)ap);\n\tif (rp == NULL) goto fail;\n\n\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) {\n\t\tPyErr_SetString(MultiArrayError, \n\t\t\t\t\"attempt to get argmax/argmin \"\\\n\t\t\t\t\"of an empty sequence??\");\n\t\tgoto fail;\n\t}\n\tn = PyArray_SIZE(ap)/m;\n\trptr = (intp *)rp->data;\n\tfor (ip = ap->data, i=0; ind + indices->nd - 1;\n for (i=0; i< nd; i++) {\n if (i < axis) {\n shape[i] = self->dimensions[i];\n n *= shape[i];\n } else {\n if (i < axis+indices->nd) {\n shape[i] = indices->dimensions[i-axis];\n m *= shape[i];\n } else {\n shape[i] = self->dimensions[i-indices->nd+1];\n chunk *= shape[i];\n }\n }\n }\n\tPy_INCREF(self->descr);\n ret = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t nd, shape, \n\t\t\t\t\t\t NULL, NULL, 0, \n\t\t\t\t\t\t (PyObject *)self);\n\t\n if (ret == NULL) goto fail;\n\t\n max_item = self->dimensions[axis];\n chunk = chunk * ret->descr->elsize;\n src = self->data;\n dest = ret->data;\n\t\n for(i=0; idata))[j];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\t\"index out of range for \"\\\n\t\t\t\t\t\t\"array\");\n goto fail;\n }\n memmove(dest, src+tmp*chunk, chunk);\n dest += chunk;\n }\n src += chunk*max_item;\n }\n\t\n PyArray_INCREF(ret);\n\n Py_XDECREF(indices);\n Py_XDECREF(self);\n\n return (PyObject *)ret;\n\t\n\t\n fail:\n Py_XDECREF(ret);\n Py_XDECREF(indices);\n Py_XDECREF(self);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array\n*/\nstatic PyObject *\nPyArray_Put(PyArrayObject *self, PyObject* values0, PyObject *indices0) \n{\n PyArrayObject *indices, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype; \n char *src, *dest;\n\n indices = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \"put: first argument must be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \"put: first argument must be contiguous\");\n return NULL;\n }\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0);\n if (indices == NULL) goto fail;\n ni = PyArray_SIZE(indices);\n\n\tthistype = self->descr->type_num;\n Py_INCREF(self->descr); \n\tvalues = (PyArrayObject *)PyArray_FromAny(values0, self->descr, 0, 0, \n\t\t\t\t\t\t DEFAULT_FLAGS | FORCECAST, NULL); \n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\n if (thistype == PyArray_OBJECT) { \n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n Py_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+tmp*chunk)));\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n\n }\n\n Py_XDECREF(values);\n Py_XDECREF(indices);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(indices);\n Py_XDECREF(values);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array according to a mask.\n*/\nstatic PyObject *\nPyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) \n{\n PyArrayObject *mask, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype;\n char *src, *dest;\n\n mask = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"putmask: first argument must \"\\\n\t\t\t\t\"be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: first argument must be contiguous\");\n return NULL;\n }\n\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n mask = (PyArrayObject *)\\\n\t\tPyArray_FROM_OTF(mask0, PyArray_BOOL, CARRAY_FLAGS | FORCECAST);\n\tif (mask == NULL) goto fail;\n ni = PyArray_SIZE(mask);\n if (ni != max_item) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: mask and data must be \"\\\n\t\t\t\t\"the same size\");\n goto fail;\n }\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n\tif (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\t /* zero if null array */\n if (nv > 0) {\n if (thistype == PyArray_OBJECT) {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) {\n\t\t\t\t\tPy_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+i*chunk)));\n memmove(dest + i * chunk, src, chunk);\n }\n\t\t\t}\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) memmove(dest + i * chunk, src, chunk);\n\t\t\t}\n\t\t}\n }\n\n Py_XDECREF(values);\n Py_XDECREF(mask);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(mask);\n Py_XDECREF(values);\n return NULL;\n}\n\n\n/* This conversion function can be used with the \"O&\" argument for\n PyArg_ParseTuple. It will immediately return an object of array type\n or will convert to a CARRAY any other object. \n\n If you use PyArray_Converter, you must DECREF the array when finished\n as you get a new reference to it.\n*/\n \n/*MULTIARRAY_API\n Useful to pass as converter function for O& processing in\n PyArgs_ParseTuple.\n*/\nstatic int \nPyArray_Converter(PyObject *object, PyObject **address) \n{\n if (PyArray_Check(object)) {\n *address = object;\n\t\tPy_INCREF(object);\n return PY_SUCCEED;\n }\n else {\n\t\t*address = PyArray_FromAny(object, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\t\tif (*address == NULL) return PY_FAIL;\n\t\treturn PY_SUCCEED;\n }\n}\n\n/*MULTIARRAY_API\n Convert an object to true / false\n*/\nstatic int\nPyArray_BoolConverter(PyObject *object, Bool *val)\n{ \n if (PyObject_IsTrue(object))\n *val=TRUE;\n else *val=FALSE;\n if (PyErr_Occurred())\n return PY_FAIL;\n return PY_SUCCEED;\n}\n\n\n/*MULTIARRAY_API\n Typestr converter\n*/\nstatic int\nPyArray_TypestrConvert(int itemsize, int gentype)\n{\n\tregister int newtype = gentype;\n\t\n\tif (gentype == PyArray_GENBOOLLTR) {\n\t\tif (itemsize == 1)\n\t\t\tnewtype = PyArray_BOOL;\n\t\telse \n\t\t\tnewtype = PyArray_NOTYPE;\n\t}\n\telse if (gentype == PyArray_SIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_INT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_INT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_INT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_INT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_INT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\n\t}\n\n\telse if (gentype == PyArray_UNSIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_UINT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_UINT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_UINT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_UINT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_UINT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t\tbreak;\n\t\t}\n\t}\n\telse if (gentype == PyArray_FLOATINGLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 4:\n\t\t\tnewtype = PyArray_FLOAT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_FLOAT64;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 10:\n\t\t\tnewtype = PyArray_FLOAT80;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 12:\n\t\t\tnewtype = PyArray_FLOAT96;\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_FLOAT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\t\n\telse if (gentype == PyArray_COMPLEXLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 8:\n\t\t\tnewtype = PyArray_COMPLEX64;\n\t\t\tbreak;\n\t\tcase 16:\n\t\t\tnewtype = PyArray_COMPLEX128;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 20:\n\t\t\tnewtype = PyArray_COMPLEX160;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 24:\n\t\t\tnewtype = PyArray_COMPLEX192;\t\t\t\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 32:\n\t\t\tnewtype = PyArray_COMPLEX256;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\n\treturn newtype;\n}\n\n\n/* this function takes a Python object which exposes the (single-segment)\n buffer interface and returns a pointer to the data segment\n \n You should increment the reference count by one of buf->base\n if you will hang on to a reference\n\n You only get a borrowed reference to the object. Do not free the\n memory...\n*/\n\n\n/*MULTIARRAY_API\n Get buffer chunk from object\n*/\nstatic int\nPyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)\n{\n int buflen;\n\n buf->ptr = NULL;\n buf->flags = BEHAVED_FLAGS;\n buf->base = NULL;\n\n\tif (obj == Py_None)\n\t\treturn PY_SUCCEED;\n\n if (PyObject_AsWriteBuffer(obj, &(buf->ptr), &buflen) < 0) {\n PyErr_Clear();\n buf->flags &= ~WRITEABLE;\n if (PyObject_AsReadBuffer(obj, (const void **)&(buf->ptr), \n &buflen) < 0)\n return PY_FAIL;\n }\n buf->len = (intp) buflen;\n \n /* Point to the base of the buffer object if present */\n if (PyBuffer_Check(obj)) buf->base = ((PyArray_Chunk *)obj)->base;\n if (buf->base == NULL) buf->base = obj;\n \n return PY_SUCCEED; \n}\n\n\n\n/* This function takes a Python sequence object and allocates and\n fills in an intp array with the converted values.\n\n **Remember to free the pointer seq.ptr when done using\n PyDimMem_FREE(seq.ptr)**\n*/\n\n/*MULTIARRAY_API\n Get intp chunk from sequence\n*/\nstatic int\nPyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)\n{\n int len;\n int nd;\n\n seq->ptr = NULL;\n if (obj == Py_None) return PY_SUCCEED;\n len = PySequence_Size(obj);\n if (len == -1) { /* Check to see if it is a number */\n if (PyNumber_Check(obj)) len = 1;\n }\n if (len < 0) {\n PyErr_SetString(PyExc_TypeError, \n \"expected sequence object with len >= 0\");\n return PY_FAIL;\n }\n if (len > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError, \"sequence too large; \" \\\n \"must be smaller than %d\", MAX_DIMS);\n return PY_FAIL;\n }\n\tif (len > 0) {\n\t\tseq->ptr = PyDimMem_NEW(len);\n\t\tif (seq->ptr == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n seq->len = len;\n nd = PyArray_IntpFromSequence(obj, (intp *)seq->ptr, len);\n if (nd == -1 || nd != len) {\n\t\tPyDimMem_FREE(seq->ptr);\n\t\tseq->ptr=NULL;\n\t\treturn PY_FAIL;\n\t}\n return PY_SUCCEED;\n}\n\n\n/* A tuple type would be either (generic typeobject, typesize) \n or (fixed-length data-type, shape) \n\n or (inheriting data-type, new-data-type)\n The new data-type must have the same itemsize as the inheriting data-type\n unless the latter is 0 \n \n Thus (int32, {'real':(int16,0),'imag',(int16,2)})\n\n is one way to specify a descriptor that will give \n a['real'] and a['imag'] to an int32 array.\n*/\n\n/* leave type reference alone */\nstatic PyArray_Descr *\n_use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) \n{\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n\t\n\t*errflag = 0;\n\tif (!PyArray_DescrConverter(newobj, &conv)) {\n\t\treturn NULL;\n\t}\n\t*errflag = 1;\n\tif (type == &OBJECT_Descr) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"cannot base a new descriptor on an\"\\\n\t\t\t\t\" OBJECT descriptor.\");\n\t\tgoto fail;\n\t}\n\tnew = PyArray_DescrNew(type);\n\tif (new == NULL) goto fail;\n\n\tif (new->elsize && new->elsize != conv->elsize) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mismatch in size of old\"\\\n\t\t\t\t\"and new data-descriptor\");\n\t\tgoto fail;\n\t}\n\tnew->elsize = conv->elsize;\n\tif (conv->fields != Py_None) {\n\t\tnew->fields = conv->fields;\n\t\tPy_XINCREF(new->fields);\n\t}\n\tPy_DECREF(conv);\n\t*errflag = 0;\n\treturn new;\n\n fail:\n\tPy_DECREF(conv);\n\treturn NULL;\n\n}\n\nstatic PyArray_Descr *\n_convert_from_tuple(PyObject *obj) \n{\n\tPyArray_Descr *type, *res;\n\tPyObject *val;\n\tint errflag;\n\t\n\tif (PyTuple_GET_SIZE(obj) != 2) return NULL;\n\n\tif (!PyArray_DescrConverter(PyTuple_GET_ITEM(obj,0), &type)) \n\t\treturn NULL;\n\tval = PyTuple_GET_ITEM(obj,1);\n\t/* try to interpret next item as a type */\n\tres = _use_inherit(type, val, &errflag);\n\tif (res || errflag) {\n\t\tPy_DECREF(type);\n\t\tif (res) return res;\n\t\telse return NULL;\n\t}\n\tPyErr_Clear();\n\t/* We get here if res was NULL but errflag wasn't set\n\t --- i.e. the conversion to a data-descr failed in _use_inherit\n\t*/\n\n\tif (type->elsize == 0) { /* interpret next item as a typesize */\n\t\tint itemsize;\n\t\titemsize = PyArray_PyIntAsInt(PyTuple_GET_ITEM(obj,1));\n\t\tif (error_converting(itemsize)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid itemsize in generic type \"\\\n\t\t\t\t\t\"tuple\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(type);\n\t\tif (type->type_num == PyArray_UNICODE)\n\t\t\ttype->elsize = itemsize << 2; \n\t\telse\n\t\t\ttype->elsize = itemsize;\n\t}\n\telse {\n\t\t/* interpret next item as shape (if it's a tuple)\n\t\t and reset the type to PyArray_VOID with \n\t\t a new fields attribute. \n\t */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyArray_Descr *newdescr;\n\t\tif (!(PyArray_IntpConverter(val, &shape)) || \n\t\t (shape.len > MAX_DIMS)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n\t\t\tgoto fail;\n\t\t}\n\t\t/* If (type, 1) was given, it is equivalent to type... */\n\t\tif (shape.len == 1 && shape.ptr[0] == 1 && \\\n\t\t PyNumber_Check(val)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\treturn type;\n\t\t}\n\t\tnewdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tif (newdescr == NULL) {PyDimMem_FREE(shape.ptr); goto fail;}\n\t\tnewdescr->elsize = type->elsize;\n\t\tnewdescr->elsize *= PyArray_MultiplyList(shape.ptr, \n\t\t\t\t\t\t\t shape.len);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tnewdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tnewdescr->subarray->base = type;\n\t\tif (type->hasobject) newdescr->hasobject = 1;\n\t\tPy_INCREF(val);\n\t\tnewdescr->subarray->shape = val;\n\t\tPy_XDECREF(newdescr->fields);\n\t\tnewdescr->fields = NULL;\n\t\ttype = newdescr;\n\t}\n\treturn type;\n\n fail:\n\tPy_XDECREF(type);\n\treturn NULL;\n}\n\n/* obj is a list. Each item is a tuple with\n\n(field-name, data-type (either a list or a string), and an optional \n shape parameter).\n*/\nstatic PyArray_Descr *\n_convert_from_array_descr(PyObject *obj)\n{\n\tint n, i, totalsize;\n\tint ret;\n\tPyObject *fields, *item, *newobj;\n\tPyObject *name, *key, *tup, *title;\n\tPyObject *nameslist;\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n int hasobject=0;\n\t\n\tn = PyList_GET_SIZE(obj);\t\n\tnameslist = PyTuple_New(n);\n\tif (!nameslist) return NULL;\n\ttotalsize = 0;\n\tfields = PyDict_New();\n\tfor (i=0; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New((title == NULL ? 2 : 3));\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\tif (title != NULL) {\t\t\t\n\t\t\tPy_INCREF(title);\n\t\t\tPyTuple_SET_ITEM(tup, 2, title);\n\t\t\tPyDict_SetItem(fields, title, tup);\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\ttotalsize += conv->elsize;\n\t\tPy_DECREF(tup);\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n\tnew->elsize = totalsize;\n new->hasobject=hasobject;\n\treturn new;\n \n fail:\n\tPy_DECREF(fields);\n\tPy_DECREF(nameslist);\n\treturn NULL;\n\n}\n\n/* a list specifying a data-type can just be\n a list of formats. The names for the fields\n will default to f1, f2, f3, and so forth.\n\n or it can be an array_descr format string -- in which case\n align must be 0. \n*/\n\nstatic PyArray_Descr *\n_convert_from_list(PyObject *obj, int align, int try_descr)\n{\n\tint n, i;\n\tint totalsize;\n\tPyObject *fields;\n\tPyArray_Descr *conv=NULL;\n\tPyArray_Descr *new;\n\tPyObject *key, *tup;\n\tPyObject *nameslist=NULL;\n \tint ret;\n\tint maxalign=0;\n int hasobject=0;\n\t\n\tn = PyList_GET_SIZE(obj);\n\ttotalsize = 0;\n\tif (n==0) return NULL;\n\tnameslist = PyTuple_New(n);\n\tif (!nameslist) return NULL;\n\tfields = PyDict_New();\n\tfor (i=0; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tif (align) {\n\t\t\tint _align;\n\t\t\t_align = conv->alignment;\n\t\t\tif (_align > 1) totalsize =\t\t\t\\\n\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\tmaxalign = MAX(maxalign, _align);\n\t\t}\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\tPyDict_SetItem(fields, key, tup);\n\t\tPy_DECREF(tup);\n\t\tPyTuple_SET_ITEM(nameslist, i, key);\n\t\ttotalsize += conv->elsize;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n new->hasobject=hasobject;\n\tif (maxalign > 1) {\n\t\ttotalsize = ((totalsize+maxalign-1)/maxalign)*maxalign;\n\t}\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\treturn new;\n\n fail:\n\tPy_DECREF(nameslist);\n\tPy_DECREF(fields);\n\tif (!try_descr) return NULL;\n\tif (align) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"failed to convert from list of formats \"\\\n\t\t\t\t\"and align cannot be 1 for conversion from \"\\\n\t\t\t\t\"array_descr structure\");\n\t\treturn NULL;\n\t}\n\tPyErr_Clear();\n\treturn _convert_from_array_descr(obj);\n}\n\n\n/* comma-separated string */\n/* this is the format developed by the numarray records module */\n/* and implemented by the format parser in that module */\n/* this is an alternative implementation found in the _internal.py \n file patterned after that one -- the approach is to try to convert \n to a list (with tuples if any repeat information is present) \n and then call the _convert_from_list)\n*/\n\nstatic PyArray_Descr *\n_convert_from_commastring(PyObject *obj, int align)\n{\n\tPyObject *listobj;\n\tPyArray_Descr *res;\n\n\tif (!PyString_Check(obj)) return NULL;\n listobj = PyObject_CallMethod(_numpy_internal, \"_commastring\",\n\t\t\t\t \"O\", obj);\n\tif (!listobj) return NULL;\n\tres = _convert_from_list(listobj, align, 0);\n\tPy_DECREF(listobj);\n\tif (!res && !PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_ValueError, \"invalid data-type\");\n\t\treturn NULL;\n\t}\n\treturn res;\n}\n\n\n\n/* a dictionary specifying a data-type\n must have at least two and up to four\n keys These must all be sequences of the same length.\n\n \"names\" --- field names \n \"formats\" --- the data-type descriptors for the field.\n \n Optional:\n\n \"offsets\" --- integers indicating the offset into the \n record of the start of the field.\n\t\t if not given, then \"consecutive offsets\" \n\t\t will be assumed and placed in the dictionary.\n \n \"titles\" --- Allows the use of an additional key\n for the fields dictionary.\n \nAttribute-lookup-based field names merely has to query the fields \ndictionary of the data-descriptor. Any result present can be used\nto return the correct field.\n\nSo, the notion of what is a name and what is a title is really quite\narbitrary. \n\nWhat does distinguish a title, however, is that if it is not None, \nit will be placed at the end of the tuple inserted into the \nfields dictionary.\n\nIf the dictionary does not have \"names\" and \"formats\" entries,\nthen it will be checked for conformity and used directly. \n*/\n\nstatic PyArray_Descr *\n_use_fields_dict(PyObject *obj, int align)\n{\n return (PyArray_Descr *)PyObject_CallMethod(_numpy_internal, \n\t\t\t\t\t\t \"_usefields\", \n\t\t\t\t\t\t \"Oi\", obj, align);\n}\n\nstatic PyArray_Descr *\n_convert_from_dict(PyObject *obj, int align)\n{\n\tPyArray_Descr *new;\n\tPyObject *fields=NULL;\n\tPyObject *names, *offsets, *descrs, *titles, *key;\n\tint n, i;\n\tint totalsize;\n\tint maxalign=0;\n int hasobject=0;\n\t\n\tfields = PyDict_New();\n\tif (fields == NULL) return (PyArray_Descr *)PyErr_NoMemory();\n\t\n\tnames = PyDict_GetItemString(obj, \"names\");\n\tdescrs = PyDict_GetItemString(obj, \"formats\");\n\n\tif (!names || !descrs) {\n\t\tPy_DECREF(fields);\n\t\treturn _use_fields_dict(obj, align);\n\t}\n\tn = PyObject_Length(names);\n\toffsets = PyDict_GetItemString(obj, \"offsets\");\n\ttitles = PyDict_GetItemString(obj, \"titles\");\n\tif ((n > PyObject_Length(descrs)) ||\t\t\t\\\n\t (offsets && (n > PyObject_Length(offsets))) ||\t\\\n\t (titles && (n > PyObject_Length(titles)))) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"all items in the dictionary must have\" \\\n\t\t\t\t\" the same length.\");\n\t\tgoto fail;\n\t}\n\n\ttotalsize = 0;\n\tfor(i=0; i totalsize) totalsize = offset;\n\t\t}\n\t\telse {\n\t\t\tif (align) {\n\t\t\t\tint _align = newdescr->alignment;\n\t\t\t\tif (_align > 1) totalsize =\t\t\\\n\t\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\t\tmaxalign = MAX(maxalign,_align);\n\t\t\t}\n\t\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\n\t\t}\n\t\tif (len == 3) PyTuple_SET_ITEM(tup, 2, item);\n\t\tname = PyObject_GetItem(names, index);\n\t\tPy_DECREF(index);\n\n\t\t/* Insert into dictionary */\n\t\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"name already used as a name or title\");\n\t\t\tret = PY_FAIL;\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) {\n\t\t\tif (PyDict_GetItem(fields, item) != NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"title already used as a name or \" \\\n\t\t\t\t\t\t\" title.\");\n\t\t\t\tret=PY_FAIL;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyDict_SetItem(fields, item, tup);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n if (!hasobject && newdescr->hasobject)\n hasobject = 1;\n\t\ttotalsize += newdescr->elsize;\n\t}\n\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tif (new == NULL) goto fail;\n\tif (maxalign > 1)\n\t\ttotalsize = ((totalsize + maxalign - 1)/maxalign)*maxalign;\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\tkey = PyInt_FromLong(-1);\n if (!PyTuple_Check(names)) {\n names = PySequence_Tuple(names);\n PyDict_SetItem(fields, key, names);\n Py_DECREF(names);\n }\n else PyDict_SetItem(fields, key, names);\n\tPy_DECREF(key);\n\tnew->fields = fields;\n new->hasobject=hasobject;\n\treturn new;\n\n fail:\n\tPy_XDECREF(fields);\n\treturn NULL;\n}\n\n/* \n any object with \n the .fields attribute and/or .itemsize attribute \n (if the .fields attribute does not give\n the total size -- i.e. a partial record naming).\n If itemsize is given it must be >= size computed from fields\n \n The .fields attribute must return a convertible dictionary if \n present. Result inherits from PyArray_VOID.\n*/\n\n\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to NULL\n*/\nstatic int\nPyArray_DescrConverter2(PyObject *obj, PyArray_Descr **at)\n{\n\tif (obj == Py_None) {\n\t\t*at = NULL;\n\t\treturn PY_SUCCEED;\n\t}\n\telse return PyArray_DescrConverter(obj, at);\n}\n\n/* This function takes a Python object representing a type and converts it \n to a the correct PyArray_Descr * structure to describe the type.\n \n Many objects can be used to represent a data-type which in NumPy is\n quite a flexible concept. \n\n This is the central code that converts Python objects to \n Type-descriptor objects that are used throughout numpy.\n */\n\n/* new reference in *at */\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to &LONG_descr\n*/\nstatic int\nPyArray_DescrConverter(PyObject *obj, PyArray_Descr **at)\n{\n char *type;\n int check_num=PyArray_NOTYPE+10;\n\tint len;\n\tPyObject *item;\n\tint elsize = 0;\n\tchar endian = '=';\n\n\t*at=NULL;\n\t\n\t/* default */\n if (obj == Py_None) {\n\t\t*at = PyArray_DescrFromType(PyArray_LONG);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n\tif (PyArray_DescrCheck(obj)) {\n\t\t*at = (PyArray_Descr *)obj;\n\t\tPy_INCREF(*at);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n if (PyType_Check(obj)) {\n\t\tif (PyType_IsSubtype((PyTypeObject *)obj, \n\t\t\t\t &PyGenericArrType_Type)) {\n\t\t\t*at = PyArray_DescrFromTypeObject(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t\telse return PY_FAIL;\n\t\t}\n\t\tcheck_num = PyArray_OBJECT;\n\t\tif (obj == (PyObject *)(&PyInt_Type))\n\t\t\tcheck_num = PyArray_LONG;\n\t\telse if (obj == (PyObject *)(&PyLong_Type))\n\t\t\tcheck_num = PyArray_LONGLONG;\n\t\telse if (obj == (PyObject *)(&PyFloat_Type)) \n\t\t\tcheck_num = PyArray_DOUBLE;\n\t\telse if (obj == (PyObject *)(&PyComplex_Type)) \n\t\t\tcheck_num = PyArray_CDOUBLE;\n\t\telse if (obj == (PyObject *)(&PyBool_Type))\n\t\t\tcheck_num = PyArray_BOOL;\n else if (obj == (PyObject *)(&PyString_Type))\n check_num = PyArray_STRING;\n else if (obj == (PyObject *)(&PyUnicode_Type))\n check_num = PyArray_UNICODE;\n\t\telse if (obj == (PyObject *)(&PyBuffer_Type))\n\t\t\tcheck_num = PyArray_VOID;\n\t\telse {\n\t\t\t*at = _arraydescr_fromobj(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* or a typecode string */\n\n\tif (PyString_Check(obj)) {\n\t\t/* Check for a string typecode. */\n\t\ttype = PyString_AS_STRING(obj);\n\t\tlen = PyString_GET_SIZE(obj);\n\t\tif (len <= 0) goto fail;\n\t\tcheck_num = (int) type[0];\n\t\tif ((char) check_num == '>' || (char) check_num == '<' || \\\n\t\t (char) check_num == '|' || (char) check_num == '=') {\n\t\t\tif (len <= 1) goto fail;\n\t\t\tendian = (char) check_num;\n\t\t\ttype++; len--;\n\t\t\tcheck_num = (int) type[0];\n\t\t\tif (endian == '|') endian = '=';\n\t\t}\n\t\tif (len > 1) {\n\t\t\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\t\t\tfor (i=1;ielsize == 0) && (elsize != 0)) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->elsize = elsize;\n\t}\n\tif (endian != '=' && PyArray_ISNBO(endian)) endian = '='; \n\t\n\tif (endian != '=' && (*at)->byteorder != '|' &&\t\\\n\t (*at)->byteorder != endian) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->byteorder = endian;\n\t}\n\t\n return PY_SUCCEED;\n\n fail:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"data type not understood\");\n\t*at=NULL;\n\treturn PY_FAIL;\n}\t\n\n/*MULTIARRAY_API\n Convert object to endian\n*/\nstatic int\nPyArray_ByteorderConverter(PyObject *obj, char *endian)\n{\n\tchar *str;\n\t*endian = PyArray_SWAP;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Byteorder string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\t*endian = str[0];\n\tif (str[0] != PyArray_BIG && str[0] != PyArray_LITTLE &&\t\\\n\t str[0] != PyArray_NATIVE) {\n\t\tif (str[0] == 'b' || str[0] == 'B')\n\t\t\t*endian = PyArray_BIG;\n\t\telse if (str[0] == 'l' || str[0] == 'L')\n\t\t\t*endian = PyArray_LITTLE;\n\t\telse if (str[0] == 'n' || str[0] == 'N')\n\t\t\t*endian = PyArray_NATIVE;\n\t\telse if (str[0] == 'i' || str[0] == 'I')\n\t\t\t*endian = PyArray_IGNORE;\n\t\telse if (str[0] == 's' || str[0] == 'S')\n\t\t\t*endian = PyArray_SWAP;\n\t\telse {\n\t\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t\t \"%s is an unrecognized byteorder\",\n\t\t\t\t str);\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Convert object to sort kind \n*/\nstatic int\nPyArray_SortkindConverter(PyObject *obj, PyArray_SORTKIND *sortkind)\n{\n\tchar *str;\n\t*sortkind = PyArray_QUICKSORT;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Sort kind string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\tif (str[0] == 'q' || str[0] == 'Q')\n\t\t*sortkind = PyArray_QUICKSORT;\n\telse if (str[0] == 'h' || str[0] == 'H')\n\t\t*sortkind = PyArray_HEAPSORT;\n\telse if (str[0] == 'm' || str[0] == 'M')\n\t\t*sortkind = PyArray_MERGESORT;\n\telse if (str[0] == 't' || str[0] == 'T')\n\t\t*sortkind = PyArray_TIMSORT;\n\telse {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"%s is an unrecognized kind of sort\",\n\t\t\t str);\n\t\treturn PY_FAIL;\n\t}\n\treturn PY_SUCCEED;\n}\n\n\n/* This function returns true if the two typecodes are \n equivalent (same basic kind and same itemsize).\n*/\n\n/*MULTIARRAY_API*/\nstatic Bool\nPyArray_EquivTypes(PyArray_Descr *typ1, PyArray_Descr *typ2)\n{\n\tregister int typenum1=typ1->type_num;\n\tregister int typenum2=typ2->type_num;\n\tregister int size1=typ1->elsize;\n\tregister int size2=typ2->elsize;\n\n\tif (size1 != size2) return FALSE;\n\tif (typ1->fields != typ2->fields) return FALSE;\n\tif (PyArray_ISNBO(typ1->byteorder) != PyArray_ISNBO(typ2->byteorder))\n\t\treturn FALSE;\n\n\tif (typenum1 == PyArray_VOID || \\\n\t typenum2 == PyArray_VOID) {\n\t\treturn ((typenum1 == typenum2) && \n\t\t\t(typ1->typeobj == typ2->typeobj) &&\n\t\t\t(typ1->fields == typ2->fields));\n\t}\n\treturn (typ1->kind == typ2->kind);\n}\n\n/*** END C-API FUNCTIONS **/\n\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\n\n\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_fromobject[] = \"array(object, dtype=None, copy=1, fortran=0, \"\\\n \"subok=0,ndmin=0)\\n\"\\\n \"will return a new array formed from the given object type given.\\n\"\\\n \"Object can be anything with an __array__ method, or any object\\n\"\\\n \"exposing the array interface, or any (nested) sequence.\\n\"\\\n \"If no type is given, then the type will be determined as the\\n\"\\\n \"minimum type required to hold the objects in the sequence.\\n\"\\\n \"If copy is zero and sequence is already an array with the right \\n\"\\\n \"type, a reference will be returned. If the sequence is an array,\\n\"\\\n \"type can be used only to upcast the array. For downcasting \\n\"\\\n \"use .astype(t) method. If subok is true, then subclasses of the\\n\"\\\n \"array may be returned. Otherwise, a base-class ndarray is returned\\n\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\n\nstatic PyObject *\n_array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n{\n\tPyObject *op, *ret=NULL;\n\tstatic char *kwd[]= {\"object\", \"dtype\", \"copy\", \"fortran\", \"subok\", \n\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\n\tPyArray_Descr *type=NULL;\n\tPyArray_Descr *oldtype=NULL;\n\tBool fortran=FALSE;\n\tint flags=0;\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&i\", kwd, &op, \n\t\t\t\t\tPyArray_DescrConverter2,\n &type, \n\t\t\t\t\tPyArray_BoolConverter, ©, \n\t\t\t\t\tPyArray_BoolConverter, &fortran,\n PyArray_BoolConverter, &subok, \n\t\t\t\t\t&ndmin)) \n\t\treturn NULL;\n\n\t/* fast exit if simple call */\n\tif (PyArray_CheckExact(op)) {\n\t\tif (type==NULL) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\tret = op;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op, \n\t\t\t\t\t\t fortran);\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\t/* One more chance */\n\t\toldtype = PyArray_DESCR(op);\n\t\tif (PyArray_EquivTypes(oldtype, type)) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\tret = op;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op,\n\t\t\t\t\t\t fortran);\n\t\t\t\tif (oldtype == type) return ret;\n\t\t\t\tPy_INCREF(oldtype);\n\t\t\t\tPy_DECREF(PyArray_DESCR(ret));\n\t\t\t\tPyArray_DESCR(ret) = oldtype;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (copy) {\n\t\tflags = ENSURECOPY;\n\t}\n\tif (fortran) {\n\t\tflags |= FORTRAN;\n\t}\n if (!subok) {\n flags |= ENSUREARRAY;\n }\n\n\tif ((ret = PyArray_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\n}\n\n/* accepts NULL type */\n/* steals referenct to type */\n/*MULTIARRAY_API\n Empty\n*/\nstatic PyObject *\nPyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n \n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type, nd, dims, \n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n PyArray_FillObjectArray(ret, Py_None);\n\t}\n\treturn (PyObject *)ret;\n}\n\n\nstatic char doc_empty[] = \"empty((d1,...,dn),dtype=int,fortran=0) will return a new array\\n of shape (d1,...,dn) and given type with all its entries uninitialized. This can be faster than zeros.\";\n\nstatic PyObject *\narray_empty(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter, &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Empty(shape.len, shape.ptr, typecode, fortran); \n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_scalar[] = \"scalar(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype corresponds to an OBJECT descriptor, then obj can be any object, otherwise obj must be a string. If obj is not given it will be interpreted as None for object type and zeros for all other types.\";\n\nstatic PyObject *\narray_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"dtype\",\"obj\", NULL};\n\tPyArray_Descr *typecode;\n\tPyObject *obj=NULL;\n\tint alloc=0;\n\tvoid *dptr;\n\tPyObject *ret;\n\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|O\",\n\t\t\t\t\t kwlist, &PyArrayDescr_Type, \n\t\t\t\t\t &typecode,\n\t\t\t\t\t &obj)) \n\t\treturn NULL;\n\t\t\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\t\t\\\n\t\t\t\t\"itemsize cannot be zero\");\n\t\treturn NULL;\n\t}\n\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (obj == NULL) obj = Py_None;\n\t\tdptr = &obj;\n\t}\n\telse {\n\t\tif (obj == NULL) {\n\t\t\tdptr = _pya_malloc(typecode->elsize);\n\t\t\tif (dptr == NULL) {\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemset(dptr, '\\0', typecode->elsize);\n\t\t\talloc = 1;\n\t\t}\n\t\telse {\n\t\t\tif (!PyString_Check(obj)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"initializing object must \"\\\n\t\t\t\t\t\t\"be a string\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tif (PyString_GET_SIZE(obj) < typecode->elsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"initialization string is too\"\\\n\t\t\t\t\t\t\" small\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdptr = PyString_AS_STRING(obj);\n\t\t}\n\t}\n\n\tret = PyArray_Scalar(dptr, typecode, NULL);\n\t\n\t/* free dptr which contains zeros */\n\tif (alloc) _pya_free(dptr);\n\treturn ret;\n}\n\n\n/* steal a reference */\n/* accepts NULL type */\n/*MULTIARRAY_API\n Zeros\n*/\nstatic PyObject *\nPyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n\tintp n;\n\n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type,\n\t\t\t\t\t\t nd, dims, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n\t\tPyObject *zero = PyInt_FromLong(0);\n PyArray_FillObjectArray(ret, zero);\n Py_DECREF(zero);\n\t}\n\telse {\n\t\tn = PyArray_NBYTES(ret);\n\t\tmemset(ret->data, 0, n);\n\t}\n\treturn (PyObject *)ret;\n\n}\n\nstatic char doc_zeros[] = \"zeros((d1,...,dn),dtype=int,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.\";\n\n\nstatic PyObject *\narray_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL}; /* XXX ? */\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Zeros(shape.len, shape.ptr, typecode, (int) fortran);\n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_set_typeDict[] = \"set_typeDict(dict) set the internal \"\\\n\t\"dictionary that can look up an array type using a registered \"\\\n\t\"code\";\n\nstatic PyObject *\narray_set_typeDict(PyObject *ignored, PyObject *args)\n{\n\tPyObject *dict;\n\tif (!PyArg_ParseTuple(args, \"O\", &dict)) return NULL;\n\tPy_XDECREF(typeDict); /* Decrement old reference (if any)*/\n\ttypeDict = dict;\n\tPy_INCREF(dict); /* Create an internal reference to it */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\n\t\n\titemsize = dtype->elsize;\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"zero-valued itemsize\");\n\t\tPy_DECREF(dtype);\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_fromString[] = \"fromstring(string, dtype=int, count=-1, sep='') returns a new 1d array initialized from the raw binary data in string. If count is positive, the new array will have count elements, otherwise it's size is determined by the size of string. If sep is not empty then the string is interpreted in ASCII mode and converted to the desired number type using sep as the separator between elements (extra whitespace is ignored).\";\n\nstatic PyObject *\narray_fromString(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tchar *data;\n\tlonglong nin=-1;\n\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", kwlist, \n\t\t\t\t\t &data, &s, \n\t\t\t\t\t PyArray_DescrConverter, &descr,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\n}\n\n/* This needs an open file object and reads it in directly. \n memory-mapped files handled differently through buffer interface.\n\nfile pointer number in resulting 1d array \n(can easily reshape later, -1 for to end of file)\ntype of array\nsep is a separator string for character-based data (or NULL for binary)\n \" \" means whitespace\n*/\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep)\n{\n\tPyArrayObject *r;\n\tsize_t nread = 0;\n\tPyArray_ScanFunc *scan;\n\tBool binary;\n\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"0-sized elements.\");\n\t\tPy_DECREF(typecode);\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\n\tif (num == -1 && binary) { /* Get size for binary file*/\n\t\tintp start, numbytes;\n\t\tstart = (intp )ftell(fp);\n\t\tfseek(fp, 0, SEEK_END);\n\t\tnumbytes = (intp )ftell(fp) - start;\n\t\trewind(fp);\n\t\tif (numbytes == -1) {\n\t\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\t\"could not seek in file\");\n\t\t\tPy_DECREF(typecode);\n\t\t\treturn NULL;\n\t\t}\n\t\tnum = numbytes / typecode->elsize;\n\t}\n\t\n\tif (binary) { /* binary data */\n\t\tr = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t 0, NULL);\n\t\tif (r==NULL) return NULL;\n\t\tnread = fread(r->data, typecode->elsize, num, fp);\n\t}\n\telse { /* character reading */\n\t\tintp i;\n\t\tchar *dptr;\n\t\tint done=0;\n\n\t\tscan = typecode->f->scanfunc;\n\t\tif (scan == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character files with that \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(typecode);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (num != -1) { /* number to read is known */\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode, \n\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\tdptr = r->data;\n\t\t\tfor (i=0; i < num; i++) {\n\t\t\t\tif (done) break;\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\t\t\t\tif (done < -2) break;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\telse { /* we have to watch for the end of the file and \n\t\t\t reallocate at the end */\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * typecode->elsize;\n\t\t\tdptr = r->data;\n\t\t\twhile (!done) {\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\n\t\t\t\t/* end of file reached trying to \n\t\t\t\t scan value. done is 1 or 2\n\t\t\t\t if end of file reached trying to\n\t\t\t\t scan separator. Still good value.\n\t\t\t\t*/\n\t\t\t\tif (done < -2) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t\tif (!done && thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tr->data = PyDataMem_RENEW(r->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = r->data + (totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tr->data = PyDataMem_RENEW(r->data, nread*r->descr->elsize);\n\t\t\tPyArray_DIM(r,0) = nread;\n\t\t\tnum = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\tif (nread < num) {\n\t\tfprintf(stderr, \"%ld items requested but only %ld read\\n\", \n\t\t\t(long) num, (long) nread);\n\t\tr->data = PyDataMem_RENEW(r->data, nread * r->descr->elsize);\n\t\tPyArray_DIM(r,0) = nread;\n\t}\n\treturn (PyObject *)r;\n}\n\nstatic char doc_fromfile[] = \\\n\t\"fromfile(file=, dtype=int, count=-1, sep='')\\n\"\t\\\n\t\"\\n\"\\\n\t\" Return an array of the given data type from a \\n\"\\\n\t\" (text or binary) file. The file argument can be an open file\\n\"\\\n\t\" or a string with the name of a file to read from. If\\n\"\\\n\t\" count==-1, then the entire file is read, otherwise count is\\n\"\\\n\t\" the number of items of the given type read in. If sep is ''\\n\"\\\n\t\" then read a binary file, otherwise it gives the separator\\n\"\\\n\t\" between elements in a text file.\\n\"\\\n\t\"\\n\"\\\n\t\" WARNING: This function should be used sparingly, as it is not\\n\"\\\n\t\" a platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to read in simply-formatted or binary data quickly.\";\n\nstatic PyObject *\narray_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *file=NULL, *ret;\n\tFILE *fp;\n\tchar *sep=\"\";\n\tchar *mode=NULL;\n\tlonglong nin=-1;\n\tstatic char *kwlist[] = {\"file\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *type=NULL;\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Ls\", kwlist, \n\t\t\t\t\t &file,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\tif (type == NULL) type = PyArray_DescrFromType(PyArray_LONG);\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"rb\";\n\t\telse mode=\"r\";\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), mode);\n\t\tif (file==NULL) return NULL;\n\t}\n\telse {\n\t\tPy_INCREF(file);\n\t}\n\tfp = PyFile_AsFile(file);\n\tif (fp == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\"first argument must be an open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_FromFile(fp, type, (intp) nin, sep);\n\tPy_DECREF(file);\n\treturn ret;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, \n\t\t intp count, intp offset) \n{\n\tPyArrayObject *ret;\n\tchar *data;\n\tint ts;\n\tintp s, n;\n\tint itemsize;\n\tint write=1;\n\n\n\tif (type->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot create an OBJECT array from memory\"\\\n\t\t\t\t\" buffer\");\n\t\tPy_DECREF(type);\n\t\treturn NULL;\n\t}\n\tif (type->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"itemsize cannot be zero in type\");\n\t\tPy_DECREF(type);\n\t\treturn NULL; \t\t\n\t}\n\n\tif (buf->ob_type->tp_as_buffer == NULL || \\\n\t (buf->ob_type->tp_as_buffer->bf_getwritebuffer == NULL &&\t\\\n\t buf->ob_type->tp_as_buffer->bf_getreadbuffer == NULL)) {\n\t\tPyObject *newbuf;\n\t\tnewbuf = PyObject_GetAttrString(buf, \"__buffer__\");\n\t\tif (newbuf == NULL) {Py_DECREF(type); return NULL;}\n\t\tbuf = newbuf;\n\t}\n\telse {Py_INCREF(buf);}\n\n\tif (PyObject_AsWriteBuffer(buf, (void *)&data, &ts)==-1) {\n\t\twrite = 0;\n\t\tPyErr_Clear();\n\t\tif (PyObject_AsReadBuffer(buf, (void *)&data, &ts)==-1) {\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((offset < 0) || (offset >= ts)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"offset must be positive and smaller than %\"\n\t\t\t INTP_FMT, (intp)ts);\n\t}\n\n\tdata += offset;\n\ts = (intp)ts - offset;\n\tn = (intp)count;\n\titemsize = type->elsize;\n\t\n\tif (n < 0 ) {\n\t\tif (s % itemsize != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tn = s/itemsize;\n\t} else {\n\t\tif (s < n*itemsize) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t type, \n\t\t\t\t\t\t\t 1, &n, \n\t\t\t\t\t\t\t NULL, data, \n\t\t\t\t\t\t\t DEFAULT_FLAGS,\n\t\t\t\t\t\t\t NULL)) == NULL) {\n\t\tPy_DECREF(buf);\n\t\treturn NULL;\n\t}\n\t\n\tif (!write) ret->flags &= ~WRITEABLE;\n\n\t/* Store a reference for decref on deallocation */\n\tret->base = buf;\n\tPyArray_UpdateFlags(ret, ALIGNED);\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_frombuffer[] = \\\n\t\"frombuffer(buffer=, dtype=int, count=-1, offset=0)\\n\"\\\n\t\"\\n\"\t\t\t\t\t\t\t\t\\\n\t\" Returns a 1-d array of data type dtype from buffer. The buffer\\n\"\\\n\t\" argument must be an object that exposes the buffer interface.\\n\"\\\n\t\" If count is -1 then the entire buffer is used, otherwise, count\\n\"\\\n\t\" is the size of the output. If offset is given then jump that\\n\"\\\n\t\" far into the buffer. If the buffer has data that is out\\n\" \\\n\t\" not in machine byte-order, than use a propert data type\\n\"\\\n\t\" descriptor. The data will not\\n\" \\\n\t\" be byteswapped, but the array will manage it in future\\n\"\\\n\t\" operations.\\n\";\n\nstatic PyObject *\narray_frombuffer(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *obj=NULL;\n\tlonglong nin=-1, offset=0;\n\tstatic char *kwlist[] = {\"buffer\", \"dtype\", \"count\", \"offset\", NULL};\n\tPyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&LL\", kwlist, \n\t\t\t\t\t &obj,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &offset)) {\n\t\treturn NULL;\n\t}\n\tif (type==NULL)\n\t\ttype = PyArray_DescrFromType(PyArray_LONG);\n\t\n\treturn PyArray_FromBuffer(obj, type, (intp)nin, (intp)offset);\n}\n\n\nstatic char doc_concatenate[] = \"concatenate((a1,a2,...),axis=None).\";\n\nstatic PyObject *\narray_concatenate(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *a0;\n\tint axis=0;\n\tstatic char *kwlist[] = {\"seq\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist,\n\t\t\t\t\t &a0,\n\t\t\t\t\t PyArray_AxisConverter, &axis))\n\t\treturn NULL;\n\treturn PyArray_Concatenate(a0, axis);\n}\n\nstatic char doc_innerproduct[] = \\\n\t\"inner(a,b) returns the dot product of two arrays, which has\\n\"\\\n\t\"shape a.shape[:-1] + b.shape[:-1] with elements computed by\\n\" \\\n\t\"the product of the elements from the last dimensions of a and b.\";\n\nstatic PyObject *array_innerproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *b0, *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a0, &b0)) return NULL;\n\t\n\treturn _ARET(PyArray_InnerProduct(a0, b0));\n}\n\nstatic char doc_matrixproduct[] = \\\n\t\"dot(a,v) returns matrix-multiplication between a and b. \\n\"\\\n\t\"The product-sum is over the last dimension of a and the \\n\"\\\n\t\"second-to-last dimension of b.\";\n\nstatic PyObject *array_matrixproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *v, *a;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a, &v)) return NULL;\n\t\n\treturn _ARET(PyArray_MatrixProduct(a, v));\n}\n\nstatic char doc_fastCopyAndTranspose[] = \"_fastCopyAndTranspose(a)\";\n\nstatic PyObject *array_fastCopyAndTranspose(PyObject *dummy, PyObject *args) {\n\tPyObject *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &a0)) return NULL;\n\t\n\treturn _ARET(PyArray_CopyAndTranspose(a0));\n}\n\nstatic char doc_correlate[] = \"cross_correlate(a,v, mode=0)\";\n\nstatic PyObject *array_correlate(PyObject *dummy, PyObject *args, PyObject *kwds) {\n\tPyObject *shape, *a0;\n\tint mode=0;\n\tstatic char *kwlist[] = {\"a\", \"v\", \"mode\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO|i\", kwlist, \n\t\t\t\t\t &a0, &shape, &mode)) return NULL;\n\t\n\treturn PyArray_Correlate(a0, shape, mode);\n}\n\n\n/*MULTIARRAY_API\n Arange, \n*/\nstatic PyObject *\nPyArray_Arange(double start, double stop, double step, int type_num)\n{\n\tintp length;\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *obj;\n\tint ret;\n\n\tlength = (intp ) ceil((stop - start)/step);\n \n\tif (length <= 0) {\n\t\tlength = 0;\n\t\treturn PyArray_New(&PyArray_Type, 1, &length, type_num,\n\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t}\n\n\trange = PyArray_New(&PyArray_Type, 1, &length, type_num, \n\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (range == NULL) return NULL;\n\n\tfuncs = PyArray_DESCR(range)->f; \n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tobj = PyFloat_FromDouble(start);\n\tret = funcs->setitem(obj, PyArray_DATA(range), (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 1) return range;\n\n\tobj = PyFloat_FromDouble(start + step);\n\tret = funcs->setitem(obj, PyArray_BYTES(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 2) return range;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\treturn NULL;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\t\n\treturn range;\n\n fail:\n\tPy_DECREF(range);\n\treturn NULL;\n}\n\n/* the formula is \n len = (intp) ceil((start - stop) / step);\n*/\nstatic intp\n_calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, int cmplx)\n{\n\tintp len;\n\tPyObject *val;\n\tdouble value;\n\t\n\t*next = PyNumber_Subtract(stop, start);\n\tif (!(*next)) return -1;\n\tval = PyNumber_TrueDivide(*next, step);\n\tPy_DECREF(*next); *next=NULL;\n\tif (!val) return -1;\n\tif (cmplx && PyComplex_Check(val)) {\n\t\tvalue = PyComplex_RealAsDouble(val);\n\t\tif (error_converting(value)) {Py_DECREF(val); return -1;}\n\t\tlen = (intp) ceil(value);\n\t\tvalue = PyComplex_ImagAsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = MIN(len, (intp) ceil(value));\n\t}\n\telse {\n\t\tvalue = PyFloat_AsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = (intp) ceil(value);\n\t}\n\t\n\tif (len > 0) {\n\t\t*next = PyNumber_Add(start, step);\n\t\tif (!next) return -1;\n\t}\n\treturn len;\n}\n\n/* this doesn't change the references */\n/*MULTIARRAY_API\n ArangeObj,\n*/\nstatic PyObject *\nPyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr *dtype) \n{\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *next;\n\tintp length;\n\n\tif (!dtype) {\n\t\tPyArray_Descr *deftype;\n\t\tPyArray_Descr *newtype;\n\t\tdeftype = PyArray_DescrFromType(PyArray_LONG);\n\t\tnewtype = PyArray_DescrFromObject(start, deftype);\n\t\tPy_DECREF(deftype);\n\t\tdeftype = newtype;\n\t\tif (stop && stop != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(stop, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tif (step && step != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(step, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tdtype = deftype;\n\t}\n\telse Py_INCREF(dtype);\n\n\tif (!step || step == Py_None) {\n\t\tstep = PyInt_FromLong(1);\n\t}\n\telse Py_XINCREF(step);\n\n\tif (!stop || stop == Py_None) {\n\t\tstop = start;\n\t\tstart = PyInt_FromLong(0);\n\t}\n\telse Py_INCREF(start);\n\n\t/* calculate the length and next = start + step*/\n\tlength = _calc_length(start, stop, step, &next, \n\t\t\t PyTypeNum_ISCOMPLEX(dtype->type_num));\n\n\tif (PyErr_Occurred()) {Py_DECREF(dtype); goto fail;}\n\tif (length <= 0) {\n\t\tlength = 0;\n\t\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\t\tPy_DECREF(step); Py_DECREF(start); return range;\n\t}\n\n\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\tif (range == NULL) goto fail;\n\n\tfuncs = PyArray_DESCR(range)->f;\n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tif (funcs->setitem(start, PyArray_DATA(range), (PyArrayObject *)range) < 0)\n\t\tgoto fail;\n\tif (length == 1) goto finish;\n\tif (funcs->setitem(next, PyArray_BYTES(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range) < 0) goto fail;\n\tif (length == 2) goto finish;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\tgoto fail;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\n finish:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_DECREF(next);\n\treturn range;\n\t\n fail:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_XDECREF(next);\n\treturn NULL;\n}\n\n\nstatic char doc_arange[] = \n\"arange([start,] stop[, step,], dtype=None)\\n\\n\"\n\"For integer arguments, just like range() except it returns an array whose type can\\n\"\n\"be specified by the keyword argument dtype.\\n\\n\"\n\"If dtype is not specified, the type of the result is deduced from the type of the\\n\"\n\"arguments.\\n\\n\"\n\"For floating point arguments, the length of the result is ceil((stop - start)/step).\\n\"\n\"This rule may result in the last element of the result be greater than stop.\";\n\nstatic PyObject *\narray_arange(PyObject *ignored, PyObject *args, PyObject *kws) {\n\tPyObject *o_start=NULL, *o_stop=NULL, *o_step=NULL;\n\tstatic char *kwd[]= {\"start\", \"stop\", \"step\", \"dtype\", NULL};\n\tPyArray_Descr *typecode=NULL;\n\t\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|OOO&\", kwd, &o_start,\n\t\t\t\t\t&o_stop, &o_step, \n\t\t\t\t\tPyArray_DescrConverter2,\n\t\t\t\t\t&typecode)) \n\t\treturn NULL;\n\n\treturn PyArray_ArangeObj(o_start, o_stop, o_step, typecode);\n}\n\n/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\n}\n\nstatic char \ndoc_set_string_function[] = \"set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.\";\n\nstatic PyObject *\narray_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *op;\n\tint repr=1;\n\tstatic char *kwlist[] = {\"f\", \"repr\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|i\", kwlist, \n\t\t\t\t\t&op, &repr)) return NULL; \n\tif (!PyCallable_Check(op)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"Argument must be callable.\");\n\t\treturn NULL;\n\t}\n\tPyArray_SetStringFunction(op, repr);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char \ndoc_set_ops_function[] = \"set_numeric_ops(op=func, ...) sets some or all of the number methods for all array objects. Don't forget **dict can be used as the argument list. Returns the functions that were replaced -- can be stored and set later.\";\n\nstatic PyObject *\narray_set_ops_function(PyObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *oldops=NULL;\n\t\n\tif ((oldops = PyArray_GetNumericOps())==NULL) return NULL;\n\n\t/* Should probably ensure that objects are at least callable */\n\t/* Leave this to the caller for now --- error will be raised\n\t later when use is attempted \n\t*/\n\tif (kwds && PyArray_SetNumericOps(kwds) == -1) {\n\t\tPy_DECREF(oldops);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"one or more objects not callable\");\n\t\treturn NULL;\n\t}\n\treturn oldops;\n}\n\n\n/*MULTIARRAY_API\n Where\n*/\nstatic PyObject *\nPyArray_Where(PyObject *condition, PyObject *x, PyObject *y)\n{\n\tPyArrayObject *arr;\n\tPyObject *tup=NULL, *obj=NULL;\n\tPyObject *ret=NULL, *zero=NULL;\n\n\n\tarr = (PyArrayObject *)PyArray_FromAny(condition, NULL, 0, 0, 0, NULL);\n\tif (arr == NULL) return NULL;\n\n\tif ((x==NULL) && (y==NULL)) {\n\t\tret = PyArray_Nonzero(arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\n\tif ((x==NULL) || (y==NULL)) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \"either both or neither \"\n\t\t\t\t\"of x and y should be given\");\n\t\treturn NULL;\n\t}\n\n\n\tzero = PyInt_FromLong((long) 0);\n\n\tobj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, \n\t\t\t\t\t\t\t\tn_ops.not_equal));\n\tPy_DECREF(zero);\n\tPy_DECREF(arr);\n\tif (obj == NULL) return NULL;\n\n\ttup = Py_BuildValue(\"(OO)\", y, x);\n\tif (tup == NULL) {Py_DECREF(obj); return NULL;}\n\n\tret = PyArray_Choose((PyAO *)obj, tup);\n\n\tPy_DECREF(obj);\n\tPy_DECREF(tup);\n\treturn ret;\n}\n\nstatic char doc_where[] = \"where(condition, | x, y) is shaped like condition\"\\\n\t\" and has elements of x and y where condition is respectively true or\"\\\n\t\" false. If x or y are not given, then it is equivalent to\"\\\n\t\" nonzero(condition).\";\n\nstatic PyObject *\narray_where(PyObject *ignored, PyObject *args)\n{\n\tPyObject *obj=NULL, *x=NULL, *y=NULL;\n\t\n\tif (!PyArg_ParseTuple(args, \"O|OO\", &obj, &x, &y)) return NULL;\n\n\treturn PyArray_Where(obj, x, y);\n\n}\n\nstatic char doc_lexsort[] = \"lexsort(keys=, axis=-1) returns an array of indexes\"\\\n\t\" similar to argsort except the sorting is done using the provided sorting\"\\\n\t\" keys. First the sort is done using key[0], then the resulting list of\"\\\n\t\" indexes is further manipulated by sorting on key[0]. And so forth\"\\\n\t\" The result is a sort on multiple keys. If the keys represented columns\" \\\n\t\" of a spread-sheet, for example, this would sort using multiple columns.\"\\\n\t\" The keys argument must be a tuple of things that can be converted to \"\\\n\t\" arrays of the same shape.\";\n\nstatic PyObject *\narray_lexsort(PyObject *ignored, PyObject *args, PyObject *kwds)\n{\n\tint axis=-1;\n\tPyObject *obj;\n\tstatic char *kwlist[] = {\"keys\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|i\", kwlist, \n\t\t\t\t\t &PyTuple_Type, &obj, &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_LexSort(obj, axis));\n}\n\n#undef _ARET\n\n\nstatic char doc_register_dtype[] = \\\n\t\"register_dtype(a) registers a new type object -- gives it a typenum\";\n\nstatic PyObject *\narray_register_dtype(PyObject *dummy, PyObject *args)\n{\n\tPyObject *dtype;\n\tint ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &dtype)) return NULL;\n\t\n\tret = PyArray_RegisterDataType((PyTypeObject *)dtype);\n\tif (ret < 0)\n\t\treturn NULL;\n\treturn PyInt_FromLong((long) ret);\n}\n\nstatic char doc_can_cast_safely[] = \\\n\t\"can_cast_safely(from=d1, to=d2) returns True if data type d1 \"\\\n\t\"can be cast to data type d2 without losing precision.\";\n\nstatic PyObject *\narray_can_cast_safely(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *d1=NULL;\n\tPyArray_Descr *d2=NULL;\n\tBool ret;\n\tPyObject *retobj;\n\tstatic char *kwlist[] = {\"from\", \"to\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O&O&\", kwlist, \n\t\t\t\t\tPyArray_DescrConverter, &d1,\n\t\t\t\t\tPyArray_DescrConverter, &d2))\n\t\treturn NULL;\n\tif (d1 == NULL || d2 == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"did not understand one of the types; \"\t\\\n\t\t\t\t\"'None' not accepted\");\n\t\treturn NULL;\n\t}\n\t\t\n\tret = PyArray_CanCastTo(d1, d2);\n\tretobj = (ret ? Py_True : Py_False);\n\tPy_INCREF(retobj);\n\treturn retobj;\n}\n\nstatic char doc_new_buffer[] = \\\n\t\"newbuffer(size) return a new uninitialized buffer object of size \"\n\t\"bytes\";\n\nstatic PyObject *\nnew_buffer(PyObject *dummy, PyObject *args)\n{\n\tint size;\n\n\tif(!PyArg_ParseTuple(args, \"i\", &size))\n\t\treturn NULL;\n\t\n\treturn PyBuffer_New(size);\n}\n\nstatic char doc_buffer_buffer[] = \\\n\t\"getbuffer(obj [,offset[, size]]) create a buffer object from the \"\\\n\t\"given object\\n referencing a slice of length size starting at \"\\\n\t\"offset. Default\\n is the entire buffer. A read-write buffer is \"\\\n\t\"attempted followed by a read-only buffer.\";\n\nstatic PyObject *\nbuffer_buffer(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj;\n\tint offset=0, size=Py_END_OF_BUFFER, n;\n\tvoid *unused;\n\tstatic char *kwlist[] = {\"object\", \"offset\", \"size\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ii\", kwlist, \n\t\t\t\t\t &obj, &offset, &size))\n\t\treturn NULL;\n\n\n\tif (PyObject_AsWriteBuffer(obj, &unused, &n) < 0) {\n\t\tPyErr_Clear();\n\t\treturn PyBuffer_FromObject(obj, offset, size);\t\t\n\t}\n\telse\n\t\treturn PyBuffer_FromReadWriteObject(obj, offset, size);\n}\n\n\nstatic struct PyMethodDef array_module_methods[] = {\n\t{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\n\t{\"set_string_function\", (PyCFunction)array_set_string_function, \n\t METH_VARARGS|METH_KEYWORDS, doc_set_string_function},\n\t{\"set_numeric_ops\", (PyCFunction)array_set_ops_function,\n\t METH_VARARGS|METH_KEYWORDS, doc_set_ops_function},\n\t{\"set_typeDict\", (PyCFunction)array_set_typeDict,\n\t METH_VARARGS, doc_set_typeDict},\n\n\t{\"array\",\t(PyCFunction)_array_fromobject, \n\t METH_VARARGS|METH_KEYWORDS, doc_fromobject},\n\t{\"arange\", (PyCFunction)array_arange, \n\t METH_VARARGS|METH_KEYWORDS, doc_arange},\n\t{\"zeros\",\t(PyCFunction)array_zeros, \n\t METH_VARARGS|METH_KEYWORDS, doc_zeros},\n\t{\"empty\",\t(PyCFunction)array_empty, \n\t METH_VARARGS|METH_KEYWORDS, doc_empty},\n\t{\"scalar\", (PyCFunction)array_scalar,\n\t METH_VARARGS|METH_KEYWORDS, doc_scalar},\n\t{\"where\", (PyCFunction)array_where,\n\t METH_VARARGS, doc_where},\n\t{\"lexsort\", (PyCFunction)array_lexsort,\n\t METH_VARARGS | METH_KEYWORDS, doc_lexsort},\n\t{\"fromstring\",(PyCFunction)array_fromString,\n\t METH_VARARGS|METH_KEYWORDS, doc_fromString},\n\t{\"concatenate\", (PyCFunction)array_concatenate, \n\t METH_VARARGS|METH_KEYWORDS, doc_concatenate},\n\t{\"inner\", (PyCFunction)array_innerproduct, \n\t METH_VARARGS, doc_innerproduct}, \n\t{\"dot\", (PyCFunction)array_matrixproduct, \n\t METH_VARARGS, doc_matrixproduct}, \n\t{\"_fastCopyAndTranspose\", (PyCFunction)array_fastCopyAndTranspose, \n\t METH_VARARGS, doc_fastCopyAndTranspose},\n\t{\"correlate\", (PyCFunction)array_correlate, \n\t METH_VARARGS | METH_KEYWORDS, doc_correlate},\n\t{\"frombuffer\", (PyCFunction)array_frombuffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_frombuffer},\n\t{\"fromfile\", (PyCFunction)array_fromfile,\n\t METH_VARARGS | METH_KEYWORDS, doc_fromfile},\n\t{\"register_dtype\", (PyCFunction)array_register_dtype,\n\t METH_VARARGS, doc_register_dtype},\n\t{\"can_cast\", (PyCFunction)array_can_cast_safely,\n\t METH_VARARGS | METH_KEYWORDS, doc_can_cast_safely},\t\t\n\t{\"newbuffer\", (PyCFunction)new_buffer,\n\t METH_VARARGS, doc_new_buffer},\t\n\t{\"getbuffer\", (PyCFunction)buffer_buffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_buffer_buffer},\t\n\t{NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n#include \"__multiarray_api.c\"\n\n/* Establish scalar-type hierarchy */\n\n/* For dual inheritance we need to make sure that the objects being\n inherited from have the tp->mro object initialized. This is\n not necessarily true for the basic type objects of Python (it is \n checked for single inheritance but not dual in PyType_Ready).\n\n Thus, we call PyType_Ready on the standard Python Types, here.\n*/ \nstatic int\nsetup_scalartypes(PyObject *dict)\n{\n\n\tinitialize_numeric_types();\n\n if (PyType_Ready(&PyBool_Type) < 0) return -1;\n if (PyType_Ready(&PyInt_Type) < 0) return -1;\n if (PyType_Ready(&PyFloat_Type) < 0) return -1;\n if (PyType_Ready(&PyComplex_Type) < 0) return -1;\n if (PyType_Ready(&PyString_Type) < 0) return -1;\n if (PyType_Ready(&PyUnicode_Type) < 0) return -1;\n\n#define SINGLE_INHERIT(child, parent) \\\n Py##child##ArrType_Type.tp_base = &Py##parent##ArrType_Type;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) {\t\t\\\n PyErr_Print(); \\\n PyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1;\t\t\t\t\t\t\\\n }\n \n if (PyType_Ready(&PyGenericArrType_Type) < 0)\n return -1;\n\n SINGLE_INHERIT(Number, Generic);\n SINGLE_INHERIT(Integer, Number);\n SINGLE_INHERIT(Inexact, Number);\n SINGLE_INHERIT(SignedInteger, Integer);\n SINGLE_INHERIT(UnsignedInteger, Integer);\n SINGLE_INHERIT(Floating, Inexact);\n SINGLE_INHERIT(ComplexFloating, Inexact);\n SINGLE_INHERIT(Flexible, Generic);\n SINGLE_INHERIT(Character, Flexible);\n\t\n#define DUAL_INHERIT(child, parent1, parent2) \\\n Py##child##ArrType_Type.tp_base = &Py##parent2##ArrType_Type;\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent2##ArrType_Type,\t\\\n\t\t\t &Py##parent1##_Type);\t\t\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\n\n#define DUAL_INHERIT2(child, parent1, parent2)\t\t\t\t\\\n Py##child##ArrType_Type.tp_base = &Py##parent1##_Type;\t\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent1##_Type,\t\t\\\n\t\t\t &Py##parent2##ArrType_Type);\t\t\\\n\tPy##child##ArrType_Type.tp_richcompare =\t\t\t\\\n\t\tPy##parent1##_Type.tp_richcompare;\t\t\t\\\n\tPy##child##ArrType_Type.tp_compare =\t\t\t\t\\\n\t\tPy##parent1##_Type.tp_compare;\t\t\t\t\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\n\n SINGLE_INHERIT(Bool, Generic);\n SINGLE_INHERIT(Byte, SignedInteger);\n SINGLE_INHERIT(Short, SignedInteger);\n#if SIZEOF_INT == SIZEOF_LONG\n DUAL_INHERIT(Int, Int, SignedInteger);\n#else\n SINGLE_INHERIT(Int, SignedInteger);\n#endif\n DUAL_INHERIT(Long, Int, SignedInteger);\n#if SIZEOF_LONGLONG == SIZEOF_LONG\n DUAL_INHERIT(LongLong, Int, SignedInteger);\n#else\n SINGLE_INHERIT(LongLong, SignedInteger);\n#endif\n\n /* fprintf(stderr, \"tp_free = %p, PyObject_Del = %p, int_tp_free = %p, base.tp_free = %p\\n\", PyIntArrType_Type.tp_free, PyObject_Del, PyInt_Type.tp_free, PySignedIntegerArrType_Type.tp_free);\n\t */\n\tSINGLE_INHERIT(UByte, UnsignedInteger);\n SINGLE_INHERIT(UShort, UnsignedInteger);\n SINGLE_INHERIT(UInt, UnsignedInteger);\n SINGLE_INHERIT(ULong, UnsignedInteger);\n SINGLE_INHERIT(ULongLong, UnsignedInteger);\n\n SINGLE_INHERIT(Float, Floating);\n DUAL_INHERIT(Double, Float, Floating);\n SINGLE_INHERIT(LongDouble, Floating);\n\n SINGLE_INHERIT(CFloat, ComplexFloating);\n DUAL_INHERIT(CDouble, Complex, ComplexFloating);\n SINGLE_INHERIT(CLongDouble, ComplexFloating);\n\n DUAL_INHERIT2(String, String, Character);\n DUAL_INHERIT2(Unicode, Unicode, Character);\n\t\n SINGLE_INHERIT(Void, Flexible);\n \n SINGLE_INHERIT(Object, Generic);\n\n return 0;\n\n#undef SINGLE_INHERIT\n#undef DUAL_INHERIT\n\n\t/* Clean up string and unicode array types so they act more like\n\t strings -- get their tables from the standard types.\n\t*/\n}\n\n/* place a flag dictionary in d */\n\nstatic void\nset_flaginfo(PyObject *d)\n{\n PyObject *s;\n PyObject *newd;\n \n newd = PyDict_New();\n\n PyDict_SetItemString(newd, \"OWNDATA\", s=PyInt_FromLong(OWNDATA));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"FORTRAN\", s=PyInt_FromLong(FORTRAN));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"CONTIGUOUS\", s=PyInt_FromLong(CONTIGUOUS));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"ALIGNED\", s=PyInt_FromLong(ALIGNED));\n Py_DECREF(s);\n\n PyDict_SetItemString(newd, \"UPDATEIFCOPY\", s=PyInt_FromLong(UPDATEIFCOPY));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"WRITEABLE\", s=PyInt_FromLong(WRITEABLE));\n Py_DECREF(s);\n \n PyDict_SetItemString(d, \"_flagdict\", newd);\n Py_DECREF(newd);\n return;\n}\n\n\n/* Initialization function for the module */\n\nDL_EXPORT(void) initmultiarray(void) {\n\tPyObject *m, *d, *s;\n\tPyObject *c_api;\n\n\tif (_multiarray_module_loaded) return;\n\t_multiarray_module_loaded = 1;\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\tif (PyType_Ready(&PyArray_Type) < 0)\n return;\n\n if (setup_scalartypes(d) < 0) goto err;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMultiIter_Type.tp_iter = PyObject_SelfIter;\n\tif (PyType_Ready(&PyArrayIter_Type) < 0)\n\t\treturn; \n \n\tif (PyType_Ready(&PyArrayMapIter_Type) < 0)\n return; \n\n\tif (PyType_Ready(&PyArrayMultiIter_Type) < 0)\n\t\treturn;\n\n\tif (PyType_Ready(&PyArrayDescr_Type) < 0)\n\t\treturn;\n\n\tif (PyType_Ready(&PyArrayFlags_Type) < 0)\n\t\treturn;\n\n\tc_api = PyCObject_FromVoidPtr((void *)PyArray_API, NULL);\n\tif (PyErr_Occurred()) goto err;\n\tPyDict_SetItemString(d, \"_ARRAY_API\", c_api);\n\tPy_DECREF(c_api);\n\tif (PyErr_Occurred()) goto err;\n\n\tMultiArrayError = PyString_FromString (\"multiarray.error\");\n\tPyDict_SetItemString (d, \"error\", MultiArrayError);\n\t\n\ts = PyString_FromString(\"3.0\");\n\tPyDict_SetItemString(d, \"__version__\", s);\n\tPy_DECREF(s);\n Py_INCREF(&PyArray_Type);\n\tPyDict_SetItemString(d, \"ndarray\", (PyObject *)&PyArray_Type);\n Py_INCREF(&PyArrayIter_Type);\n\tPyDict_SetItemString(d, \"flatiter\", (PyObject *)&PyArrayIter_Type);\n Py_INCREF(&PyArrayMultiIter_Type);\n\tPyDict_SetItemString(d, \"broadcast\", \n\t\t\t (PyObject *)&PyArrayMultiIter_Type);\n\tPy_INCREF(&PyArrayDescr_Type);\n\tPyDict_SetItemString(d, \"dtype\", (PyObject *)&PyArrayDescr_Type);\n\n\tPy_INCREF(&PyArrayFlags_Type);\n\tPyDict_SetItemString(d, \"flagsobj\", (PyObject *)&PyArrayFlags_Type);\n\n set_flaginfo(d);\n\n\tif (set_typeinfo(d) != 0) goto err;\n\n\t_numpy_internal =\t\t\t\t\t\t\\\n\t\tPyImport_ImportModule(\"numpy.core._internal\");\n\tif (_numpy_internal != NULL) return;\n\n err:\t\n\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\n\treturn;\n}\n\n", + "methods": [ + { + "name": "_arraydescr_fromobj", + "long_name": "_arraydescr_fromobj( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 15, + "complexity": 3, + "token_count": 67, + "parameters": [ + "obj" + ], + "start_line": 34, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyIntList", + "long_name": "PyArray_MultiplyIntList( register int * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 74, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyList", + "long_name": "PyArray_MultiplyList( register intp * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 85, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPtr", + "long_name": "PyArray_GetPtr( PyArrayObject * obj , register intp * ind)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "obj", + "ind" + ], + "start_line": 96, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AxisConverter", + "long_name": "PyArray_AxisConverter( PyObject * obj , int * axis)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 53, + "parameters": [ + "obj", + "axis" + ], + "start_line": 110, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CompareLists", + "long_name": "PyArray_CompareLists( intp * l1 , intp * l2 , int n)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 3, + "token_count": 51, + "parameters": [ + "l1", + "l2", + "n" + ], + "start_line": 128, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_View", + "long_name": "PyArray_View( PyArrayObject * self , PyArray_Descr * type , PyTypeObject * pytype)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self", + "type", + "pytype" + ], + "start_line": 142, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ravel", + "long_name": "PyArray_Ravel( PyArrayObject * a , PyArray_CONDITION fortran)", + "filename": "multiarraymodule.c", + "nloc": 17, + "complexity": 5, + "token_count": 104, + "parameters": [ + "a", + "fortran" + ], + "start_line": 178, + "end_line": 196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "power_of_ten", + "long_name": "power_of_ten( int n)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 72, + "parameters": [ + "n" + ], + "start_line": 199, + "end_line": 211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Round", + "long_name": "PyArray_Round( PyArrayObject * a , int decimals)", + "filename": "multiarraymodule.c", + "nloc": 85, + "complexity": 19, + "token_count": 614, + "parameters": [ + "a", + "decimals" + ], + "start_line": 217, + "end_line": 309, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Flatten", + "long_name": "PyArray_Flatten( PyArrayObject * a , PyArray_CONDITION fortran)", + "filename": "multiarraymodule.c", + "nloc": 34, + "complexity": 6, + "token_count": 176, + "parameters": [ + "a", + "fortran" + ], + "start_line": 316, + "end_line": 352, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Reshape", + "long_name": "PyArray_Reshape( PyArrayObject * self , PyObject * shape)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 55, + "parameters": [ + "self", + "shape" + ], + "start_line": 363, + "end_line": 372, + "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": 375, + "end_line": 401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_old_newshape", + "long_name": "_old_newshape( PyArrayObject * self , PyArray_Dims * newdims)", + "filename": "multiarraymodule.c", + "nloc": 72, + "complexity": 17, + "token_count": 409, + "parameters": [ + "self", + "newdims" + ], + "start_line": 409, + "end_line": 496, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "_reverse_shape", + "long_name": "_reverse_shape( PyArray_Dims * newshape)", + "filename": "multiarraymodule.c", + "nloc": 14, + "complexity": 2, + "token_count": 81, + "parameters": [ + "newshape" + ], + "start_line": 500, + "end_line": 514, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Newshape", + "long_name": "PyArray_Newshape( PyArrayObject * self , PyArray_Dims * newshape , PyArray_CONDITION fortran)", + "filename": "multiarraymodule.c", + "nloc": 30, + "complexity": 11, + "token_count": 207, + "parameters": [ + "self", + "newshape", + "fortran" + ], + "start_line": 521, + "end_line": 553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Squeeze", + "long_name": "PyArray_Squeeze( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 34, + "complexity": 5, + "token_count": 204, + "parameters": [ + "self" + ], + "start_line": 562, + "end_line": 597, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Mean", + "long_name": "PyArray_Mean( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 19, + "complexity": 4, + "token_count": 139, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 604, + "end_line": 625, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Std", + "long_name": "PyArray_Std( PyArrayObject * self , int axis , int rtype , int variance)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 13, + "token_count": 450, + "parameters": [ + "self", + "axis", + "rtype", + "variance" + ], + "start_line": 632, + "end_line": 691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sum", + "long_name": "PyArray_Sum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 698, + "end_line": 708, + "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": 714, + "end_line": 724, + "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": 730, + "end_line": 740, + "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": 746, + "end_line": 757, + "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": 763, + "end_line": 774, + "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": 780, + "end_line": 791, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Compress", + "long_name": "PyArray_Compress( PyArrayObject * self , PyObject * condition , int axis)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 3, + "token_count": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 798, + "end_line": 818, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Nonzero", + "long_name": "PyArray_Nonzero( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 13, + "token_count": 414, + "parameters": [ + "self" + ], + "start_line": 824, + "end_line": 883, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Clip", + "long_name": "PyArray_Clip( PyArrayObject * self , PyObject * min , PyObject * max)", + "filename": "multiarraymodule.c", + "nloc": 28, + "complexity": 6, + "token_count": 237, + "parameters": [ + "self", + "min", + "max" + ], + "start_line": 889, + "end_line": 919, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Conjugate", + "long_name": "PyArray_Conjugate( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 9, + "token_count": 228, + "parameters": [ + "self" + ], + "start_line": 925, + "end_line": 961, + "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": 967, + "end_line": 977, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Diagonal", + "long_name": "PyArray_Diagonal( PyArrayObject * self , int offset , int axis1 , int axis2)", + "filename": "multiarraymodule.c", + "nloc": 104, + "complexity": 23, + "token_count": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 983, + "end_line": 1102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AsCArray", + "long_name": "PyArray_AsCArray( PyObject ** op , * ptr , intp * dims , int nd , PyArray_Descr * typedescr)", + "filename": "multiarraymodule.c", + "nloc": 50, + "complexity": 12, + "token_count": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 1118, + "end_line": 1169, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As1D", + "long_name": "PyArray_As1D( PyObject ** op , char ** ptr , int * d1 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 71, + "parameters": [ + "op", + "ptr", + "d1", + "typecode" + ], + "start_line": 1177, + "end_line": 1187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As2D", + "long_name": "PyArray_As2D( PyObject ** op , char ** * ptr , int * d1 , int * d2 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 92, + "parameters": [ + "op", + "ptr", + "d1", + "d2", + "typecode" + ], + "start_line": 1193, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Free", + "long_name": "PyArray_Free( PyObject * op , * ptr)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 4, + "token_count": 67, + "parameters": [ + "op", + "ptr" + ], + "start_line": 1213, + "end_line": 1224, + "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": 1228, + "end_line": 1256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Concatenate", + "long_name": "PyArray_Concatenate( PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1268, + "end_line": 1374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SwapAxes", + "long_name": "PyArray_SwapAxes( PyArrayObject * ap , int a1 , int a2)", + "filename": "multiarraymodule.c", + "nloc": 38, + "complexity": 12, + "token_count": 227, + "parameters": [ + "ap", + "a1", + "a2" + ], + "start_line": 1380, + "end_line": 1421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Transpose", + "long_name": "PyArray_Transpose( PyArrayObject * ap , PyArray_Dims * permute)", + "filename": "multiarraymodule.c", + "nloc": 46, + "complexity": 10, + "token_count": 309, + "parameters": [ + "ap", + "permute" + ], + "start_line": 1427, + "end_line": 1480, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Repeat", + "long_name": "PyArray_Repeat( PyArrayObject * aop , PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 78, + "complexity": 15, + "token_count": 523, + "parameters": [ + "aop", + "op", + "axis" + ], + "start_line": 1486, + "end_line": 1581, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "_signbit_set", + "long_name": "_signbit_set( PyArrayObject * arr)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 89, + "parameters": [ + "arr" + ], + "start_line": 1585, + "end_line": 1602, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ScalarKind", + "long_name": "PyArray_ScalarKind( int typenum , PyArrayObject ** arr)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 8, + "token_count": 80, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 1607, + "end_line": 1619, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCoerceScalar", + "long_name": "PyArray_CanCoerceScalar( char thistype , char neededtype , PyArray_SCALARKIND scalar)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 9, + "token_count": 101, + "parameters": [ + "thistype", + "neededtype", + "scalar" + ], + "start_line": 1623, + "end_line": 1645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 73, + "complexity": 15, + "token_count": 482, + "parameters": [ + "op", + "retn" + ], + "start_line": 1653, + "end_line": 1732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Choose", + "long_name": "PyArray_Choose( PyArrayObject * ip , PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 15, + "token_count": 518, + "parameters": [ + "ip", + "op" + ], + "start_line": 1739, + "end_line": 1820, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 82, + "top_nesting_level": 0 + }, + { + "name": "_strided_copy", + "long_name": "_strided_copy( char * dst , intp dststride , char * src , intp srcstride , intp num , int elsize)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 48, + "parameters": [ + "dst", + "dststride", + "src", + "srcstride", + "num", + "elsize" + ], + "start_line": 1823, + "end_line": 1830, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "_new_sort", + "long_name": "_new_sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 8, + "token_count": 284, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1841, + "end_line": 1895, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "_new_argsort", + "long_name": "_new_argsort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 67, + "complexity": 13, + "token_count": 498, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1898, + "end_line": 1976, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "qsortCompare", + "long_name": "qsortCompare( const * a , const * b)", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "a", + "b" + ], + "start_line": 1984, + "end_line": 1987, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sort", + "long_name": "PyArray_Sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 52, + "complexity": 14, + "token_count": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 2042, + "end_line": 2108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "argsort_static_compare", + "long_name": "argsort_static_compare( const * ip1 , const * ip2)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 1, + "token_count": 67, + "parameters": [ + "ip1", + "ip2" + ], + "start_line": 2114, + "end_line": 2122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgSort", + "long_name": "PyArray_ArgSort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 15, + "token_count": 493, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 2128, + "end_line": 2208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_LexSort", + "long_name": "PyArray_LexSort( PyObject * sort_keys , int axis)", + "filename": "multiarraymodule.c", + "nloc": 132, + "complexity": 36, + "token_count": 1162, + "parameters": [ + "sort_keys", + "axis" + ], + "start_line": 2220, + "end_line": 2364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 145, + "top_nesting_level": 0 + }, + { + "name": "local_where", + "long_name": "local_where( PyArrayObject * ap1 , PyArrayObject * ap2 , PyArrayObject * ret)", + "filename": "multiarraymodule.c", + "nloc": 35, + "complexity": 7, + "token_count": 243, + "parameters": [ + "ap1", + "ap2", + "ret" + ], + "start_line": 2368, + "end_line": 2403, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SearchSorted", + "long_name": "PyArray_SearchSorted( PyArrayObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 5, + "token_count": 231, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2409, + "end_line": 2454, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2461, + "end_line": 2485, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 79, + "complexity": 15, + "token_count": 624, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2494, + "end_line": 2592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 89, + "complexity": 17, + "token_count": 680, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2600, + "end_line": 2711, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 286, + "parameters": [ + "op" + ], + "start_line": 2717, + "end_line": 2771, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Correlate", + "long_name": "PyArray_Correlate( PyObject * op1 , PyObject * op2 , int mode)", + "filename": "multiarraymodule.c", + "nloc": 86, + "complexity": 13, + "token_count": 601, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2777, + "end_line": 2874, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgMin", + "long_name": "PyArray_ArgMin( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 5, + "token_count": 141, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2881, + "end_line": 2905, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Max", + "long_name": "PyArray_Max( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 71, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2911, + "end_line": 2922, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Min", + "long_name": "PyArray_Min( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 71, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2928, + "end_line": 2939, + "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": 2945, + "end_line": 2968, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgMax", + "long_name": "PyArray_ArgMax( PyArrayObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 7, + "token_count": 326, + "parameters": [ + "op", + "axis" + ], + "start_line": 2975, + "end_line": 3032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Take", + "long_name": "PyArray_Take( PyArrayObject * self0 , PyObject * indices0 , int axis)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 473, + "parameters": [ + "self0", + "indices0", + "axis" + ], + "start_line": 3039, + "end_line": 3114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Put", + "long_name": "PyArray_Put( PyArrayObject * self , PyObject * values0 , PyObject * indices0)", + "filename": "multiarraymodule.c", + "nloc": 64, + "complexity": 15, + "token_count": 479, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 3120, + "end_line": 3190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PutMask", + "long_name": "PyArray_PutMask( PyArrayObject * self , PyObject * values0 , PyObject * mask0)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 422, + "parameters": [ + "self", + "values0", + "mask0" + ], + "start_line": 3196, + "end_line": 3267, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Converter", + "long_name": "PyArray_Converter( PyObject * object , PyObject ** address)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3283, + "end_line": 3295, + "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": 3301, + "end_line": 3309, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConditionConverter", + "long_name": "PyArray_ConditionConverter( PyObject * object , PyArray_CONDITION * val)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 4, + "token_count": 54, + "parameters": [ + "object", + "val" + ], + "start_line": 3315, + "end_line": 3326, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_TypestrConvert", + "long_name": "PyArray_TypestrConvert( int itemsize , int gentype)", + "filename": "multiarraymodule.c", + "nloc": 96, + "complexity": 35, + "token_count": 308, + "parameters": [ + "itemsize", + "gentype" + ], + "start_line": 3334, + "end_line": 3449, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BufferConverter", + "long_name": "PyArray_BufferConverter( PyObject * obj , PyArray_Chunk * buf)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 6, + "token_count": 147, + "parameters": [ + "obj", + "buf" + ], + "start_line": 3467, + "end_line": 3492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpConverter", + "long_name": "PyArray_IntpConverter( PyObject * obj , PyArray_Dims * seq)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 10, + "token_count": 189, + "parameters": [ + "obj", + "seq" + ], + "start_line": 3507, + "end_line": 3543, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "_use_inherit", + "long_name": "_use_inherit( PyArray_Descr * type , PyObject * newobj , int * errflag)", + "filename": "multiarraymodule.c", + "nloc": 35, + "complexity": 7, + "token_count": 171, + "parameters": [ + "type", + "newobj", + "errflag" + ], + "start_line": 3561, + "end_line": 3599, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_tuple", + "long_name": "_convert_from_tuple( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 400, + "parameters": [ + "obj" + ], + "start_line": 3602, + "end_line": 3680, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 93, + "complexity": 24, + "token_count": 596, + "parameters": [ + "obj" + ], + "start_line": 3688, + "end_line": 3783, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3794, + "end_line": 3865, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_commastring", + "long_name": "_convert_from_commastring( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 92, + "parameters": [ + "obj", + "align" + ], + "start_line": 3878, + "end_line": 3894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_use_fields_dict", + "long_name": "_use_fields_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 1, + "token_count": 29, + "parameters": [ + "obj", + "align" + ], + "start_line": 3931, + "end_line": 3936, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_dict", + "long_name": "_convert_from_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 117, + "complexity": 30, + "token_count": 752, + "parameters": [ + "obj", + "align" + ], + "start_line": 3939, + "end_line": 4065, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter2", + "long_name": "PyArray_DescrConverter2( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 37, + "parameters": [ + "obj", + "at" + ], + "start_line": 4083, + "end_line": 4090, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter", + "long_name": "PyArray_DescrConverter( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 141, + "complexity": 55, + "token_count": 886, + "parameters": [ + "obj", + "at" + ], + "start_line": 4107, + "end_line": 4287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 181, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ByteorderConverter", + "long_name": "PyArray_ByteorderConverter( PyObject * obj , char * endian)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 16, + "token_count": 218, + "parameters": [ + "obj", + "endian" + ], + "start_line": 4293, + "end_line": 4325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SortkindConverter", + "long_name": "PyArray_SortkindConverter( PyObject * obj , PyArray_SORTKIND * sortkind)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 11, + "token_count": 162, + "parameters": [ + "obj", + "sortkind" + ], + "start_line": 4331, + "end_line": 4357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EquivTypes", + "long_name": "PyArray_EquivTypes( PyArray_Descr * typ1 , PyArray_Descr * typ2)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 8, + "token_count": 138, + "parameters": [ + "typ1", + "typ2" + ], + "start_line": 4366, + "end_line": 4385, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_prepend_ones", + "long_name": "_prepend_ones( PyArrayObject * arr , int nd , int ndmin)", + "filename": "multiarraymodule.c", + "nloc": 23, + "complexity": 3, + "token_count": 175, + "parameters": [ + "arr", + "nd", + "ndmin" + ], + "start_line": 4390, + "end_line": 4415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 20, + "token_count": 410, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4437, + "end_line": 4516, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Empty", + "long_name": "PyArray_Empty( int nd , intp * dims , PyArray_Descr * type , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 14, + "complexity": 4, + "token_count": 96, + "parameters": [ + "nd", + "dims", + "type", + "fortran" + ], + "start_line": 4524, + "end_line": 4539, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_empty", + "long_name": "array_empty( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 2, + "token_count": 130, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4545, + "end_line": 4569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_scalar", + "long_name": "array_scalar( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 10, + "token_count": 254, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4574, + "end_line": 4632, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zeros", + "long_name": "PyArray_Zeros( int nd , intp * dims , PyArray_Descr * type , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 4, + "token_count": 134, + "parameters": [ + "nd", + "dims", + "type", + "fortran" + ], + "start_line": 4641, + "end_line": 4665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_zeros", + "long_name": "array_zeros( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 2, + "token_count": 133, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4671, + "end_line": 4695, + "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": 4702, + "end_line": 4711, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_skip_sep", + "long_name": "_skip_sep( char ** ptr , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 78, + "parameters": [ + "ptr", + "sep" + ], + "start_line": 4714, + "end_line": 4725, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 133, + "complexity": 22, + "token_count": 711, + "parameters": [ + "data", + "slen", + "dtype", + "n", + "sep" + ], + "start_line": 4730, + "end_line": 4872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 143, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 2, + "token_count": 116, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4877, + "end_line": 4894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 114, + "complexity": 22, + "token_count": 664, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4908, + "end_line": 5036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "top_nesting_level": 0 + }, + { + "name": "array_fromfile", + "long_name": "array_fromfile( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 7, + "token_count": 225, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 5054, + "end_line": 5092, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromBuffer", + "long_name": "PyArray_FromBuffer( PyObject * buf , PyArray_Descr * type , intp count , intp offset)", + "filename": "multiarraymodule.c", + "nloc": 83, + "complexity": 16, + "token_count": 446, + "parameters": [ + "buf", + "type", + "count", + "offset" + ], + "start_line": 5096, + "end_line": 5189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "array_frombuffer", + "long_name": "array_frombuffer( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 121, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 5205, + "end_line": 5222, + "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": 5228, + "end_line": 5239, + "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": 5246, + "end_line": 5252, + "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": 5259, + "end_line": 5265, + "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": 5269, + "end_line": 5275, + "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": 5279, + "end_line": 5288, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Arange", + "long_name": "PyArray_Arange( double start , double stop , double step , int type_num)", + "filename": "multiarraymodule.c", + "nloc": 40, + "complexity": 9, + "token_count": 300, + "parameters": [ + "start", + "stop", + "step", + "type_num" + ], + "start_line": 5295, + "end_line": 5346, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "_calc_length", + "long_name": "_calc_length( PyObject * start , PyObject * stop , PyObject * step , PyObject ** next , int cmplx)", + "filename": "multiarraymodule.c", + "nloc": 31, + "complexity": 10, + "token_count": 235, + "parameters": [ + "start", + "stop", + "step", + "next", + "cmplx" + ], + "start_line": 5352, + "end_line": 5384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArangeObj", + "long_name": "PyArray_ArangeObj( PyObject * start , PyObject * stop , PyObject * step , PyArray_Descr * dtype)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 19, + "token_count": 461, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 5391, + "end_line": 5475, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "array_arange", + "long_name": "array_arange( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 100, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 5488, + "end_line": 5500, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNDArrayCVersion", + "long_name": "PyArray_GetNDArrayCVersion()", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [], + "start_line": 5507, + "end_line": 5510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array__get_ndarray_c_version", + "long_name": "array__get_ndarray_c_version( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5516, + "end_line": 5522, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_set_string_function", + "long_name": "array_set_string_function( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 98, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5528, + "end_line": 5544, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "array_set_ops_function", + "long_name": "array_set_ops_function( PyObject * self , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 5550, + "end_line": 5567, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Where", + "long_name": "PyArray_Where( PyObject * condition , PyObject * x , PyObject * y)", + "filename": "multiarraymodule.c", + "nloc": 31, + "complexity": 8, + "token_count": 233, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5574, + "end_line": 5614, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_where", + "long_name": "array_where( PyObject * ignored , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 60, + "parameters": [ + "ignored", + "args" + ], + "start_line": 5622, + "end_line": 5630, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_lexsort", + "long_name": "array_lexsort( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 5642, + "end_line": 5652, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_register_dtype", + "long_name": "array_register_dtype( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 3, + "token_count": 64, + "parameters": [ + "dummy", + "args" + ], + "start_line": 5661, + "end_line": 5672, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_can_cast_safely", + "long_name": "array_can_cast_safely( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 5, + "token_count": 128, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5679, + "end_line": 5702, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "new_buffer", + "long_name": "new_buffer( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 7, + "complexity": 2, + "token_count": 37, + "parameters": [ + "dummy", + "args" + ], + "start_line": 5709, + "end_line": 5717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "buffer_buffer", + "long_name": "buffer_buffer( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 120, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5726, + "end_line": 5744, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "setup_scalartypes", + "long_name": "setup_scalartypes( PyObject * dict)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 10, + "token_count": 351, + "parameters": [ + "dict" + ], + "start_line": 5810, + "end_line": 5923, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 114, + "top_nesting_level": 0 + }, + { + "name": "set_flaginfo", + "long_name": "set_flaginfo( PyObject * d)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 1, + "token_count": 152, + "parameters": [ + "d" + ], + "start_line": 5928, + "end_line": 5952, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "initmultiarray", + "long_name": "initmultiarray()", + "filename": "multiarraymodule.c", + "nloc": 57, + "complexity": 16, + "token_count": 392, + "parameters": [], + "start_line": 5957, + "end_line": 6032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "_arraydescr_fromobj", + "long_name": "_arraydescr_fromobj( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 15, + "complexity": 3, + "token_count": 67, + "parameters": [ + "obj" + ], + "start_line": 34, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyIntList", + "long_name": "PyArray_MultiplyIntList( register int * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 74, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyList", + "long_name": "PyArray_MultiplyList( register intp * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 85, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPtr", + "long_name": "PyArray_GetPtr( PyArrayObject * obj , register intp * ind)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "obj", + "ind" + ], + "start_line": 96, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AxisConverter", + "long_name": "PyArray_AxisConverter( PyObject * obj , int * axis)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 53, + "parameters": [ + "obj", + "axis" + ], + "start_line": 110, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CompareLists", + "long_name": "PyArray_CompareLists( intp * l1 , intp * l2 , int n)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 3, + "token_count": 51, + "parameters": [ + "l1", + "l2", + "n" + ], + "start_line": 128, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_View", + "long_name": "PyArray_View( PyArrayObject * self , PyArray_Descr * type , PyTypeObject * pytype)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self", + "type", + "pytype" + ], + "start_line": 142, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ravel", + "long_name": "PyArray_Ravel( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 102, + "parameters": [ + "a", + "fortran" + ], + "start_line": 178, + "end_line": 195, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "power_of_ten", + "long_name": "power_of_ten( int n)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 72, + "parameters": [ + "n" + ], + "start_line": 198, + "end_line": 210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Round", + "long_name": "PyArray_Round( PyArrayObject * a , int decimals)", + "filename": "multiarraymodule.c", + "nloc": 85, + "complexity": 19, + "token_count": 614, + "parameters": [ + "a", + "decimals" + ], + "start_line": 216, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Flatten", + "long_name": "PyArray_Flatten( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 6, + "token_count": 176, + "parameters": [ + "a", + "fortran" + ], + "start_line": 315, + "end_line": 350, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Reshape", + "long_name": "PyArray_Reshape( PyArrayObject * self , PyObject * shape)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "shape" + ], + "start_line": 361, + "end_line": 370, + "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": 373, + "end_line": 399, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Newshape", + "long_name": "PyArray_Newshape( PyArrayObject * self , PyArray_Dims * newdims)", + "filename": "multiarraymodule.c", + "nloc": 72, + "complexity": 17, + "token_count": 409, + "parameters": [ + "self", + "newdims" + ], + "start_line": 410, + "end_line": 497, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Squeeze", + "long_name": "PyArray_Squeeze( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 34, + "complexity": 5, + "token_count": 204, + "parameters": [ + "self" + ], + "start_line": 506, + "end_line": 541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Mean", + "long_name": "PyArray_Mean( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 19, + "complexity": 4, + "token_count": 139, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 548, + "end_line": 569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Std", + "long_name": "PyArray_Std( PyArrayObject * self , int axis , int rtype , int variance)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 13, + "token_count": 450, + "parameters": [ + "self", + "axis", + "rtype", + "variance" + ], + "start_line": 576, + "end_line": 635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sum", + "long_name": "PyArray_Sum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 642, + "end_line": 652, + "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": 658, + "end_line": 668, + "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": 674, + "end_line": 684, + "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": 690, + "end_line": 701, + "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": 707, + "end_line": 718, + "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": 724, + "end_line": 735, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Compress", + "long_name": "PyArray_Compress( PyArrayObject * self , PyObject * condition , int axis)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 3, + "token_count": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 742, + "end_line": 762, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Nonzero", + "long_name": "PyArray_Nonzero( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 13, + "token_count": 414, + "parameters": [ + "self" + ], + "start_line": 768, + "end_line": 827, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Clip", + "long_name": "PyArray_Clip( PyArrayObject * self , PyObject * min , PyObject * max)", + "filename": "multiarraymodule.c", + "nloc": 28, + "complexity": 6, + "token_count": 237, + "parameters": [ + "self", + "min", + "max" + ], + "start_line": 833, + "end_line": 863, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Conjugate", + "long_name": "PyArray_Conjugate( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 9, + "token_count": 228, + "parameters": [ + "self" + ], + "start_line": 869, + "end_line": 905, + "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": 911, + "end_line": 921, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Diagonal", + "long_name": "PyArray_Diagonal( PyArrayObject * self , int offset , int axis1 , int axis2)", + "filename": "multiarraymodule.c", + "nloc": 104, + "complexity": 23, + "token_count": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 927, + "end_line": 1046, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AsCArray", + "long_name": "PyArray_AsCArray( PyObject ** op , * ptr , intp * dims , int nd , PyArray_Descr * typedescr)", + "filename": "multiarraymodule.c", + "nloc": 50, + "complexity": 12, + "token_count": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 1062, + "end_line": 1113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As1D", + "long_name": "PyArray_As1D( PyObject ** op , char ** ptr , int * d1 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 71, + "parameters": [ + "op", + "ptr", + "d1", + "typecode" + ], + "start_line": 1121, + "end_line": 1131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As2D", + "long_name": "PyArray_As2D( PyObject ** op , char ** * ptr , int * d1 , int * d2 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 92, + "parameters": [ + "op", + "ptr", + "d1", + "d2", + "typecode" + ], + "start_line": 1137, + "end_line": 1149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Free", + "long_name": "PyArray_Free( PyObject * op , * ptr)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 4, + "token_count": 67, + "parameters": [ + "op", + "ptr" + ], + "start_line": 1157, + "end_line": 1168, + "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": 1172, + "end_line": 1200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Concatenate", + "long_name": "PyArray_Concatenate( PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1212, + "end_line": 1318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SwapAxes", + "long_name": "PyArray_SwapAxes( PyArrayObject * ap , int a1 , int a2)", + "filename": "multiarraymodule.c", + "nloc": 38, + "complexity": 12, + "token_count": 227, + "parameters": [ + "ap", + "a1", + "a2" + ], + "start_line": 1324, + "end_line": 1365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Transpose", + "long_name": "PyArray_Transpose( PyArrayObject * ap , PyArray_Dims * permute)", + "filename": "multiarraymodule.c", + "nloc": 46, + "complexity": 10, + "token_count": 309, + "parameters": [ + "ap", + "permute" + ], + "start_line": 1371, + "end_line": 1424, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Repeat", + "long_name": "PyArray_Repeat( PyArrayObject * aop , PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 78, + "complexity": 15, + "token_count": 523, + "parameters": [ + "aop", + "op", + "axis" + ], + "start_line": 1430, + "end_line": 1525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "_signbit_set", + "long_name": "_signbit_set( PyArrayObject * arr)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 89, + "parameters": [ + "arr" + ], + "start_line": 1529, + "end_line": 1546, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ScalarKind", + "long_name": "PyArray_ScalarKind( int typenum , PyArrayObject ** arr)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 8, + "token_count": 80, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 1551, + "end_line": 1563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCoerceScalar", + "long_name": "PyArray_CanCoerceScalar( char thistype , char neededtype , PyArray_SCALARKIND scalar)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 9, + "token_count": 101, + "parameters": [ + "thistype", + "neededtype", + "scalar" + ], + "start_line": 1567, + "end_line": 1589, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 73, + "complexity": 15, + "token_count": 482, + "parameters": [ + "op", + "retn" + ], + "start_line": 1597, + "end_line": 1676, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Choose", + "long_name": "PyArray_Choose( PyArrayObject * ip , PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 15, + "token_count": 518, + "parameters": [ + "ip", + "op" + ], + "start_line": 1683, + "end_line": 1764, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 82, + "top_nesting_level": 0 + }, + { + "name": "_strided_copy", + "long_name": "_strided_copy( char * dst , intp dststride , char * src , intp srcstride , intp num , int elsize)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 48, + "parameters": [ + "dst", + "dststride", + "src", + "srcstride", + "num", + "elsize" + ], + "start_line": 1767, + "end_line": 1774, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "_new_sort", + "long_name": "_new_sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 8, + "token_count": 284, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1785, + "end_line": 1839, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "_new_argsort", + "long_name": "_new_argsort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 67, + "complexity": 13, + "token_count": 498, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1842, + "end_line": 1920, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "qsortCompare", + "long_name": "qsortCompare( const * a , const * b)", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "a", + "b" + ], + "start_line": 1928, + "end_line": 1931, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sort", + "long_name": "PyArray_Sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 52, + "complexity": 14, + "token_count": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1986, + "end_line": 2052, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "argsort_static_compare", + "long_name": "argsort_static_compare( const * ip1 , const * ip2)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 1, + "token_count": 67, + "parameters": [ + "ip1", + "ip2" + ], + "start_line": 2058, + "end_line": 2066, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgSort", + "long_name": "PyArray_ArgSort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 15, + "token_count": 493, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 2072, + "end_line": 2152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_LexSort", + "long_name": "PyArray_LexSort( PyObject * sort_keys , int axis)", + "filename": "multiarraymodule.c", + "nloc": 132, + "complexity": 36, + "token_count": 1162, + "parameters": [ + "sort_keys", + "axis" + ], + "start_line": 2164, + "end_line": 2308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 145, + "top_nesting_level": 0 + }, + { + "name": "local_where", + "long_name": "local_where( PyArrayObject * ap1 , PyArrayObject * ap2 , PyArrayObject * ret)", + "filename": "multiarraymodule.c", + "nloc": 35, + "complexity": 7, + "token_count": 243, + "parameters": [ + "ap1", + "ap2", + "ret" + ], + "start_line": 2312, + "end_line": 2347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SearchSorted", + "long_name": "PyArray_SearchSorted( PyArrayObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 5, + "token_count": 231, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2353, + "end_line": 2398, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2405, + "end_line": 2429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 79, + "complexity": 15, + "token_count": 624, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2438, + "end_line": 2536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 89, + "complexity": 17, + "token_count": 680, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2544, + "end_line": 2655, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 286, + "parameters": [ + "op" + ], + "start_line": 2661, + "end_line": 2715, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Correlate", + "long_name": "PyArray_Correlate( PyObject * op1 , PyObject * op2 , int mode)", + "filename": "multiarraymodule.c", + "nloc": 86, + "complexity": 13, + "token_count": 601, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2721, + "end_line": 2818, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgMin", + "long_name": "PyArray_ArgMin( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 5, + "token_count": 141, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2825, + "end_line": 2849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Max", + "long_name": "PyArray_Max( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 71, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2855, + "end_line": 2866, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Min", + "long_name": "PyArray_Min( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 71, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2872, + "end_line": 2883, + "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": 2889, + "end_line": 2912, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgMax", + "long_name": "PyArray_ArgMax( PyArrayObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 7, + "token_count": 326, + "parameters": [ + "op", + "axis" + ], + "start_line": 2919, + "end_line": 2976, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Take", + "long_name": "PyArray_Take( PyArrayObject * self0 , PyObject * indices0 , int axis)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 473, + "parameters": [ + "self0", + "indices0", + "axis" + ], + "start_line": 2983, + "end_line": 3058, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Put", + "long_name": "PyArray_Put( PyArrayObject * self , PyObject * values0 , PyObject * indices0)", + "filename": "multiarraymodule.c", + "nloc": 64, + "complexity": 15, + "token_count": 479, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 3064, + "end_line": 3134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PutMask", + "long_name": "PyArray_PutMask( PyArrayObject * self , PyObject * values0 , PyObject * mask0)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 422, + "parameters": [ + "self", + "values0", + "mask0" + ], + "start_line": 3140, + "end_line": 3211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Converter", + "long_name": "PyArray_Converter( PyObject * object , PyObject ** address)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3227, + "end_line": 3239, + "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": 3245, + "end_line": 3253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_TypestrConvert", + "long_name": "PyArray_TypestrConvert( int itemsize , int gentype)", + "filename": "multiarraymodule.c", + "nloc": 96, + "complexity": 35, + "token_count": 308, + "parameters": [ + "itemsize", + "gentype" + ], + "start_line": 3260, + "end_line": 3375, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BufferConverter", + "long_name": "PyArray_BufferConverter( PyObject * obj , PyArray_Chunk * buf)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 6, + "token_count": 147, + "parameters": [ + "obj", + "buf" + ], + "start_line": 3393, + "end_line": 3418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpConverter", + "long_name": "PyArray_IntpConverter( PyObject * obj , PyArray_Dims * seq)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 10, + "token_count": 189, + "parameters": [ + "obj", + "seq" + ], + "start_line": 3433, + "end_line": 3469, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "_use_inherit", + "long_name": "_use_inherit( PyArray_Descr * type , PyObject * newobj , int * errflag)", + "filename": "multiarraymodule.c", + "nloc": 35, + "complexity": 7, + "token_count": 171, + "parameters": [ + "type", + "newobj", + "errflag" + ], + "start_line": 3487, + "end_line": 3525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_tuple", + "long_name": "_convert_from_tuple( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 400, + "parameters": [ + "obj" + ], + "start_line": 3528, + "end_line": 3606, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 93, + "complexity": 24, + "token_count": 596, + "parameters": [ + "obj" + ], + "start_line": 3614, + "end_line": 3709, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3720, + "end_line": 3791, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_commastring", + "long_name": "_convert_from_commastring( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 92, + "parameters": [ + "obj", + "align" + ], + "start_line": 3804, + "end_line": 3820, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_use_fields_dict", + "long_name": "_use_fields_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 1, + "token_count": 29, + "parameters": [ + "obj", + "align" + ], + "start_line": 3857, + "end_line": 3862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_dict", + "long_name": "_convert_from_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 117, + "complexity": 30, + "token_count": 752, + "parameters": [ + "obj", + "align" + ], + "start_line": 3865, + "end_line": 3991, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter2", + "long_name": "PyArray_DescrConverter2( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 37, + "parameters": [ + "obj", + "at" + ], + "start_line": 4009, + "end_line": 4016, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter", + "long_name": "PyArray_DescrConverter( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 141, + "complexity": 55, + "token_count": 886, + "parameters": [ + "obj", + "at" + ], + "start_line": 4033, + "end_line": 4213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 181, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ByteorderConverter", + "long_name": "PyArray_ByteorderConverter( PyObject * obj , char * endian)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 16, + "token_count": 218, + "parameters": [ + "obj", + "endian" + ], + "start_line": 4219, + "end_line": 4251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SortkindConverter", + "long_name": "PyArray_SortkindConverter( PyObject * obj , PyArray_SORTKIND * sortkind)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 11, + "token_count": 162, + "parameters": [ + "obj", + "sortkind" + ], + "start_line": 4257, + "end_line": 4283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EquivTypes", + "long_name": "PyArray_EquivTypes( PyArray_Descr * typ1 , PyArray_Descr * typ2)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 8, + "token_count": 138, + "parameters": [ + "typ1", + "typ2" + ], + "start_line": 4292, + "end_line": 4311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_prepend_ones", + "long_name": "_prepend_ones( PyArrayObject * arr , int nd , int ndmin)", + "filename": "multiarraymodule.c", + "nloc": 23, + "complexity": 3, + "token_count": 175, + "parameters": [ + "arr", + "nd", + "ndmin" + ], + "start_line": 4316, + "end_line": 4341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 15, + "token_count": 373, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4363, + "end_line": 4438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Empty", + "long_name": "PyArray_Empty( int nd , intp * dims , PyArray_Descr * type , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 14, + "complexity": 4, + "token_count": 96, + "parameters": [ + "nd", + "dims", + "type", + "fortran" + ], + "start_line": 4446, + "end_line": 4461, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_empty", + "long_name": "array_empty( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 2, + "token_count": 130, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4467, + "end_line": 4491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_scalar", + "long_name": "array_scalar( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 10, + "token_count": 254, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4496, + "end_line": 4554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zeros", + "long_name": "PyArray_Zeros( int nd , intp * dims , PyArray_Descr * type , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 4, + "token_count": 134, + "parameters": [ + "nd", + "dims", + "type", + "fortran" + ], + "start_line": 4563, + "end_line": 4587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_zeros", + "long_name": "array_zeros( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 2, + "token_count": 133, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4593, + "end_line": 4617, + "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": 4624, + "end_line": 4633, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_skip_sep", + "long_name": "_skip_sep( char ** ptr , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 78, + "parameters": [ + "ptr", + "sep" + ], + "start_line": 4636, + "end_line": 4647, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 133, + "complexity": 22, + "token_count": 711, + "parameters": [ + "data", + "slen", + "dtype", + "n", + "sep" + ], + "start_line": 4652, + "end_line": 4794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 143, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 2, + "token_count": 116, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4799, + "end_line": 4816, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 114, + "complexity": 22, + "token_count": 664, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4830, + "end_line": 4958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "top_nesting_level": 0 + }, + { + "name": "array_fromfile", + "long_name": "array_fromfile( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 7, + "token_count": 225, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4976, + "end_line": 5014, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromBuffer", + "long_name": "PyArray_FromBuffer( PyObject * buf , PyArray_Descr * type , intp count , intp offset)", + "filename": "multiarraymodule.c", + "nloc": 83, + "complexity": 16, + "token_count": 446, + "parameters": [ + "buf", + "type", + "count", + "offset" + ], + "start_line": 5018, + "end_line": 5111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "array_frombuffer", + "long_name": "array_frombuffer( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 121, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 5127, + "end_line": 5144, + "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": 5150, + "end_line": 5161, + "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": 5168, + "end_line": 5174, + "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": 5181, + "end_line": 5187, + "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": 5191, + "end_line": 5197, + "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": 5201, + "end_line": 5210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Arange", + "long_name": "PyArray_Arange( double start , double stop , double step , int type_num)", + "filename": "multiarraymodule.c", + "nloc": 40, + "complexity": 9, + "token_count": 300, + "parameters": [ + "start", + "stop", + "step", + "type_num" + ], + "start_line": 5217, + "end_line": 5268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "_calc_length", + "long_name": "_calc_length( PyObject * start , PyObject * stop , PyObject * step , PyObject ** next , int cmplx)", + "filename": "multiarraymodule.c", + "nloc": 31, + "complexity": 10, + "token_count": 235, + "parameters": [ + "start", + "stop", + "step", + "next", + "cmplx" + ], + "start_line": 5274, + "end_line": 5306, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArangeObj", + "long_name": "PyArray_ArangeObj( PyObject * start , PyObject * stop , PyObject * step , PyArray_Descr * dtype)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 19, + "token_count": 461, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 5313, + "end_line": 5397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "array_arange", + "long_name": "array_arange( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 100, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 5410, + "end_line": 5422, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNDArrayCVersion", + "long_name": "PyArray_GetNDArrayCVersion()", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [], + "start_line": 5428, + "end_line": 5431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array__get_ndarray_c_version", + "long_name": "array__get_ndarray_c_version( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5437, + "end_line": 5443, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_set_string_function", + "long_name": "array_set_string_function( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 98, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5449, + "end_line": 5465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "array_set_ops_function", + "long_name": "array_set_ops_function( PyObject * self , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 5471, + "end_line": 5488, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Where", + "long_name": "PyArray_Where( PyObject * condition , PyObject * x , PyObject * y)", + "filename": "multiarraymodule.c", + "nloc": 31, + "complexity": 8, + "token_count": 233, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5495, + "end_line": 5535, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_where", + "long_name": "array_where( PyObject * ignored , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 60, + "parameters": [ + "ignored", + "args" + ], + "start_line": 5543, + "end_line": 5551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_lexsort", + "long_name": "array_lexsort( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 5563, + "end_line": 5573, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_register_dtype", + "long_name": "array_register_dtype( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 3, + "token_count": 64, + "parameters": [ + "dummy", + "args" + ], + "start_line": 5582, + "end_line": 5593, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_can_cast_safely", + "long_name": "array_can_cast_safely( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 5, + "token_count": 128, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5600, + "end_line": 5623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "new_buffer", + "long_name": "new_buffer( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 7, + "complexity": 2, + "token_count": 37, + "parameters": [ + "dummy", + "args" + ], + "start_line": 5630, + "end_line": 5638, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "buffer_buffer", + "long_name": "buffer_buffer( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 120, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5647, + "end_line": 5665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "setup_scalartypes", + "long_name": "setup_scalartypes( PyObject * dict)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 10, + "token_count": 351, + "parameters": [ + "dict" + ], + "start_line": 5731, + "end_line": 5844, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 114, + "top_nesting_level": 0 + }, + { + "name": "set_flaginfo", + "long_name": "set_flaginfo( PyObject * d)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 1, + "token_count": 152, + "parameters": [ + "d" + ], + "start_line": 5849, + "end_line": 5873, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "initmultiarray", + "long_name": "initmultiarray()", + "filename": "multiarraymodule.c", + "nloc": 57, + "complexity": 16, + "token_count": 392, + "parameters": [], + "start_line": 5878, + "end_line": 5953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 20, + "token_count": 410, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4437, + "end_line": 4516, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Flatten", + "long_name": "PyArray_Flatten( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 6, + "token_count": 176, + "parameters": [ + "a", + "fortran" + ], + "start_line": 315, + "end_line": 350, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_old_newshape", + "long_name": "_old_newshape( PyArrayObject * self , PyArray_Dims * newdims)", + "filename": "multiarraymodule.c", + "nloc": 72, + "complexity": 17, + "token_count": 409, + "parameters": [ + "self", + "newdims" + ], + "start_line": 409, + "end_line": 496, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Newshape", + "long_name": "PyArray_Newshape( PyArrayObject * self , PyArray_Dims * newshape , PyArray_CONDITION fortran)", + "filename": "multiarraymodule.c", + "nloc": 30, + "complexity": 11, + "token_count": 207, + "parameters": [ + "self", + "newshape", + "fortran" + ], + "start_line": 521, + "end_line": 553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "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": 3301, + "end_line": 3309, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ravel", + "long_name": "PyArray_Ravel( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 102, + "parameters": [ + "a", + "fortran" + ], + "start_line": 178, + "end_line": 195, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConditionConverter", + "long_name": "PyArray_ConditionConverter( PyObject * object , PyArray_CONDITION * val)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 4, + "token_count": 54, + "parameters": [ + "object", + "val" + ], + "start_line": 3315, + "end_line": 3326, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ravel", + "long_name": "PyArray_Ravel( PyArrayObject * a , PyArray_CONDITION fortran)", + "filename": "multiarraymodule.c", + "nloc": 17, + "complexity": 5, + "token_count": 104, + "parameters": [ + "a", + "fortran" + ], + "start_line": 178, + "end_line": 196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Newshape", + "long_name": "PyArray_Newshape( PyArrayObject * self , PyArray_Dims * newdims)", + "filename": "multiarraymodule.c", + "nloc": 72, + "complexity": 17, + "token_count": 409, + "parameters": [ + "self", + "newdims" + ], + "start_line": 410, + "end_line": 497, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Reshape", + "long_name": "PyArray_Reshape( PyArrayObject * self , PyObject * shape)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 55, + "parameters": [ + "self", + "shape" + ], + "start_line": 363, + "end_line": 372, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_reverse_shape", + "long_name": "_reverse_shape( PyArray_Dims * newshape)", + "filename": "multiarraymodule.c", + "nloc": 14, + "complexity": 2, + "token_count": 81, + "parameters": [ + "newshape" + ], + "start_line": 500, + "end_line": 514, + "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 , PyArray_CONDITION fortran)", + "filename": "multiarraymodule.c", + "nloc": 34, + "complexity": 6, + "token_count": 176, + "parameters": [ + "a", + "fortran" + ], + "start_line": 316, + "end_line": 352, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + } + ], + "nloc": 4605, + "complexity": 1023, + "token_count": 29804, + "diff_parsed": { + "added": [ + "PyArray_Ravel(PyArrayObject *a, PyArray_CONDITION fortran)", + "\tif (fortran == PyArray_DONTCARE)", + "\t\tfortran = PyArray_ISFORTRAN(a);", + "", + "\t\treturn PyArray_Newshape(a, &newdim, PyArray_FALSE);", + "PyArray_Flatten(PyArrayObject *a, PyArray_CONDITION fortran)", + "\tif (fortran == PyArray_DONTCARE)", + "\t\tfortran = PyArray_ISFORTRAN(a);", + " ret = PyArray_Newshape(self, &newdims, PyArray_FALSE);", + " in the old array --- uses C-contiguous perspective.", + "_old_newshape(PyArrayObject *self, PyArray_Dims *newdims)", + "/* Used to reshape a Fortran Array */", + "static void", + "_reverse_shape(PyArray_Dims *newshape)", + "{", + "\tint i, n = newshape->len;", + "\tintp *ptr = newshape->ptr;", + "\tintp *eptr;", + "\tintp tmp;", + "\tint len = n >> 1;", + "", + "\teptr = ptr+n-1;", + "\tfor(i=0; ilen == 0) || (PyArray_ISCONTIGUOUS(self) && \\", + "\t\t\t\t (fortran != PyArray_TRUE))) {", + "\t\tret = _old_newshape(self, newshape);", + "\t}", + "\telse if ((fortran == PyArray_TRUE) && PyArray_ISFORTRAN(self)) {", + "\t\ttmp = PyArray_Transpose(self, NULL);", + "\t\tif (tmp == NULL) return NULL;", + "\t\t_reverse_shape(newshape);", + "\t\tret = _old_newshape((PyArrayObject *)tmp, newshape);", + "\t\tPy_DECREF(tmp);", + "\t\tif (ret == NULL) return NULL;", + "\t\ttmp = PyArray_Transpose((PyArrayObject *)ret, NULL);", + "\t\tPy_DECREF(ret);", + "\t\tif (tmp == NULL) return NULL;", + "\t\tret = tmp;", + "\t}", + "\telse {", + "\t\ttmp = PyArray_Copy(self);", + "\t\tif (tmp==NULL) return NULL;", + "\t\tret = _old_newshape((PyArrayObject *)tmp, newshape);", + "\t\tPy_DECREF(tmp);", + "\t}", + "", + "\treturn ret;", + "}", + "", + "\tif (PyObject_IsTrue(object))", + "\t\t*val=TRUE;", + "\telse *val=FALSE;", + "\tif (PyErr_Occurred())", + "\t\treturn PY_FAIL;", + "\treturn PY_SUCCEED;", + "/*MULTIARRAY_API", + " Convert an object to true / false", + "*/", + "static int", + "PyArray_ConditionConverter(PyObject *object, PyArray_CONDITION *val)", + "{", + "", + "\tif (object == Py_None)", + "\t\t*val = PyArray_DONTCARE;", + "\telse if (PyObject_IsTrue(object))", + "\t\t*val=PyArray_TRUE;", + "\telse *val=PyArray_FALSE;", + "\tif (PyErr_Occurred())", + "\t\treturn PY_FAIL;", + "\treturn PY_SUCCEED;", + "}", + "", + "", + "\tPyArray_CONDITION fortran=PyArray_DONTCARE;", + "\t\t\t\t\tPyArray_ConditionConverter, &fortran,", + "\t\t\tif (!copy && (fortran == PyArray_DONTCARE\t\\", + "\t\t\t\t || fortran==PyArray_ISFORTRAN(op))) {", + "\t\t\tif (!copy && (fortran == PyArray_DONTCARE || \\", + "\t\t\t\t fortran==PyArray_ISFORTRAN(op))) {", + "\tif (fortran!=PyArray_FALSE && \\", + "\t ((fortran == PyArray_TRUE) ||", + "\t (PyArray_Check(op) && PyArray_ISFORTRAN(op)))) {", + "\tif (!subok) {", + "/*", + "Included at the very first so not auto-grabbed and thus not", + "labeled." + ], + "deleted": [ + "PyArray_Ravel(PyArrayObject *a, int fortran)", + "\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);", + "", + "\t\treturn PyArray_Newshape(a, &newdim);", + "PyArray_Flatten(PyArrayObject *a, int fortran)", + "\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);", + " ret = PyArray_Newshape(self, &newdims);", + " in the old array", + "/*MULTIARRAY_API", + " New shape for an array", + "*/", + "PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims)", + " if (PyObject_IsTrue(object))", + " *val=TRUE;", + " else *val=FALSE;", + " if (PyErr_Occurred())", + " return PY_FAIL;", + " return PY_SUCCEED;", + "\tBool fortran=FALSE;", + "\t\t\t\t\tPyArray_BoolConverter, &fortran,", + "\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {", + "\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {", + "\tif (fortran) {", + " if (!subok) {", + "/*MULTIARRAY_API", + " GetNDArrayCVersion" + ] + } + }, + { + "old_path": "numpy/core/src/scalartypes.inc.src", + "new_path": "numpy/core/src/scalartypes.inc.src", + "filename": "scalartypes.inc.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -952,7 +952,7 @@ gentype_wraparray(PyObject *scalar, PyObject *args)\n \n /**begin repeat\n \n-#name=tolist, item, tostring, astype, copy, __deepcopy__, choose, searchsorted, reshape, view, swapaxes, conj, conjugate, nonzero, flatten, ravel, fill, transpose, newbyteorder#\n+#name=tolist, item, tostring, astype, copy, __deepcopy__, choose, searchsorted, view, swapaxes, conj, conjugate, nonzero, flatten, ravel, fill, transpose, newbyteorder#\n */\n \n static PyObject *\n@@ -1011,7 +1011,7 @@ gentype_byteswap(PyObject *self, PyObject *args)\n \n /**begin repeat\n \n-#name=take, getfield, put, putmask, repeat, tofile, mean, trace, diagonal, clip, std, var, sum, cumsum, prod, cumprod, compress, sort, argsort, round, argmax, argmin, max, min, ptp, any, all, resize#\n+#name=take, getfield, put, putmask, repeat, tofile, mean, trace, diagonal, clip, std, var, sum, cumsum, prod, cumprod, compress, sort, argsort, round, argmax, argmin, max, min, ptp, any, all, resize, reshape#\n */\n \n static PyObject *\n@@ -1186,7 +1186,8 @@ static PyMethodDef gentype_methods[] = {\n \t{\"setfield\", (PyCFunction)gentype_setfield, \n \t METH_VARARGS | METH_KEYWORDS, NULL},\n {\"copy\", (PyCFunction)gentype_copy, 1, NULL}, \n- {\"resize\", (PyCFunction)gentype_resize, 1, NULL}, \n+ {\"resize\", (PyCFunction)gentype_resize, \n+\t METH_VARARGS|METH_KEYWORDS, NULL}, \n \n \t{\"__array__\", (PyCFunction)gentype_getarray, 1, doc_getarray},\n \t{\"__array_wrap__\", (PyCFunction)gentype_wraparray, 1, doc_sc_wraparray},\n@@ -1229,7 +1230,7 @@ static PyMethodDef gentype_methods[] = {\n \t{\"argmin\", (PyCFunction)gentype_argmin,\n \t METH_VARARGS|METH_KEYWORDS, NULL},\n \t{\"reshape\",\t(PyCFunction)gentype_reshape, \n-\t METH_VARARGS, NULL},\n+\t METH_VARARGS|METH_KEYWORDS, NULL},\n \t{\"squeeze\",\t(PyCFunction)gentype_squeeze, \n \t METH_VARARGS, NULL},\n \t{\"view\", (PyCFunction)gentype_view, \n", + "added_lines": 5, + "deleted_lines": 4, + "source_code": "/* -*- c -*- */\n\n#ifndef _MULTIARRAYMODULE\n#define _MULTIARRAYMODULE\n#endif\n#include \"numpy/arrayscalars.h\"\nstatic int PyArrayScalar_Offset[PyArray_NTYPES+1];\n\n#define _SOFFSET_(obj, type_num) ((char *)(obj) + PyArrayScalar_Offset[(type_num)])\n\nstatic PyBoolScalarObject _PyArrayScalar_BoolValues[2] = {\n\t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 0},\n\t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 1},\n};\n\n/* Inheritance established later when tp_bases is set (or tp_base for \n single inheritance) */\n\n/**begin repeat\n\n#name=number, integer, signedinteger, unsignedinteger, inexact, floating, complexfloating, flexible, \ncharacter#\n#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating, ComplexFloating, Flexible, Character#\n*/\n\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@scalar\",\t\t /*tp_name*/\n sizeof(PyObject),\t\t /*tp_basicsize*/\n};\n/**end repeat**/\n\n\n/* no error checking is performed -- ctypeptr must be same type as scalar */\n/* in case of flexible type, the data is not copied \n into ctypeptr which is expected to be a pointer to pointer */\n/*OBJECT_API\n Convert to c-type\n*/\nstatic void\nPyArray_ScalarAsCtype(PyObject *scalar, void *ctypeptr)\n{\n\tPyArray_Descr *typecode;\n\ttypecode = PyArray_DescrFromScalar(scalar);\n\t\n\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\tvoid **newptr = (void **)ctypeptr;\n\t\tswitch(typecode->type_num) {\n\t\tcase PyArray_STRING:\n\t\t\t*newptr = (void *)PyString_AS_STRING(scalar);\n break;\n\t\tcase PyArray_UNICODE:\n\t\t\t*newptr = (void *)PyUnicode_AS_DATA(scalar);\n break;\n\t\tdefault:\n\t\t\t*newptr = ((PyVoidScalarObject *)scalar)->obval;\n break;\n\t\t}\n\t\treturn;\n\t}\n\tmemcpy(ctypeptr, _SOFFSET_(scalar, typecode->type_num),\n\t typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn;\n}\n\n/* The output buffer must be large-enough to receive the value */\n/* Even for flexible types which is different from ScalarAsCtype\n where only a reference for flexible types is returned \n*/\n\n/*OBJECT_API\n Cast Scalar to c-type\n*/\nstatic int\nPyArray_CastScalarToCtype(PyObject *scalar, void *ctypeptr, \n\t\t\t PyArray_Descr *outcode)\n{\n\tPyArray_Descr* descr;\n\t\n\tdescr = PyArray_DescrFromScalar(scalar);\n\tif (PyTypeNum_ISEXTENDED(descr->type_num) ||\n\t PyTypeNum_ISEXTENDED(outcode->type_num)) {\n\t\tPyArrayObject *ain, *aout;\n\n\t\tain = (PyArrayObject *)PyArray_FromScalar(scalar, NULL);\n\t\tif (ain == NULL) {Py_DECREF(descr); return -1;}\n\t\taout = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t outcode,\n\t\t\t\t\t 0, NULL, \n\t\t\t\t\t NULL, ctypeptr, \n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\t\tif (aout == NULL) {Py_DECREF(ain); return -1;}\n\t\tdescr->f->cast[outcode->type_num](ain->data, \n\t\t\t\t\t aout->data, 1, ain, aout);\n\t\tPy_DECREF(ain);\n\t\tPy_DECREF(aout);\n\t}\n\telse {\n\t\tdescr->f->cast[outcode->type_num](_SOFFSET_(scalar, \n\t\t\t\t\t\t\t descr->type_num), \n\t\t\t\t\t ctypeptr, 1, NULL, NULL);\n\t}\n\tPy_DECREF(descr);\n\treturn 0;\n}\n\n/* 0-dim array from array-scalar object */\n/* always contains a copy of the data \n unless outcode is NULL, it is of void type and the referrer does\n not own it either.\n*/\n\n/* steals reference to outcode */\n/*OBJECT_API\n Get 0-dim array from scalar\n*/\nstatic PyObject *\nPyArray_FromScalar(PyObject *scalar, PyArray_Descr *outcode)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *r;\n\tchar *memptr;\n\tPyObject *ret;\n\n\t/* convert to 0-dim array of scalar typecode */\n\ttypecode = PyArray_DescrFromScalar(scalar);\n\tif ((typecode->type_num == PyArray_VOID) &&\t\t\t\\\n\t !(((PyVoidScalarObject *)scalar)->flags & OWNDATA) &&\t\\\n\t outcode == NULL) {\n\t\tr = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t typecode,\n\t\t\t\t\t 0, NULL, NULL,\n\t\t\t\t\t ((PyVoidScalarObject *)scalar)->obval,\n\t\t\t\t\t ((PyVoidScalarObject *)scalar)->flags,\n\t\t\t\t\t NULL);\n\t\tPyArray_BASE(r) = (PyObject *)scalar;\n\t\tPy_INCREF(scalar);\n\t\treturn r;\n\t}\n\tr = PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t typecode,\n\t\t\t\t 0, NULL, \n\t\t\t\t NULL, NULL, 0, NULL);\n\tif (r==NULL) {Py_XDECREF(outcode); return NULL;}\n\n\tswitch(typecode->type_num) {\n\tcase PyArray_STRING:\n\t\tmemptr = PyString_AS_STRING(scalar);\n\t\tbreak;\n\tcase PyArray_UNICODE:\n\t\tmemptr = (char *)PyUnicode_AS_DATA(scalar);\n#ifdef Py_UNICODE_WIDE\n\t\tbreak;\n#else\n\t\tPyUCS2Buffer_AsUCS4((Py_UNICODE *)memptr, \n\t\t\t\t (PyArray_UCS4 *)PyArray_DATA(r),\n\t\t\t\t PyUnicode_GET_SIZE(scalar),\n\t\t\t\t PyArray_ITEMSIZE(r) >> 2);\n goto finish;\n#endif\n\tdefault:\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tmemptr = (((PyVoidScalarObject *)scalar)->obval);\n\t\t}\n\t\telse {\n\t\t\tmemptr = _SOFFSET_(scalar, typecode->type_num);\n\t\t}\n\t\tbreak;\n\t}\n\n\tmemcpy(PyArray_DATA(r), memptr, PyArray_ITEMSIZE(r));\n\tif (PyArray_ISOBJECT(r)) {\n\t\tPy_INCREF(*((PyObject **)memptr));\n\t}\n#ifndef Py_UNICODE_WIDE\n finish:\t\n#endif\n\tif (outcode == NULL) return r;\n\t\n\tif (outcode->type_num == typecode->type_num) {\n\t\tif (!PyTypeNum_ISEXTENDED(typecode->type_num))\n\t\t\treturn r;\n\t\tif (outcode->elsize == typecode->elsize);\n\t\treturn r;\t\t\t\n\t}\n\t\n\t/* cast if necessary to desired output typecode */\n\tret = PyArray_CastToType((PyArrayObject *)r, outcode, 0);\n\tPy_DECREF(r);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n const size_t size = _PyObject_VAR_SIZE(type, nitems+1);\n\n obj = (PyObject *)_pya_malloc(size);\n\tmemset(obj, 0, size);\n\tif (type->tp_itemsize == 0)\n PyObject_INIT(obj, type);\n else\n (void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems);\n return obj;\n}\n\nstatic void\ngentype_dealloc(PyObject *v) \n{\n\tv->ob_type->tp_free(v);\n}\n\n\nstatic PyObject *\ngentype_power(PyObject *m1, PyObject *m2, PyObject *m3)\n{\n\tPyObject *arr, *ret, *arg2;\n\tchar *msg=\"unsupported operand type(s) for ** or pow()\";\n\t\n\tif (!PyArray_IsScalar(m1,Generic)) {\n\t\tif (PyArray_Check(m1)) {\n\t\t\tret = m1->ob_type->tp_as_number->nb_power(m1,m2, \n\t\t\t\t\t\t\t\t Py_None);\n\t\t}\n\t\telse {\n\t\t\tif (!PyArray_IsScalar(m2,Generic)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tarr = PyArray_FromScalar(m2, NULL);\n\t\t\tif (arr == NULL) return NULL;\n\t\t\tret = arr->ob_type->tp_as_number->nb_power(m1, arr,\n\t\t\t\t\t\t\t\t Py_None);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t\treturn ret;\n\t}\n\tif (!PyArray_IsScalar(m2, Generic)) {\n\t\tif (PyArray_Check(m2)) {\n\t\t\tret = m2->ob_type->tp_as_number->nb_power(m1,m2, \n\t\t\t\t\t\t\t\t Py_None);\n\t\t}\n\t\telse {\n\t\t\tif (!PyArray_IsScalar(m1, Generic)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tarr = PyArray_FromScalar(m1, NULL);\n\t\t\tif (arr == NULL) return NULL;\n\t\t\tret = arr->ob_type->tp_as_number->nb_power(arr, m2,\n\t\t\t\t\t\t\t\t Py_None);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t\treturn ret;\n\t}\n\tarr=arg2=NULL;\n\tarr = PyArray_FromScalar(m1, NULL);\n\targ2 = PyArray_FromScalar(m2, NULL);\t\n\tif (arr == NULL || arg2 == NULL) {\n\t\tPy_XDECREF(arr); Py_XDECREF(arg2); return NULL;\n\t}\n\tret = arr->ob_type->tp_as_number->nb_power(arr, arg2, Py_None);\n\tPy_DECREF(arr);\n\tPy_DECREF(arg2);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_generic_method(PyObject *self, PyObject *args, PyObject *kwds, \n\t\t char *str)\n{\n\tPyObject *arr, *meth, *ret;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tmeth = PyObject_GetAttrString(arr, str);\n\tif (meth == NULL) {Py_DECREF(arr); return NULL;}\n\tif (kwds == NULL) \n\t\tret = PyObject_CallObject(meth, args);\n\telse\n\t\tret = PyObject_Call(meth, args, kwds);\n\tPy_DECREF(meth);\n\tPy_DECREF(arr);\n if (ret && PyArray_Check(ret))\n return PyArray_Return((PyArrayObject *)ret);\n else\n return ret;\n}\n\n/**begin repeat\n\n#name=add, subtract, divide, remainder, divmod, lshift, rshift, and, xor, or, floor_divide, true_divide#\n#PYNAME=Add, Subtract, Divide, Remainder, Divmod, Lshift, Rshift, And, Xor, Or, FloorDivide, TrueDivide#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *m1, PyObject *m2)\n{\n\treturn PyArray_Type.tp_as_number->nb_@name@(m1, m2);\n}\n/**end repeat**/\n\n\nstatic PyObject *\ngentype_multiply(PyObject *m1, PyObject *m2)\n{\n\tPyObject *ret=NULL;\n\tlong repeat;\n\n\tif (!PyArray_IsScalar(m1, Generic) && \n\t ((m1->ob_type->tp_as_number == NULL) ||\n\t (m1->ob_type->tp_as_number->nb_multiply == NULL))) {\n\t\t/* Try to convert m2 to an int and try sequence\n\t\t repeat */\n\t\trepeat = PyInt_AsLong(m2);\n\t\tif (repeat == -1 && PyErr_Occurred()) return NULL;\n\t\tret = PySequence_Repeat(m1, (int) repeat);\n\t}\n\telse if (!PyArray_IsScalar(m2, Generic) && \n\t\t ((m2->ob_type->tp_as_number == NULL) ||\n\t\t (m2->ob_type->tp_as_number->nb_multiply == NULL))) {\n\t\t/* Try to convert m1 to an int and try sequence\n\t\t repeat */\n\t\trepeat = PyInt_AsLong(m1);\n\t\tif (repeat == -1 && PyErr_Occurred()) return NULL;\n\t\tret = PySequence_Repeat(m2, (int) repeat);\n\t}\n\tif (ret==NULL) {\n\t\tPyErr_Clear(); /* no effect if not set */\n\t\tret = PyArray_Type.tp_as_number->nb_multiply(m1, m2);\n\t}\n\treturn ret;\n}\n\n/**begin repeat\n\n#name=positive, negative, absolute, invert, int, long, float, oct, hex#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *m1)\n{\n\tPyObject *arr, *ret;\n\n\tarr = PyArray_FromScalar(m1, NULL);\n\tif (arr == NULL) return NULL;\n\tret = arr->ob_type->tp_as_number->nb_@name@(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n/**end repeat**/\n\nstatic int\ngentype_nonzero_number(PyObject *m1)\n{\n\tPyObject *arr;\n\tint ret;\n\n\tarr = PyArray_FromScalar(m1, NULL);\n\tif (arr == NULL) return -1;\n\tret = arr->ob_type->tp_as_number->nb_nonzero(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_str(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret, *tmp;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tif (arr==NULL) return NULL;\n\tret = PyObject_Str((tmp=arr->descr->f->getitem(arr->data, arr)));\n\tPy_DECREF(arr);\n\tPy_XDECREF(tmp);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_repr(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret, *tmp ;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tif (arr==NULL) return NULL;\n\tret = PyObject_Repr((tmp=arr->descr->f->getitem(arr->data, arr)));\n\tPy_DECREF(arr);\n\tPy_XDECREF(tmp);\n\treturn ret;\n}\n\nstatic void\nformat_longdouble(char *buf, size_t buflen, longdouble val, int precision)\n{\n register char *cp;\n\n PyOS_snprintf(buf, buflen, \"%.*\" LONGDOUBLE_FMT, precision, val);\n cp = buf;\n if (*cp == '-')\n cp++;\n for (; *cp != '\\0'; cp++) {\n if (!isdigit(Py_CHARMASK(*cp)))\n break;\n }\n if (*cp == '\\0') {\n *cp++ = '.';\n *cp++ = '0';\n *cp++ = '\\0';\n }\n}\n\n/* over-ride repr and str of array-scalar strings and unicode to \n remove NULL bytes and then call the corresponding functions \n of string and unicode. \n */\n\n/**begin repeat\n#name=string*2,unicode*2#\n#form=(repr,str)*2#\n#Name=String*2,Unicode*2#\n#NAME=STRING*2,UNICODE*2#\n#extra=AndSize*2,,#\n#type=char*2, Py_UNICODE*2#\n*/\nstatic PyObject *\n@name@type_@form@(PyObject *self)\n{\n\tconst @type@ *dptr, *ip;\n\tint len;\n\tPyObject *new;\n\tPyObject *ret;\n\n\tip = dptr = Py@Name@_AS_@NAME@(self);\n\tlen = Py@Name@_GET_SIZE(self);\n\tdptr += len-1;\n\twhile(len > 0 && *dptr-- == 0) len--;\n\tnew = Py@Name@_From@Name@@extra@(ip, len);\n\tif (new == NULL) return PyString_FromString(\"\");\n\tret = Py@Name@_Type.tp_@form@(new);\n\tPy_DECREF(new);\n\treturn ret;\n}\n/**end repeat**/\n\n\n\n#if SIZEOF_LONGDOUBLE == SIZEOF_DOUBLE\n#define PREC_REPR 17\n#define PREC_STR 17\n#else\n#define PREC_REPR 21\n#define PREC_STR 21\n#endif\n\nstatic PyObject *\nlongdoubletype_repr(PyObject *self)\n{\n static char buf[100];\n format_longdouble(buf, sizeof(buf), ((PyLongDoubleScalarObject *)self)->obval, PREC_REPR);\n return PyString_FromString(buf);\n}\n\nstatic PyObject *\nclongdoubletype_repr(PyObject *self)\n{\n static char buf1[100];\n static char buf2[100];\n\tstatic char buf3[202];\n clongdouble x;\n x = ((PyCLongDoubleScalarObject *)self)->obval;\n format_longdouble(buf1, sizeof(buf1), x.real, PREC_REPR);\n format_longdouble(buf2, sizeof(buf2), x.imag, PREC_REPR);\n\n\tsnprintf(buf3, sizeof(buf3), \"(%s+%sj)\", buf1, buf2);\n\treturn PyString_FromString(buf3);\n}\n\n#define longdoubletype_str longdoubletype_repr\n#define clongdoubletype_str clongdoubletype_repr\n\n/** Could improve this with a PyLong_FromLongDouble(longdouble ldval)\n but this would need some more work...\n**/\n\n/**begin repeat\n\n#name=(int, long, hex, oct, float)*2#\n#KIND=(Long*4, Float)*2#\n#char=,,,,,c*5#\n#CHAR=,,,,,C*5#\n#POST=,,,,,.real*5#\n*/\nstatic PyObject *\n@char@longdoubletype_@name@(PyObject *self)\n{\n\tdouble dval;\n\tPyObject *obj, *ret;\n\t\n\tdval = (double)(((Py@CHAR@LongDoubleScalarObject *)self)->obval)@POST@;\n\tobj = Py@KIND@_FromDouble(dval);\n\tret = obj->ob_type->tp_as_number->nb_@name@(obj);\n\tPy_DECREF(obj);\n\treturn ret;\n}\n/**end repeat**/\n\n#if PY_VERSION_HEX >= 0x02050000\n/* This needs a better implementation */\nstatic Py_ssize_t\ngentype_index(PyObject *self)\n{\n\tPyObject *obj;\n\tif (!(PyArray_IsScalar(self, Integer))) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"not an integer type.\");\n\t\treturn -1;\n\t}\n\tobj = gentype_int(self);\n\tif (obj == NULL) return -1;\n\treturn PyInt_AsSsize_t(obj);\t\n}\n#endif\n\n\nstatic PyNumberMethods gentype_as_number = {\n (binaryfunc)gentype_add,\t\t /*nb_add*/\n (binaryfunc)gentype_subtract,\t\t /*nb_subtract*/\n (binaryfunc)gentype_multiply,\t\t /*nb_multiply*/\n (binaryfunc)gentype_divide,\t\t /*nb_divide*/\n (binaryfunc)gentype_remainder,\t /*nb_remainder*/\n (binaryfunc)gentype_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)gentype_power,\t\t /*nb_power*/\n (unaryfunc)gentype_negative,\t \n (unaryfunc)gentype_positive, \t /*nb_pos*/ \n (unaryfunc)gentype_absolute,\t\t /*(unaryfunc)gentype_abs,*/\n (inquiry)gentype_nonzero_number,\t\t /*nb_nonzero*/\n (unaryfunc)gentype_invert,\t\t /*nb_invert*/\n (binaryfunc)gentype_lshift,\t /*nb_lshift*/\n (binaryfunc)gentype_rshift,\t /*nb_rshift*/\n (binaryfunc)gentype_and,\t /*nb_and*/\n (binaryfunc)gentype_xor,\t /*nb_xor*/\n (binaryfunc)gentype_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)gentype_int,\t\t /*nb_int*/\n (unaryfunc)gentype_long,\t\t /*nb_long*/\n (unaryfunc)gentype_float,\t\t /*nb_float*/\n (unaryfunc)gentype_oct,\t\t /*nb_oct*/\n (unaryfunc)gentype_hex,\t\t /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)gentype_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)gentype_true_divide,\t /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n\t(lenfunc)gentype_index, /* nb_index */\n#endif\n};\n\n\nstatic PyObject *\ngentype_richcompare(PyObject *self, PyObject *other, int cmp_op) \n{\n\n\tPyObject *arr, *ret;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tret = arr->ob_type->tp_richcompare(arr, other, cmp_op);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_ndim_get(PyObject *self)\n{\n\treturn PyInt_FromLong(0);\n}\n\nstatic PyObject *\ngentype_flags_get(PyObject *self)\n{\n return PyArray_NewFlagsObject(NULL);\n}\n\nstatic PyObject *\nvoidtype_flags_get(PyVoidScalarObject *self)\n{\n\treturn PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 1);\n}\n\nstatic PyObject *\nvoidtype_dtypedescr_get(PyVoidScalarObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n\nstatic PyObject *\ngentype_shape_get(PyObject *self)\n{\n\treturn PyTuple_New(0);\n}\n\n/*\nstatic int\ngentype_shape_set(PyObject *self, PyObject *val)\n{\n\tif (!PyTuple_Check(val) || PyTuple_GET_SIZE(val) > 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \\\n\t\t\t\t\"invalid shape for scalar\");\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n*/\n\nstatic PyObject *\ngentype_dataptr_get(PyObject *self)\n{\n\treturn Py_BuildValue(\"NO\",PyString_FromString(\"\"),Py_True);\n}\n\n\nstatic PyObject *\ngentype_data_get(PyObject *self)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\n\ttypecode = PyArray_DescrFromScalar(self);\n\tret = PyBuffer_FromObject(self, 0, typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\n\nstatic PyObject *\ngentype_itemsize_get(PyObject *self)\n{\t\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\n\ttypecode = PyArray_DescrFromScalar(self);\n\tret = PyInt_FromLong((long) typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_size_get(PyObject *self)\n{\n\treturn PyInt_FromLong(1);\n}\n\nstatic void\ngentype_struct_free(void *ptr, void *arr)\n{\n Py_DECREF((PyObject *)arr);\n _pya_free(ptr);\n}\n\nstatic PyObject *\ngentype_struct_get(PyObject *self)\n{\n PyArrayObject *arr;\n PyArrayInterface *inter;\n \n arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = 0;\n inter->flags = arr->flags;\n inter->typekind = arr->descr->kind;\n inter->itemsize = arr->descr->elsize;\n inter->strides = NULL;\n inter->shape = NULL;\n inter->data = arr->data;\n return PyCObject_FromVoidPtrAndDesc(inter, arr, gentype_struct_free);\n}\n\nstatic PyObject *\ngentype_typestr_get(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tret = PyObject_GetAttrString((PyObject *)arr->descr, \"str\");\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_descr_get(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tret = PyObject_GetAttrString((PyObject *)arr, \"__array_descr__\");\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\n\nstatic PyObject *\ngentype_typedescr_get(PyObject *self)\n{\n\treturn (PyObject *)PyArray_DescrFromScalar(self);\n}\n\n\nstatic PyObject *\ngentype_base_get(PyObject *self)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic PyArray_Descr *\n_realdescr_fromcomplexscalar(PyObject *self, int *typenum)\n{\n\tif PyArray_IsScalar(self, CDouble) {\n\t\t*typenum = PyArray_CDOUBLE;\n\t\treturn PyArray_DescrFromType(PyArray_DOUBLE);\n\t}\n\tif PyArray_IsScalar(self, CFloat) {\n\t\t*typenum = PyArray_CFLOAT;\n\t\treturn PyArray_DescrFromType(PyArray_FLOAT);\n\t}\n\tif PyArray_IsScalar(self, CLongDouble) {\n\t\t*typenum = PyArray_CLONGDOUBLE;\n\t\treturn PyArray_DescrFromType(PyArray_LONGDOUBLE);\n\t}\n\treturn NULL;\n}\n\nstatic PyObject *\ngentype_real_get(PyObject *self)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\tint typenum;\n\n\tif (PyArray_IsScalar(self, ComplexFloating)) {\n\t\ttypecode = _realdescr_fromcomplexscalar(self, &typenum);\n\t\tret = PyArray_Scalar(_SOFFSET_(self, typenum), typecode,\n\t\t\t\t NULL);\n\t\tPy_DECREF(typecode);\n\t\treturn ret;\n\t}\n\telse if PyArray_IsScalar(self, Object) {\n\t\tPyObject *obj = ((PyObjectScalarObject *)self)->obval;\n\t\tret = PyObject_GetAttrString(obj, \"real\");\n\t\tif (ret != NULL) return ret;\n\t\tPyErr_Clear();\n\t}\n\tPy_INCREF(self);\n\treturn (PyObject *)self;\n}\n\nstatic PyObject *\ngentype_imag_get(PyObject *self)\n{\t\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\t\n\tint typenum;\n\t\n\ttypecode = _realdescr_fromcomplexscalar(self, &typenum);\n\tif (PyArray_IsScalar(self, ComplexFloating)) {\n\t\tret = PyArray_Scalar(_SOFFSET_(self, typenum)\t\t\\\n\t\t\t\t + typecode->elsize, typecode, NULL);\n\t}\n\telse if PyArray_IsScalar(self, Object) {\n\t\tPyObject *obj = ((PyObjectScalarObject *)self)->obval;\n\t\tPyArray_Descr *newtype;\n\t\tret = PyObject_GetAttrString(obj, \"imag\");\n\t\tif (ret == NULL) {\n\t\t\tPyErr_Clear();\n\t\t\tobj = PyInt_FromLong(0);\n\t\t\tnewtype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\t\tret = PyArray_Scalar((char *)&obj, newtype, NULL);\n\t\t\tPy_DECREF(newtype);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tchar *temp;\n\t\ttemp = PyDataMem_NEW(typecode->elsize);\n\t\tmemset(temp, '\\0', typecode->elsize);\n\t\tret = PyArray_Scalar(temp, typecode, NULL);\n\t\tPyDataMem_FREE(temp);\n\t}\n\t\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_flat_get(PyObject *self)\n{\n\tPyObject *ret, *arr;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tret = PyArray_IterNew(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyGetSetDef gentype_getsets[] = {\n {\"ndim\", \n\t (getter)gentype_ndim_get, \n\t (setter) 0, \n\t \"number of array dimensions\"},\n {\"flags\", \n\t (getter)gentype_flags_get, \n\t (setter)0, \n\t \"integer value of flags\"},\n {\"shape\", \n\t (getter)gentype_shape_get, \n\t (setter)0, \n\t \"tuple of array dimensions\"},\n {\"strides\", \n\t (getter)gentype_shape_get, \n\t (setter) 0, \n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)gentype_data_get, \n\t (setter) 0, \n\t \"pointer to start of data\"},\n {\"itemsize\", \n\t (getter)gentype_itemsize_get, \n\t (setter)0, \n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)gentype_size_get,\n (setter)0,\n \"number of elements in the gentype\"},\n {\"nbytes\",\n (getter)gentype_itemsize_get,\n (setter)0,\n \"length of item in bytes\"},\n\t{\"base\",\n\t (getter)gentype_base_get,\n\t (setter)0,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)gentype_typedescr_get,\n\t NULL,\n\t \"get array data-descriptor\"},\n {\"real\", \n\t (getter)gentype_real_get, \n\t (setter)0,\n\t \"real part of scalar\"},\n {\"imag\", \n\t (getter)gentype_imag_get, \n\t (setter)0, \n\t \"imaginary part of scalar\"},\n\t{\"flat\", \n\t (getter)gentype_flat_get, \n\t (setter)0, \n\t \"a 1-d view of scalar\"}, \n\t{\"__array_data__\", \n\t (getter)gentype_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)gentype_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)gentype_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)gentype_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)gentype_shape_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)gentype_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t/* Does not have __array_priority__ because it is not a subtype.\n\t */\n \t{NULL, NULL, NULL, NULL} /* Sentinel */\n};\n\n\n/* 0-dim array from scalar object */\n\nstatic char doc_getarray[] = \"sc.__array__(|type) return 0-dim array\";\n\nstatic PyObject *\ngentype_getarray(PyObject *scalar, PyObject *args) \n{\n\tPyArray_Descr *outcode=NULL;\n\tPyObject *ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", &PyArray_DescrConverter,\n\t\t\t &outcode)) return NULL;\n\tret = PyArray_FromScalar(scalar, outcode);\n\treturn ret;\n}\n\nstatic char doc_sc_wraparray[] = \"sc.__array_wrap__(obj) return scalar from array\";\n\nstatic PyObject *\ngentype_wraparray(PyObject *scalar, PyObject *args)\n{\n\tPyObject *arr;\n\n\tif (PyTuple_Size(args) < 1) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"only accepts 1 argument.\");\n\t\treturn NULL;\n\t}\n\tarr = PyTuple_GET_ITEM(args, 0);\n\tif (!PyArray_Check(arr)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"can only be called with ndarray object\");\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_Scalar(PyArray_DATA(arr), PyArray_DESCR(arr), arr);\n}\n\n\n/**begin repeat\n\n#name=tolist, item, tostring, astype, copy, __deepcopy__, choose, searchsorted, view, swapaxes, conj, conjugate, nonzero, flatten, ravel, fill, transpose, newbyteorder#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *self, PyObject *args)\n{\n\treturn gentype_generic_method(self, args, NULL, \"@name@\");\n}\n/**end repeat**/\n\nstatic PyObject *\ngentype_squeeze(PyObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\tPy_INCREF(self);\n\treturn self;\n}\n\nstatic int\ngentype_getreadbuf(PyObject *, int, void **);\n\nstatic PyObject *\ngentype_byteswap(PyObject *self, PyObject *args)\n{\n\tBool inplace=FALSE;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter, &inplace))\n\t\treturn NULL;\n\t\n\tif (inplace) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot byteswap a scalar in-place\");\n\t\treturn NULL;\n\t}\n\telse {\n\t\t/* get the data, copyswap it and pass it to a new Array scalar\n\t\t */\n\t\tchar *data;\n\t\tint numbytes;\n\t\tPyArray_Descr *descr;\n\t\tPyObject *new;\n\t\tchar *newmem;\n\n\t\tnumbytes = gentype_getreadbuf(self, 0, (void **)&data);\n\t\tdescr = PyArray_DescrFromScalar(self);\n\t\tnewmem = _pya_malloc(descr->elsize);\n\t\tif (newmem == NULL) {Py_DECREF(descr); return PyErr_NoMemory();}\n\t\telse memcpy(newmem, data, descr->elsize);\n\t\tdescr->f->copyswap(newmem, NULL, 1, descr->elsize);\n\t\tnew = PyArray_Scalar(newmem, descr, NULL);\n\t\t_pya_free(newmem);\n\t\tPy_DECREF(descr);\n\t\treturn new;\n\t}\n}\n\n\n/**begin repeat\n\n#name=take, getfield, put, putmask, repeat, tofile, mean, trace, diagonal, clip, std, var, sum, cumsum, prod, cumprod, compress, sort, argsort, round, argmax, argmin, max, min, ptp, any, all, resize, reshape#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\treturn gentype_generic_method(self, args, kwds, \"@name@\");\n}\n/**end repeat**/\n\nstatic PyObject *\nvoidtype_getfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyObject *ret;\n\n\tret = gentype_generic_method((PyObject *)self, args, kwds, \"getfield\");\n\tif (!ret) return ret;\n\tif (PyArray_IsScalar(ret, Generic) &&\t\\\n\t (!PyArray_IsScalar(ret, Void))) {\n\t\tPyArray_Descr *new;\n\t\tif (!PyArray_ISNBO(self->descr->byteorder)) {\n\t\t\tnew = PyArray_DescrFromScalar(ret);\n\t\t\tnew->f->copyswap(_SOFFSET_(ret, \n\t\t\t\t\t\t new->type_num),\n\t\t\t\t\t NULL, 1, new->elsize);\n\t\t\tPy_DECREF(new);\n\t\t}\n\t}\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_setfield(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\t\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"Can't set fields in a non-void array scalar.\");\n\treturn NULL;\n}\t\n\nstatic PyObject *\nvoidtype_setfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *typecode;\n\tint offset = 0;\n\tPyObject *value, *src;\n\tint mysize;\n\tchar *dptr;\n\tstatic char *kwlist[] = {\"value\", \"dtype\", \"offset\", 0};/* XXX ? */\n\t\n\tif ((self->flags & WRITEABLE) != WRITEABLE) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"Can't write to memory\");\n\t\treturn NULL;\n\t}\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO&|i\", kwlist,\n\t\t\t\t\t &value,\n\t\t\t\t\t PyArray_DescrConverter, \n\t\t\t\t\t &typecode, &offset)) return NULL;\n\n\tmysize = self->ob_size;\n\t\n\tif (offset < 0 || (offset + typecode->elsize) > mysize) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need 0 <= offset <= %d for requested type \" \\\n\t\t\t \"but received offset = %d\",\n\t\t\t mysize-typecode->elsize, offset);\n\t\tPy_DECREF(typecode);\n\t\treturn NULL;\n\t}\t\n\n\tdptr = self->obval + offset;\n\n\t/* Copy data from value to correct place in dptr */\n src = PyArray_FromAny(value, typecode, 0, 0, CARRAY_FLAGS, NULL);\n if (src == NULL) return NULL;\n\ttypecode->f->copyswap(dptr, PyArray_DATA(src), \n\t\t\t !PyArray_ISNBO(self->descr->byteorder),\n\t\t\t PyArray_ITEMSIZE(src));\n\tPy_DECREF(src);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic PyObject *\ngentype_reduce(PyObject *self, PyObject *args)\n{\n\tPyObject *ret=NULL, *obj=NULL, *mod=NULL;\n\tconst char *buffer; \n\tint buflen;\n\n\t/* Return a tuple of (callable object, arguments) */\n\n\tret = PyTuple_New(2);\n\tif (ret == NULL) return NULL;\t\n\tif (PyObject_AsReadBuffer(self, (const void **)&buffer, &buflen)<0) {\n\t\tPy_DECREF(ret); return NULL;\n\t}\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) return NULL;\n\tobj = PyObject_GetAttrString(mod, \"scalar\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) return NULL;\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tobj = PyObject_GetAttrString((PyObject *)self, \"dtype\");\n\tif PyArray_IsScalar(self, Object) {\n\t\tmod = ((PyObjectScalarObject *)self)->obval;\n\t\tPyTuple_SET_ITEM(ret, 1,\n\t\t\t\t Py_BuildValue(\"NO\", obj, mod));\n\t}\n\telse {\n\t\tmod = PyString_FromStringAndSize(buffer, buflen);\n\t\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t\t Py_BuildValue(\"NN\", obj, mod));\n\t}\n\treturn ret;\n}\n\n/* ignores everything */\nstatic PyObject *\ngentype_setstate(PyObject *self, PyObject *args)\n{\n\tPy_INCREF(Py_None);\n\treturn (Py_None);\n}\n\nstatic PyObject *\ngentype_dump(PyObject *self, PyObject *args)\n{\n\tPyObject *file=NULL;\n\tint ret;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &file))\n\t\treturn NULL;\n\tret = PyArray_Dump(self, file, 2);\n\tif (ret < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyObject *\ngentype_dumps(PyObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\"))\n\t\treturn NULL;\n\treturn PyArray_Dumps(self, 2);\n}\n\n\n/* setting flags cannot be done for scalars */\nstatic PyObject *\ngentype_setflags(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* need to fill in doc-strings for these methods on import -- copy from \n array docstrings \n*/\nstatic PyMethodDef gentype_methods[] = {\n {\"tolist\",\t (PyCFunction)gentype_tolist,\t1, NULL},\n {\"item\", (PyCFunction)gentype_item, METH_VARARGS, NULL},\n\t{\"tofile\", (PyCFunction)gentype_tofile, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"tostring\", (PyCFunction)gentype_tostring, METH_VARARGS, NULL},\n {\"byteswap\", (PyCFunction)gentype_byteswap,1, NULL},\n {\"astype\", (PyCFunction)gentype_astype, 1, NULL},\n\t{\"getfield\", (PyCFunction)gentype_getfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{\"setfield\", (PyCFunction)gentype_setfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n {\"copy\", (PyCFunction)gentype_copy, 1, NULL}, \n {\"resize\", (PyCFunction)gentype_resize, \n\t METH_VARARGS|METH_KEYWORDS, NULL}, \n\n\t{\"__array__\", (PyCFunction)gentype_getarray, 1, doc_getarray},\n\t{\"__array_wrap__\", (PyCFunction)gentype_wraparray, 1, doc_sc_wraparray},\n\n /* for the copy module */\n {\"__copy__\", (PyCFunction)gentype_copy, 1, NULL},\n {\"__deepcopy__\", (PyCFunction)gentype___deepcopy__, 1, NULL},\n\n\n {\"__reduce__\", (PyCFunction) gentype_reduce, 1, NULL},\t\n\t/* For consistency does nothing */\n\t{\"__setstate__\", (PyCFunction) gentype_setstate, 1, NULL},\n\n\t{\"dumps\", (PyCFunction) gentype_dumps, 1, NULL},\n\t{\"dump\", (PyCFunction) gentype_dump, 1, NULL},\n\n\t/* Methods for array */\n\t{\"fill\", (PyCFunction)gentype_fill,\n\t METH_VARARGS, NULL},\n\t{\"transpose\",\t(PyCFunction)gentype_transpose, \n\t METH_VARARGS, NULL},\n\t{\"take\",\t(PyCFunction)gentype_take, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"put\",\t(PyCFunction)gentype_put, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"putmask\",\t(PyCFunction)gentype_putmask, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"repeat\",\t(PyCFunction)gentype_repeat, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"choose\",\t(PyCFunction)gentype_choose, \n\t METH_VARARGS, NULL},\t\n\t{\"sort\",\t(PyCFunction)gentype_sort, \n\t METH_VARARGS, NULL},\n\t{\"argsort\",\t(PyCFunction)gentype_argsort, \n\t METH_VARARGS, NULL},\n\t{\"searchsorted\", (PyCFunction)gentype_searchsorted, \n\t METH_VARARGS, NULL},\t\n\t{\"argmax\",\t(PyCFunction)gentype_argmax, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"argmin\", (PyCFunction)gentype_argmin,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"reshape\",\t(PyCFunction)gentype_reshape, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"squeeze\",\t(PyCFunction)gentype_squeeze, \n\t METH_VARARGS, NULL},\n\t{\"view\", (PyCFunction)gentype_view, \n\t METH_VARARGS, NULL},\n\t{\"swapaxes\", (PyCFunction)gentype_swapaxes,\n\t METH_VARARGS, NULL},\n\t{\"max\", (PyCFunction)gentype_max,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"min\", (PyCFunction)gentype_min,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"ptp\", (PyCFunction)gentype_ptp,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"mean\", (PyCFunction)gentype_mean,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"trace\", (PyCFunction)gentype_trace,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"diagonal\", (PyCFunction)gentype_diagonal,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"clip\", (PyCFunction)gentype_clip,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"conj\", (PyCFunction)gentype_conj,\n\t METH_VARARGS, NULL},\n\t{\"conjugate\", (PyCFunction)gentype_conjugate,\n\t METH_VARARGS, NULL},\n\t{\"nonzero\", (PyCFunction)gentype_nonzero,\n\t METH_VARARGS, NULL},\n\t{\"std\", (PyCFunction)gentype_std,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"var\", (PyCFunction)gentype_var,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"sum\", (PyCFunction)gentype_sum,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"cumsum\", (PyCFunction)gentype_cumsum,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"prod\", (PyCFunction)gentype_prod,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"cumprod\", (PyCFunction)gentype_cumprod,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"all\", (PyCFunction)gentype_all,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"any\", (PyCFunction)gentype_any,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"compress\", (PyCFunction)gentype_compress,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"flatten\", (PyCFunction)gentype_flatten,\n\t METH_VARARGS, NULL},\n\t{\"ravel\", (PyCFunction)gentype_ravel,\n\t METH_VARARGS, NULL},\n\t{\"round\", (PyCFunction)gentype_round,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"setflags\", (PyCFunction)gentype_setflags,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"newbyteorder\", (PyCFunction)gentype_newbyteorder,\n\t METH_VARARGS, NULL},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\nstatic PyGetSetDef voidtype_getsets[] = {\n {\"flags\", \n\t (getter)voidtype_flags_get, \n\t (setter)0, \n\t \"integer value of flags\"},\n\t{\"dtype\",\n\t (getter)voidtype_dtypedescr_get,\n\t (setter)0,\n\t \"dtype object\"},\n\t{NULL, NULL}\n};\n\nstatic PyMethodDef voidtype_methods[] = {\n\t{\"getfield\", (PyCFunction)voidtype_getfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{\"setfield\", (PyCFunction)voidtype_setfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{NULL, NULL}\n};\n\n/************* As_mapping functions for void array scalar ************/\n\nstatic int\nvoidtype_length(PyVoidScalarObject *self) \n{\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\treturn 0;\n\t}\n\telse { /* return the number of fields */\n\t\tPyObject *key;\n\t\tPyObject *flist;\n\t\tkey = PyInt_FromLong(-1);\n\t\tflist = PyDict_GetItem(self->descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!flist) return 0;\n\t\treturn PyTuple_GET_SIZE(flist);\n\t}\n}\n\n/* get field by name or number */\nstatic PyObject *\nvoidtype_subscript(PyVoidScalarObject *self, PyObject *ind)\n{\n\tint n, m;\n\tchar *msg = \"invalid index\";\n\tPyObject *flist=NULL, *key, *fieldinfo;\n\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"can't index void scalar without fields\");\n\t\treturn NULL;\n\t}\n\n\tif (PyString_Check(ind) || PyUnicode_Check(ind)) {\n\t\t/* look up in fields */\n\t\tfieldinfo = PyDict_GetItem(self->descr->fields, ind);\n\t\tif (!fieldinfo) {\n\t\t\tPyErr_SetString(PyExc_IndexError, msg);\n\t\t\treturn NULL;\n\t\t}\n\t\treturn voidtype_getfield(self, fieldinfo, NULL);\n\t}\n\t\n\t/* try to convert it to a number */\n\tn = PyArray_PyIntAsIntp(ind);\n\tif (error_converting(n)) {\n\t\tPyErr_Clear();\n\t\tgoto fail;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tflist = PyDict_GetItem(self->descr->fields, key);\n\tPy_DECREF(key);\n\tif (!flist) m = 0; \n\tm = PyTuple_GET_SIZE(flist);\n\tif (n < 0) n += m;\n\tif (n < 0 || n >= m) goto fail;\n\tfieldinfo = PyDict_GetItem(self->descr->fields, \n\t\t\t\t PyTuple_GET_ITEM(flist, n));\n\treturn voidtype_getfield(self, fieldinfo, NULL);\n\n fail:\n\tPyErr_SetString(PyExc_IndexError, msg);\n\treturn NULL;\n}\n\nstatic int\nvoidtype_ass_subscript(PyVoidScalarObject *self, PyObject *ind, PyObject *val) \n{\n\tint n, m;\n\tchar *msg = \"invalid index\";\n\tPyObject *flist=NULL, *key, *fieldinfo, *newtup;\n\tPyObject *res;\n\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"can't index void scalar without fields\");\n\t\treturn -1;\n\t}\n\n\tif (PyString_Check(ind) || PyUnicode_Check(ind)) {\n\t\t/* look up in fields */\n\t\tfieldinfo = PyDict_GetItem(self->descr->fields, ind);\n\t\tif (!fieldinfo) {\n\t\t\tPyErr_SetString(PyExc_IndexError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tnewtup = Py_BuildValue(\"(OOO)\", val, \n\t\t\t\t PyTuple_GET_ITEM(fieldinfo, 0),\n\t\t\t\t PyTuple_GET_ITEM(fieldinfo, 1));\n\t\tres = voidtype_setfield(self, newtup, NULL);\n\t\tPy_DECREF(newtup);\n\t\tif (!res) return -1;\n\t\tPy_DECREF(res);\n\t\treturn 0;\n\t}\n\t\n\t/* try to convert it to a number */\n\tn = PyArray_PyIntAsIntp(ind);\n\tif (error_converting(n)) {\n\t\tPyErr_Clear();\n\t\tgoto fail;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tflist = PyDict_GetItem(self->descr->fields, key);\n\tPy_DECREF(key);\n\tif (!flist) m = 0; \n\tm = PyTuple_GET_SIZE(flist);\n\tif (n < 0) n += m;\n\tif (n < 0 || n >= m) goto fail;\n\tfieldinfo = PyDict_GetItem(self->descr->fields, \n\t\t\t\t PyTuple_GET_ITEM(flist, n));\n\tnewtup = Py_BuildValue(\"(OOO)\", val, \n\t\t\t PyTuple_GET_ITEM(fieldinfo, 0),\n\t\t\t PyTuple_GET_ITEM(fieldinfo, 1));\n\tres = voidtype_setfield(self, fieldinfo, NULL);\n\tPy_DECREF(newtup);\n\tif (!res) return -1;\n\tPy_DECREF(res);\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_IndexError, msg);\n\treturn -1;\n}\n\nstatic PyMappingMethods voidtype_as_mapping = {\n (inquiry)voidtype_length,\t\t /*mp_length*/\n (binaryfunc)voidtype_subscript,\t /*mp_subscript*/\n (objobjargproc)voidtype_ass_subscript,\t /*mp_ass_subscript*/\n};\n\n\nstatic int\ngentype_getreadbuf(PyObject *self, int segment, void **ptrptr)\n{\n\tint numbytes;\n\tPyArray_Descr *outcode;\n\t\n\tif (segment != 0) {\n\t\tPyErr_SetString(PyExc_SystemError, \n\t\t\t\t\"Accessing non-existent array segment\");\n\t\treturn -1;\n\t}\n\n\toutcode = PyArray_DescrFromScalar(self);\n\tnumbytes = outcode->elsize;\n\tif PyArray_IsScalar(self, Flexible) {\n\t\tif PyArray_IsScalar(self, String)\n\t\t\t*ptrptr = PyString_AS_STRING(self);\n\t\telse if PyArray_IsScalar(self, Unicode)\n\t\t\t*ptrptr = (char *)PyUnicode_AS_DATA(self);\n\t\telse if PyArray_IsScalar(self, Void)\n\t\t\t*ptrptr = ((PyVoidScalarObject *)self)->obval;\n\t}\n\telse \n\t\t*ptrptr = (void *)_SOFFSET_(self, outcode->type_num);\n\n\tPy_DECREF(outcode);\n\treturn numbytes;\n}\n\nstatic int\ngentype_getsegcount(PyObject *self, int *lenp)\n{\n\tPyArray_Descr *outcode;\n\n\toutcode = PyArray_DescrFromScalar(self);\n\tif (lenp)\n\t\t*lenp = outcode->elsize;\n\tPy_DECREF(outcode);\n\treturn 1;\n}\n\nstatic int\ngentype_getcharbuf(PyObject *self, int segment, const char **ptrptr)\n{\n\tif (PyArray_IsScalar(self, String) ||\t\\\n\t PyArray_IsScalar(self, Unicode))\n\t\treturn gentype_getreadbuf(self, segment, (void **)ptrptr);\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"Non-character array cannot be interpreted \"\\\n\t\t\t\t\"as character buffer.\");\n\t\treturn -1;\n\t}\n}\n\n\nstatic PyBufferProcs gentype_as_buffer = {\n (getreadbufferproc)gentype_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)0, /*bf_getwritebuffer*/\n (getsegcountproc)gentype_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)gentype_getcharbuf, /*bf_getcharbuffer*/\n};\n\n\n#define BASEFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES\n#define LEAFFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES\n\nstatic PyTypeObject PyGenericArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"genericscalar\",\t /*tp_name*/\n sizeof(PyObject),\t\t /*tp_basicsize*/\n};\n\nstatic void\nunicode_dealloc(PyObject *v) \n{\n\tPyDataMem_FREE(((PyVoidScalarObject *)v)->obval);\n\tv->ob_type->tp_free(v);\n}\n\nstatic void\nvoid_dealloc(PyVoidScalarObject *v) \n{\n\tif (v->flags & OWNDATA)\n\t\tPyDataMem_FREE(v->obval);\n\tPy_XDECREF(v->descr);\n\tPy_XDECREF(v->base);\n\tv->ob_type->tp_free(v);\n}\n\nstatic void\nobject_arrtype_dealloc(PyObject *v)\n{\n\tPy_XDECREF(((PyObjectScalarObject *)v)->obval);\n\tv->ob_type->tp_free(v);\n}\n\n/* string and unicode inherit from Python Type first and so GET_ITEM is different to\n get to the Python Type.\n */\n\n/**begin repeat \n#name=byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, object#\n#TYPE=BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, STRING, UNICODE, OBJECT#\n#num=1*16,0,0,1#\n*/\nstatic PyObject *\n@name@_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj=NULL;\n\tPyObject *arr;\n\tPyArray_Descr *typecode;\n\n\tif (type->tp_bases && (PyTuple_GET_SIZE(type->tp_bases)==2)) {\n\t\tPyTypeObject *sup;\n\t\tPyObject *ret;\n\t\t/* We are inheriting from a Python type as well so\n\t\t give it first dibs on conversion */\n\t\tsup = (PyTypeObject *)PyTuple_GET_ITEM(type->tp_bases, @num@);\n\t\tret = sup->tp_new(type, args, kwds);\n\t\tif (ret) return ret;\n\t\tPyErr_Clear();\n\t\t/* now do default conversion */\n\t}\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\n\ttypecode = PyArray_DescrFromType(PyArray_@TYPE@);\n\tarr = PyArray_FromAny(obj, typecode, 0, 0, FORCECAST, NULL);\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n/**end repeat**/\n\n/* bool->tp_new only returns Py_True or Py_False */\nstatic PyObject *\nbool_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj=NULL;\n\tPyObject *arr;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\tif (obj == Py_False)\n\t\tPyArrayScalar_RETURN_FALSE;\n\tif (obj == Py_True)\n\t\tPyArrayScalar_RETURN_TRUE;\n\tarr = PyArray_FROM_OTF(obj, PyArray_BOOL, FORCECAST);\n\tif (arr && 0 == PyArray_NDIM(arr)) {\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)PyArray_DATA(arr));\n\t}\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n\nstatic PyObject *\nbool_arrtype_and(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)&(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_and(a, b);\n}\n\nstatic PyObject *\nbool_arrtype_or(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)|(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_or(a, b);\n}\n\nstatic PyObject *\nbool_arrtype_xor(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)^(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_xor(a, b);\n}\n\nstatic int\nbool_arrtype_nonzero(PyObject *a)\n{\n\treturn a == PyArrayScalar_True;\n}\n\n/* Arithmetic methods -- only so we can override &, |, ^. */\nstatic PyNumberMethods bool_arrtype_as_number = {\n\tbool_arrtype_or,\t\t\t/* nb_add */\n\t0,\t\t\t\t\t/* nb_subtract */\n\tbool_arrtype_and,\t\t\t/* nb_multiply */\n\t0,\t\t\t\t\t/* nb_divide */\n\t0,\t\t\t\t\t/* nb_remainder */\n\t0,\t\t\t\t\t/* nb_divmod */\n\t0,\t\t\t\t\t/* nb_power */\n\t0,\t\t\t\t\t/* nb_negative */\n\t0,\t\t\t\t\t/* nb_positive */\n\t0,\t\t\t\t\t/* nb_absolute */\n\t(inquiry)bool_arrtype_nonzero,\t\t/* nb_nonzero */\n\t0,\t\t\t\t\t/* nb_invert */\n\t0,\t\t\t\t\t/* nb_lshift */\n\t0,\t\t\t\t\t/* nb_rshift */\n\t(binaryfunc)bool_arrtype_and,\t\t/* nb_and */\n\t(binaryfunc)bool_arrtype_xor,\t\t/* nb_xor */\n\t(binaryfunc)bool_arrtype_or,\t\t/* nb_or */\n};\n\nstatic PyObject *\nvoid_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj, *arr;\n\tulonglong memu=1;\n\tPyObject *new=NULL;\n\tchar *destptr;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\t/* For a VOID scalar first see if obj is an integer or long \n\t and create new memory of that size (filled with 0) for the scalar\n\t*/\n\n\tif (PyLong_Check(obj) || PyInt_Check(obj) || \\\n\t PyArray_IsScalar(obj, Integer) ||\n\t (PyArray_Check(obj) && PyArray_NDIM(obj)==0 &&\t\\\n\t PyArray_ISINTEGER(obj))) {\n\t\tnew = obj->ob_type->tp_as_number->nb_long(obj);\n\t}\n\tif (new && PyLong_Check(new)) {\n\t\tPyObject *ret;\n\t\tmemu = PyLong_AsUnsignedLongLong(new);\n\t\tPy_DECREF(new);\n\t\tif (PyErr_Occurred() || (memu > MAX_INT)) {\n\t\t\tPyErr_Clear();\n\t\t\tPyErr_Format(PyExc_OverflowError, \n\t\t\t\t \"size must be smaller than %d\",\n\t\t\t\t (int) MAX_INT);\n\t\t\treturn NULL;\n\t\t}\n\t\tdestptr = PyDataMem_NEW((int) memu);\n\t\tif (destptr == NULL) return PyErr_NoMemory();\n\t\tret = type->tp_alloc(type, 0);\n\t\tif (ret == NULL) {\n\t\t\tPyDataMem_FREE(destptr);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\t((PyVoidScalarObject *)ret)->obval = destptr;\n\t\t((PyVoidScalarObject *)ret)->ob_size = (int) memu;\n\t\t((PyVoidScalarObject *)ret)->descr = \\\n\t\t\tPyArray_DescrNewFromType(PyArray_VOID);\n\t\t((PyVoidScalarObject *)ret)->descr->elsize = (int) memu;\n\t\t((PyVoidScalarObject *)ret)->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t((PyVoidScalarObject *)ret)->base = NULL;\n\t\tmemset(destptr, '\\0', (size_t) memu);\n\t\treturn ret;\n\t}\n\n\tarr = PyArray_FROM_OTF(obj, PyArray_VOID, FORCECAST);\n return PyArray_Return((PyArrayObject *)arr);\n}\n\n\n/**************** Define Hash functions ********************/\n\n/**begin repeat\n#lname=bool,ubyte,ushort#\n#name=Bool,UByte, UShort#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n return (long)(((Py@name@ScalarObject *)obj)->obval);\n}\n/**end repeat**/\n\n/**begin repeat\n#lname=byte,short,uint,ulong#\n#name=Byte,Short,UInt,ULong#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((Py@name@ScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n/**end repeat**/\n\n#if SIZEOF_INT != SIZEOF_LONG\nstatic long\nint_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((PyIntScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n#endif\n\n/**begin repeat\n#char=,u#\n#Char=,U#\n#ext=&& (x >= LONG_MIN),#\n*/\n#if SIZEOF_LONG != SIZEOF_LONGLONG\n/* we assume SIZEOF_LONGLONG=2*SIZEOF_LONG */\nstatic long\n@char@longlong_arrtype_hash(PyObject *obj)\n{\n long y;\n @char@longlong x = (((Py@Char@LongLongScalarObject *)obj)->obval);\n\n if ((x <= LONG_MAX)@ext@) {\n y = (long) x;\n }\n else {\n union Mask {\n long hashvals[2];\n @char@longlong v;\n } both;\n\n both.v = x;\n y = both.hashvals[0] + (1000003)*both.hashvals[1];\n }\n if (y == -1) y = -2;\n return y;\n}\n#endif\n/**end repeat**/\n\n#if SIZEOF_LONG==SIZEOF_LONGLONG\nstatic long\nulonglong_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((PyULongLongScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n#endif\n\n\n\n/* Wrong thing to do for longdouble, but....*/\n/**begin repeat\n#lname=float, longdouble#\n#name=Float, LongDouble#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n return _Py_HashDouble((double) ((Py@name@ScalarObject *)obj)->obval);\n}\n\n/* borrowed from complex_hash */\nstatic long\nc@lname@_arrtype_hash(PyObject *obj)\n{\n long hashreal, hashimag, combined;\n hashreal = _Py_HashDouble((double) \\\n (((PyC@name@ScalarObject *)obj)->obval).real);\n\n if (hashreal == -1) return -1;\n hashimag = _Py_HashDouble((double) \\\n (((PyC@name@ScalarObject *)obj)->obval).imag);\n if (hashimag == -1) return -1;\n\n combined = hashreal + 1000003 * hashimag;\n if (combined == -1) combined = -2;\n return combined;\n}\n/**end repeat**/\n\nstatic long\nobject_arrtype_hash(PyObject *obj)\n{\n return PyObject_Hash(((PyObjectScalarObject *)obj)->obval);\n}\n\n/* just hash the pointer */\nstatic long\nvoid_arrtype_hash(PyObject *obj)\n{\n return _Py_HashPointer((void *)(((PyVoidScalarObject *)obj)->obval));\n}\n\n/*object arrtype getattro and setattro */\nstatic PyObject *\nobject_arrtype_getattro(PyObjectScalarObject *obj, PyObject *attr) {\n\tPyObject *res;\n\n\t/* first look in object and then hand off to generic type */\n\n\tres = PyObject_GenericGetAttr(obj->obval, attr);\t\n\tif (res) return res;\n\tPyErr_Clear();\n\treturn \tPyObject_GenericGetAttr((PyObject *)obj, attr);\n}\n\nstatic int\nobject_arrtype_setattro(PyObjectScalarObject *obj, PyObject *attr, PyObject *val) {\n\tint res;\n\t/* first look in object and then hand off to generic type */\n\n\tres = PyObject_GenericSetAttr(obj->obval, attr, val);\n\tif (res >= 0) return res;\n\tPyErr_Clear();\n\treturn PyObject_GenericSetAttr((PyObject *)obj, attr, val);\n}\n\nstatic PyObject *\nobject_arrtype_concat(PyObjectScalarObject *self, PyObject *other)\n{\n\treturn PySequence_Concat(self->obval, other);\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_length(PyObjectScalarObject *self) \n{\n\treturn PyObject_Length(self->obval);\n}\n\nstatic PyObject *\nobject_arrtype_repeat(PyObjectScalarObject *self, _int_or_ssize_t count)\n{\n\treturn PySequence_Repeat(self->obval, count);\n}\n\nstatic PyObject *\nobject_arrtype_subscript(PyObjectScalarObject *self, PyObject *key)\n{\n\treturn PyObject_GetItem(self->obval, key);\n}\n\nstatic int\nobject_arrtype_ass_subscript(PyObjectScalarObject *self, PyObject *key, \n\t\t\t PyObject *value)\n{\n\treturn PyObject_SetItem(self->obval, key, value);\n}\n\nstatic int\nobject_arrtype_contains(PyObjectScalarObject *self, PyObject *ob)\n{\n\treturn PySequence_Contains(self->obval, ob);\n}\n\nstatic PyObject *\nobject_arrtype_inplace_concat(PyObjectScalarObject *self, PyObject *o)\n{\n\treturn PySequence_InPlaceConcat(self->obval, o);\n}\n\nstatic PyObject *\nobject_arrtype_inplace_repeat(PyObjectScalarObject *self, _int_or_ssize_t count)\n{\n\treturn PySequence_InPlaceRepeat(self->obval, count);\n}\n\nstatic PySequenceMethods object_arrtype_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)object_arrtype_length, /*sq_length*/\n (binaryfunc)object_arrtype_concat, /*sq_concat*/\n (ssizeargfunc)object_arrtype_repeat, /*sq_repeat*/\n 0, /*sq_item*/\n 0, /*sq_slice*/\n 0, /* sq_ass_item */\n 0, /* sq_ass_slice */\n (objobjproc)object_arrtype_contains, /* sq_contains */\n (binaryfunc)object_arrtype_inplace_concat, /* sq_inplace_concat */\n (ssizeargfunc)object_arrtype_inplace_repeat, /* sq_inplace_repeat */\n#else\n (inquiry)object_arrtype_length, /*sq_length*/\n (binaryfunc)object_arrtype_concat, /*sq_concat*/\n (intargfunc)object_arrtype_repeat, /*sq_repeat*/\n 0, /*sq_item*/\n 0, /*sq_slice*/\n 0, /* sq_ass_item */\n 0, /* sq_ass_slice */\n (objobjproc)object_arrtype_contains, /* sq_contains */\n (binaryfunc)object_arrtype_inplace_concat, /* sq_inplace_concat */\n (intargfunc)object_arrtype_inplace_repeat, /* sq_inplace_repeat */\n#endif\n};\n\nstatic PyMappingMethods object_arrtype_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)object_arrtype_length,\n (binaryfunc)object_arrtype_subscript,\n (objobjargproc)object_arrtype_ass_subscript,\n#else\n (inquiry)object_arrtype_length,\n (binaryfunc)object_arrtype_subscript,\n (objobjargproc)object_arrtype_ass_subscript,\n#endif\n};\n\nstatic _int_or_ssize_t\nobject_arrtype_getsegcount(PyObjectScalarObject *self, _int_or_ssize_t *lenp) \n{\n\tint newlen;\n\tint cnt;\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\t\n\tif (pb == NULL || \\\n\t pb->bf_getsegcount == NULL || \\\n\t (cnt = (*pb->bf_getsegcount)(self->obval, &newlen)) != 1) \n\t\treturn 0;\n\t\n\tif (lenp) \n\t\t*lenp = newlen;\n\t\n\treturn cnt;\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_getreadbuf(PyObjectScalarObject *self, _int_or_ssize_t segment, void **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getreadbuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a readable buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getreadbuffer)(self->obval, segment, ptrptr);\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_getwritebuf(PyObjectScalarObject *self, _int_or_ssize_t segment, void **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getwritebuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a writeable buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getwritebuffer)(self->obval, segment, ptrptr);\n}\n\nstatic _int_or_ssize_t \nobject_arrtype_getcharbuf(PyObjectScalarObject *self, _int_or_ssize_t segment, \n\t\t\t const char **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getcharbuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a character buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getcharbuffer)(self->obval, segment, ptrptr);\n}\n\nstatic PyBufferProcs object_arrtype_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)object_arrtype_getreadbuf,\n (writebufferproc)object_arrtype_getwritebuf,\n (segcountproc)object_arrtype_getsegcount,\n (charbufferproc)object_arrtype_getcharbuf,\n#else\n (getreadbufferproc)object_arrtype_getreadbuf,\n (getwritebufferproc)object_arrtype_getwritebuf,\n (getsegcountproc)object_arrtype_getsegcount,\n (getcharbufferproc)object_arrtype_getcharbuf,\n#endif\n};\n\nstatic PyObject *\nobject_arrtype_call(PyObjectScalarObject *obj, PyObject *args, PyObject *kwds)\n{\n\treturn PyObject_Call(obj->obval, args, kwds);\n}\n\nstatic PyTypeObject PyObjectArrType_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"objectscalar\",\t /*tp_name*/\n sizeof(PyObjectScalarObject),\t /*tp_basicsize*/\n 0, /* tp_itemsize */\n (destructor)object_arrtype_dealloc, /* tp_dealloc */\n 0, /* tp_print */\n 0, /* tp_getattr */\n 0, /* tp_setattr */\n 0, /* tp_compare */\n 0, /* tp_repr */\n 0, /* tp_as_number */\n &object_arrtype_as_sequence, /* tp_as_sequence */\n &object_arrtype_as_mapping, /* tp_as_mapping */\n 0, /* tp_hash */\n (ternaryfunc)object_arrtype_call, /* tp_call */\n 0, /* tp_str */\n (getattrofunc)object_arrtype_getattro, /* tp_getattro */\n (setattrofunc)object_arrtype_setattro, /* tp_setattro */\n &object_arrtype_as_buffer, /* tp_as_buffer */\n 0, /* tp_flags */\n};\n\n/**begin repeat\n#name=bool, string, unicode, void#\n#NAME=Bool, String, Unicode, Void#\n*/\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@scalar\",\t /*tp_name*/\n sizeof(Py@NAME@ScalarObject),\t /*tp_basicsize*/\n};\n/**end repeat**/\n\n/**begin repeat\n#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n#name=int*5, uint*5, float*3, complex*3#\n#CNAME=(CHAR, SHORT, INT, LONG, LONGLONG)*2, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n*/\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@\" STRBITSOF_@CNAME@ \"scalar\",\t /*tp_name*/\n sizeof(Py@NAME@ScalarObject),\t /*tp_basicsize*/\n};\n\n/**end repeat**/\n\n\nstatic PyNumberMethods longdoubletype_as_number;\nstatic PyNumberMethods clongdoubletype_as_number;\n\n\nstatic void\ninitialize_numeric_types(void)\n{\n\tPyGenericArrType_Type.tp_dealloc = (destructor)gentype_dealloc;\n\tPyGenericArrType_Type.tp_as_number = &gentype_as_number;\n\tPyGenericArrType_Type.tp_as_buffer = &gentype_as_buffer;\n\tPyGenericArrType_Type.tp_flags = BASEFLAGS;\n\tPyGenericArrType_Type.tp_methods = gentype_methods;\n\tPyGenericArrType_Type.tp_getset = gentype_getsets;\n\tPyGenericArrType_Type.tp_new = NULL;\n PyGenericArrType_Type.tp_alloc = gentype_alloc;\n\tPyGenericArrType_Type.tp_free = _pya_free;\n\tPyGenericArrType_Type.tp_repr = gentype_repr;\n\tPyGenericArrType_Type.tp_str = gentype_str;\n\tPyGenericArrType_Type.tp_richcompare = gentype_richcompare;\n\n\tPyBoolArrType_Type.tp_as_number = &bool_arrtype_as_number;\n\n\tPyStringArrType_Type.tp_alloc = NULL;\n\tPyStringArrType_Type.tp_free = NULL;\n\t\n\tPyStringArrType_Type.tp_repr = stringtype_repr;\n\tPyStringArrType_Type.tp_str = stringtype_str;\n\n\tPyUnicodeArrType_Type.tp_repr = unicodetype_repr;\n\tPyUnicodeArrType_Type.tp_str = unicodetype_str;\n\n\tPyVoidArrType_Type.tp_methods = voidtype_methods;\n\tPyVoidArrType_Type.tp_getset = voidtype_getsets;\n\tPyVoidArrType_Type.tp_as_mapping = &voidtype_as_mapping;\n\t\n\t/**begin repeat\n#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating, \nComplexFloating, Flexible, Character#\n\t*/\n Py@NAME@ArrType_Type.tp_flags = BASEFLAGS;\n\t/**end repeat**/\n\n\t/**begin repeat\n#name=bool, byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, void, object#\n#NAME=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, String, Unicode, Void, Object#\n\t*/\n\tPy@NAME@ArrType_Type.tp_flags = LEAFFLAGS;\n\tPy@NAME@ArrType_Type.tp_new = @name@_arrtype_new;\n\tPy@NAME@ArrType_Type.tp_richcompare = gentype_richcompare;\n\t/**end repeat**/\n\t/* Allow the Void type to be subclassed -- for adding new types */\n\tPyVoidArrType_Type.tp_flags = BASEFLAGS;\n\n /**begin repeat\n#name=bool, byte, short, ubyte, ushort, uint, ulong, ulonglong, float, longdouble, cfloat, clongdouble, void, object#\n#NAME=Bool, Byte, Short, UByte, UShort, UInt, ULong, ULongLong, Float, LongDouble, CFloat, CLongDouble, Void, Object#\n */\n Py@NAME@ArrType_Type.tp_hash = @name@_arrtype_hash;\n /**end repeat**/\n\n#if SIZEOF_INT != SIZEOF_LONG\n /* We won't be inheriting from Python Int type. */\n PyIntArrType_Type.tp_hash = int_arrtype_hash;\n#endif\n\n#if SIZEOF_LONG != SIZEOF_LONGLONG\n /* We won't be inheriting from Python Int type. */\n PyLongLongArrType_Type.tp_hash = longlong_arrtype_hash;\n#endif\n\n\t/* These need to be coded specially because getitem does not\n\t return a normal Python type\n\t*/\n\tPyLongDoubleArrType_Type.tp_as_number = &longdoubletype_as_number;\n\tPyCLongDoubleArrType_Type.tp_as_number = &clongdoubletype_as_number;\n\n\t/**begin repeat\n#name=int, long, hex, oct, float, repr, str#\n#kind=tp_as_number->nb*5, tp*2#\n\t*/\n\tPyLongDoubleArrType_Type.@kind@_@name@ = longdoubletype_@name@;\n\tPyCLongDoubleArrType_Type.@kind@_@name@ = clongdoubletype_@name@;\n\t/**end repeat**/\n\n\tPyStringArrType_Type.tp_itemsize = sizeof(char);\n\tPyVoidArrType_Type.tp_dealloc = (destructor) void_dealloc;\n\tPyUnicodeArrType_Type.tp_dealloc = unicode_dealloc;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMapIter_Type.tp_iter = PyObject_SelfIter;\n\n/**begin repeat\n#name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,#\n#num=BOOL, BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, OBJECT, NTYPES#\n**/\n PyArrayScalar_Offset[PyArray_@num@] = (int) offsetof(Py@name@ScalarObject, obval);\n/**end repeat**/\n}\n\n\n/* the order of this table is important */\nstatic PyTypeObject *typeobjects[] = {\n &PyBoolArrType_Type,\n &PyByteArrType_Type,\n\t&PyUByteArrType_Type,\n &PyShortArrType_Type,\n &PyUShortArrType_Type,\n\t&PyIntArrType_Type,\n\t&PyUIntArrType_Type,\n\t&PyLongArrType_Type,\n\t&PyULongArrType_Type,\n\t&PyLongLongArrType_Type,\n\t&PyULongLongArrType_Type,\n\t&PyFloatArrType_Type,\n\t&PyDoubleArrType_Type,\n\t&PyLongDoubleArrType_Type,\n\t&PyCFloatArrType_Type,\n\t&PyCDoubleArrType_Type,\n\t&PyCLongDoubleArrType_Type,\n\t&PyObjectArrType_Type,\n\t&PyStringArrType_Type,\n\t&PyUnicodeArrType_Type,\n\t&PyVoidArrType_Type\n};\n\nstatic int\n_typenum_fromtypeobj(PyObject *type, int user)\n{\n\tint typenum, i;\n\n\ttypenum = PyArray_NOTYPE;\n i = 0;\n\twhile(i < PyArray_NTYPES) {\n\t\tif (type == (PyObject *)typeobjects[i]) {\n\t\t\ttypenum = i;\n\t\t\tbreak;\n\t\t}\n i++;\n\t}\n\t\n\tif (!user) return typenum;\n\n\t/* Search any registered types */\n\ti = 0;\n\twhile (i < PyArray_NUMUSERTYPES) {\n\t\tif (type == (PyObject *)(userdescrs[i]->typeobj)) {\n\t\t\ttypenum = i + PyArray_USERDEF;\n\t\t\tbreak;\n\t\t}\n\t\ti++;\n\t}\n\treturn typenum;\n}\n\n/* new reference */\nstatic PyArray_Descr *\nPyArray_DescrFromTypeObject(PyObject *type)\n{\t\n\tint typenum;\n\tPyArray_Descr *new, *conv=NULL;\n\n\t/* if it's a builtin type, then use the typenumber */\n\ttypenum = _typenum_fromtypeobj(type,1);\t\n\tif (typenum != PyArray_NOTYPE) {\n\t\tnew = PyArray_DescrFromType(typenum);\n\t\tif (PyTypeNum_ISUSERDEF(typenum)) goto finish;\n\t\treturn new;\n\t}\n\n\t/* Check the generic types */\n\tif ((type == (PyObject *) &PyNumberArrType_Type) ||\t\t\\\n\t (type == (PyObject *) &PyInexactArrType_Type) ||\t\t\\\n\t (type == (PyObject *) &PyFloatingArrType_Type))\n\t\ttypenum = PyArray_DOUBLE;\n\telse if (type == (PyObject *)&PyComplexFloatingArrType_Type)\n\t\ttypenum = PyArray_CDOUBLE;\n\telse if ((type == (PyObject *)&PyIntegerArrType_Type) ||\t\\\n\t\t (type == (PyObject *)&PySignedIntegerArrType_Type))\n\t\ttypenum = PyArray_LONG;\n\telse if (type == (PyObject *) &PyUnsignedIntegerArrType_Type)\n\t\ttypenum = PyArray_ULONG;\n\telse if (type == (PyObject *) &PyCharacterArrType_Type)\n\t\ttypenum = PyArray_STRING;\n\telse if ((type == (PyObject *) &PyGenericArrType_Type) || \\\n\t\t (type == (PyObject *) &PyFlexibleArrType_Type))\n\t\ttypenum = PyArray_VOID;\n\n\tif (typenum != PyArray_NOTYPE) {\n\t\treturn PyArray_DescrFromType(typenum);\n\t}\n\t\n\t/* Otherwise --- type is a sub-type of an array scalar\n\t currently only VOID allows it -- use it as the type-object.\n\t*/\n\t/* look for a dtypedescr attribute */\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\n finish:\n\tconv = _arraydescr_fromobj(type);\n\tif (conv) {\n\t\tnew->fields = conv->fields;\n\t\tPy_INCREF(new->fields);\n\t\tnew->elsize = conv->elsize;\n\t\tnew->subarray = conv->subarray;\n\t\tconv->subarray = NULL;\n\t\tPy_DECREF(conv);\n\t}\n Py_DECREF(new->typeobj);\n new->typeobj = (PyTypeObject *)type;\n Py_INCREF(type);\n\treturn new;\n}\n\n/* New reference */\n/*OBJECT_API\n Return descr object from array scalar.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromScalar(PyObject *sc)\n{\n\tint type_num;\n\tPyArray_Descr *descr;\n\n\tif PyArray_IsScalar(sc, Void) {\n\t\tdescr = ((PyVoidScalarObject *)sc)->descr;\n\t\tPy_INCREF(descr);\n\t\treturn descr;\n\t}\n descr = PyArray_DescrFromTypeObject((PyObject *)sc->ob_type);\n if (descr->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(descr);\n type_num = descr->type_num;\n\t\tif (type_num == PyArray_STRING) \n\t\t\tdescr->elsize = PyString_GET_SIZE(sc);\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tdescr->elsize = PyUnicode_GET_DATA_SIZE(sc);\n#ifndef Py_UNICODE_WIDE\n\t\t\tdescr->elsize <<= 1;\n#endif\t\t\n\t\t}\n\t\telse {\n\t\t\tdescr->elsize =\t\t\t\t\t\\\n\t\t\t\t((PyVoidScalarObject *)sc)->ob_size;\n\t\t\tdescr->fields = PyObject_GetAttrString(sc, \"fields\");\n\t\t\tif (!descr->fields || !PyDict_Check(descr->fields) || \\\n\t\t\t (descr->fields == Py_None)) {\n\t\t\t\tPy_XDECREF(descr->fields);\n\t\t\t\tdescr->fields = NULL;\n\t\t\t}\n\t\t\tPyErr_Clear();\n\t\t}\n }\n\treturn descr;\n}\n\n/* New reference */\n/*OBJECT_API\n Get a typeobject from a type-number\n*/\nstatic PyObject *\nPyArray_TypeObjectFromType(int type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr == NULL) return NULL;\n\tobj = (PyObject *)descr->typeobj;\n\tPy_INCREF(obj);\n\tPy_DECREF(descr);\n\treturn obj;\n}\n\n", + "source_code_before": "/* -*- c -*- */\n\n#ifndef _MULTIARRAYMODULE\n#define _MULTIARRAYMODULE\n#endif\n#include \"numpy/arrayscalars.h\"\nstatic int PyArrayScalar_Offset[PyArray_NTYPES+1];\n\n#define _SOFFSET_(obj, type_num) ((char *)(obj) + PyArrayScalar_Offset[(type_num)])\n\nstatic PyBoolScalarObject _PyArrayScalar_BoolValues[2] = {\n\t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 0},\n\t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 1},\n};\n\n/* Inheritance established later when tp_bases is set (or tp_base for \n single inheritance) */\n\n/**begin repeat\n\n#name=number, integer, signedinteger, unsignedinteger, inexact, floating, complexfloating, flexible, \ncharacter#\n#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating, ComplexFloating, Flexible, Character#\n*/\n\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@scalar\",\t\t /*tp_name*/\n sizeof(PyObject),\t\t /*tp_basicsize*/\n};\n/**end repeat**/\n\n\n/* no error checking is performed -- ctypeptr must be same type as scalar */\n/* in case of flexible type, the data is not copied \n into ctypeptr which is expected to be a pointer to pointer */\n/*OBJECT_API\n Convert to c-type\n*/\nstatic void\nPyArray_ScalarAsCtype(PyObject *scalar, void *ctypeptr)\n{\n\tPyArray_Descr *typecode;\n\ttypecode = PyArray_DescrFromScalar(scalar);\n\t\n\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\tvoid **newptr = (void **)ctypeptr;\n\t\tswitch(typecode->type_num) {\n\t\tcase PyArray_STRING:\n\t\t\t*newptr = (void *)PyString_AS_STRING(scalar);\n break;\n\t\tcase PyArray_UNICODE:\n\t\t\t*newptr = (void *)PyUnicode_AS_DATA(scalar);\n break;\n\t\tdefault:\n\t\t\t*newptr = ((PyVoidScalarObject *)scalar)->obval;\n break;\n\t\t}\n\t\treturn;\n\t}\n\tmemcpy(ctypeptr, _SOFFSET_(scalar, typecode->type_num),\n\t typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn;\n}\n\n/* The output buffer must be large-enough to receive the value */\n/* Even for flexible types which is different from ScalarAsCtype\n where only a reference for flexible types is returned \n*/\n\n/*OBJECT_API\n Cast Scalar to c-type\n*/\nstatic int\nPyArray_CastScalarToCtype(PyObject *scalar, void *ctypeptr, \n\t\t\t PyArray_Descr *outcode)\n{\n\tPyArray_Descr* descr;\n\t\n\tdescr = PyArray_DescrFromScalar(scalar);\n\tif (PyTypeNum_ISEXTENDED(descr->type_num) ||\n\t PyTypeNum_ISEXTENDED(outcode->type_num)) {\n\t\tPyArrayObject *ain, *aout;\n\n\t\tain = (PyArrayObject *)PyArray_FromScalar(scalar, NULL);\n\t\tif (ain == NULL) {Py_DECREF(descr); return -1;}\n\t\taout = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t outcode,\n\t\t\t\t\t 0, NULL, \n\t\t\t\t\t NULL, ctypeptr, \n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\t\tif (aout == NULL) {Py_DECREF(ain); return -1;}\n\t\tdescr->f->cast[outcode->type_num](ain->data, \n\t\t\t\t\t aout->data, 1, ain, aout);\n\t\tPy_DECREF(ain);\n\t\tPy_DECREF(aout);\n\t}\n\telse {\n\t\tdescr->f->cast[outcode->type_num](_SOFFSET_(scalar, \n\t\t\t\t\t\t\t descr->type_num), \n\t\t\t\t\t ctypeptr, 1, NULL, NULL);\n\t}\n\tPy_DECREF(descr);\n\treturn 0;\n}\n\n/* 0-dim array from array-scalar object */\n/* always contains a copy of the data \n unless outcode is NULL, it is of void type and the referrer does\n not own it either.\n*/\n\n/* steals reference to outcode */\n/*OBJECT_API\n Get 0-dim array from scalar\n*/\nstatic PyObject *\nPyArray_FromScalar(PyObject *scalar, PyArray_Descr *outcode)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *r;\n\tchar *memptr;\n\tPyObject *ret;\n\n\t/* convert to 0-dim array of scalar typecode */\n\ttypecode = PyArray_DescrFromScalar(scalar);\n\tif ((typecode->type_num == PyArray_VOID) &&\t\t\t\\\n\t !(((PyVoidScalarObject *)scalar)->flags & OWNDATA) &&\t\\\n\t outcode == NULL) {\n\t\tr = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t typecode,\n\t\t\t\t\t 0, NULL, NULL,\n\t\t\t\t\t ((PyVoidScalarObject *)scalar)->obval,\n\t\t\t\t\t ((PyVoidScalarObject *)scalar)->flags,\n\t\t\t\t\t NULL);\n\t\tPyArray_BASE(r) = (PyObject *)scalar;\n\t\tPy_INCREF(scalar);\n\t\treturn r;\n\t}\n\tr = PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t typecode,\n\t\t\t\t 0, NULL, \n\t\t\t\t NULL, NULL, 0, NULL);\n\tif (r==NULL) {Py_XDECREF(outcode); return NULL;}\n\n\tswitch(typecode->type_num) {\n\tcase PyArray_STRING:\n\t\tmemptr = PyString_AS_STRING(scalar);\n\t\tbreak;\n\tcase PyArray_UNICODE:\n\t\tmemptr = (char *)PyUnicode_AS_DATA(scalar);\n#ifdef Py_UNICODE_WIDE\n\t\tbreak;\n#else\n\t\tPyUCS2Buffer_AsUCS4((Py_UNICODE *)memptr, \n\t\t\t\t (PyArray_UCS4 *)PyArray_DATA(r),\n\t\t\t\t PyUnicode_GET_SIZE(scalar),\n\t\t\t\t PyArray_ITEMSIZE(r) >> 2);\n goto finish;\n#endif\n\tdefault:\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tmemptr = (((PyVoidScalarObject *)scalar)->obval);\n\t\t}\n\t\telse {\n\t\t\tmemptr = _SOFFSET_(scalar, typecode->type_num);\n\t\t}\n\t\tbreak;\n\t}\n\n\tmemcpy(PyArray_DATA(r), memptr, PyArray_ITEMSIZE(r));\n\tif (PyArray_ISOBJECT(r)) {\n\t\tPy_INCREF(*((PyObject **)memptr));\n\t}\n#ifndef Py_UNICODE_WIDE\n finish:\t\n#endif\n\tif (outcode == NULL) return r;\n\t\n\tif (outcode->type_num == typecode->type_num) {\n\t\tif (!PyTypeNum_ISEXTENDED(typecode->type_num))\n\t\t\treturn r;\n\t\tif (outcode->elsize == typecode->elsize);\n\t\treturn r;\t\t\t\n\t}\n\t\n\t/* cast if necessary to desired output typecode */\n\tret = PyArray_CastToType((PyArrayObject *)r, outcode, 0);\n\tPy_DECREF(r);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n const size_t size = _PyObject_VAR_SIZE(type, nitems+1);\n\n obj = (PyObject *)_pya_malloc(size);\n\tmemset(obj, 0, size);\n\tif (type->tp_itemsize == 0)\n PyObject_INIT(obj, type);\n else\n (void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems);\n return obj;\n}\n\nstatic void\ngentype_dealloc(PyObject *v) \n{\n\tv->ob_type->tp_free(v);\n}\n\n\nstatic PyObject *\ngentype_power(PyObject *m1, PyObject *m2, PyObject *m3)\n{\n\tPyObject *arr, *ret, *arg2;\n\tchar *msg=\"unsupported operand type(s) for ** or pow()\";\n\t\n\tif (!PyArray_IsScalar(m1,Generic)) {\n\t\tif (PyArray_Check(m1)) {\n\t\t\tret = m1->ob_type->tp_as_number->nb_power(m1,m2, \n\t\t\t\t\t\t\t\t Py_None);\n\t\t}\n\t\telse {\n\t\t\tif (!PyArray_IsScalar(m2,Generic)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tarr = PyArray_FromScalar(m2, NULL);\n\t\t\tif (arr == NULL) return NULL;\n\t\t\tret = arr->ob_type->tp_as_number->nb_power(m1, arr,\n\t\t\t\t\t\t\t\t Py_None);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t\treturn ret;\n\t}\n\tif (!PyArray_IsScalar(m2, Generic)) {\n\t\tif (PyArray_Check(m2)) {\n\t\t\tret = m2->ob_type->tp_as_number->nb_power(m1,m2, \n\t\t\t\t\t\t\t\t Py_None);\n\t\t}\n\t\telse {\n\t\t\tif (!PyArray_IsScalar(m1, Generic)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tarr = PyArray_FromScalar(m1, NULL);\n\t\t\tif (arr == NULL) return NULL;\n\t\t\tret = arr->ob_type->tp_as_number->nb_power(arr, m2,\n\t\t\t\t\t\t\t\t Py_None);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t\treturn ret;\n\t}\n\tarr=arg2=NULL;\n\tarr = PyArray_FromScalar(m1, NULL);\n\targ2 = PyArray_FromScalar(m2, NULL);\t\n\tif (arr == NULL || arg2 == NULL) {\n\t\tPy_XDECREF(arr); Py_XDECREF(arg2); return NULL;\n\t}\n\tret = arr->ob_type->tp_as_number->nb_power(arr, arg2, Py_None);\n\tPy_DECREF(arr);\n\tPy_DECREF(arg2);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_generic_method(PyObject *self, PyObject *args, PyObject *kwds, \n\t\t char *str)\n{\n\tPyObject *arr, *meth, *ret;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tmeth = PyObject_GetAttrString(arr, str);\n\tif (meth == NULL) {Py_DECREF(arr); return NULL;}\n\tif (kwds == NULL) \n\t\tret = PyObject_CallObject(meth, args);\n\telse\n\t\tret = PyObject_Call(meth, args, kwds);\n\tPy_DECREF(meth);\n\tPy_DECREF(arr);\n if (ret && PyArray_Check(ret))\n return PyArray_Return((PyArrayObject *)ret);\n else\n return ret;\n}\n\n/**begin repeat\n\n#name=add, subtract, divide, remainder, divmod, lshift, rshift, and, xor, or, floor_divide, true_divide#\n#PYNAME=Add, Subtract, Divide, Remainder, Divmod, Lshift, Rshift, And, Xor, Or, FloorDivide, TrueDivide#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *m1, PyObject *m2)\n{\n\treturn PyArray_Type.tp_as_number->nb_@name@(m1, m2);\n}\n/**end repeat**/\n\n\nstatic PyObject *\ngentype_multiply(PyObject *m1, PyObject *m2)\n{\n\tPyObject *ret=NULL;\n\tlong repeat;\n\n\tif (!PyArray_IsScalar(m1, Generic) && \n\t ((m1->ob_type->tp_as_number == NULL) ||\n\t (m1->ob_type->tp_as_number->nb_multiply == NULL))) {\n\t\t/* Try to convert m2 to an int and try sequence\n\t\t repeat */\n\t\trepeat = PyInt_AsLong(m2);\n\t\tif (repeat == -1 && PyErr_Occurred()) return NULL;\n\t\tret = PySequence_Repeat(m1, (int) repeat);\n\t}\n\telse if (!PyArray_IsScalar(m2, Generic) && \n\t\t ((m2->ob_type->tp_as_number == NULL) ||\n\t\t (m2->ob_type->tp_as_number->nb_multiply == NULL))) {\n\t\t/* Try to convert m1 to an int and try sequence\n\t\t repeat */\n\t\trepeat = PyInt_AsLong(m1);\n\t\tif (repeat == -1 && PyErr_Occurred()) return NULL;\n\t\tret = PySequence_Repeat(m2, (int) repeat);\n\t}\n\tif (ret==NULL) {\n\t\tPyErr_Clear(); /* no effect if not set */\n\t\tret = PyArray_Type.tp_as_number->nb_multiply(m1, m2);\n\t}\n\treturn ret;\n}\n\n/**begin repeat\n\n#name=positive, negative, absolute, invert, int, long, float, oct, hex#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *m1)\n{\n\tPyObject *arr, *ret;\n\n\tarr = PyArray_FromScalar(m1, NULL);\n\tif (arr == NULL) return NULL;\n\tret = arr->ob_type->tp_as_number->nb_@name@(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n/**end repeat**/\n\nstatic int\ngentype_nonzero_number(PyObject *m1)\n{\n\tPyObject *arr;\n\tint ret;\n\n\tarr = PyArray_FromScalar(m1, NULL);\n\tif (arr == NULL) return -1;\n\tret = arr->ob_type->tp_as_number->nb_nonzero(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_str(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret, *tmp;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tif (arr==NULL) return NULL;\n\tret = PyObject_Str((tmp=arr->descr->f->getitem(arr->data, arr)));\n\tPy_DECREF(arr);\n\tPy_XDECREF(tmp);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_repr(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret, *tmp ;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tif (arr==NULL) return NULL;\n\tret = PyObject_Repr((tmp=arr->descr->f->getitem(arr->data, arr)));\n\tPy_DECREF(arr);\n\tPy_XDECREF(tmp);\n\treturn ret;\n}\n\nstatic void\nformat_longdouble(char *buf, size_t buflen, longdouble val, int precision)\n{\n register char *cp;\n\n PyOS_snprintf(buf, buflen, \"%.*\" LONGDOUBLE_FMT, precision, val);\n cp = buf;\n if (*cp == '-')\n cp++;\n for (; *cp != '\\0'; cp++) {\n if (!isdigit(Py_CHARMASK(*cp)))\n break;\n }\n if (*cp == '\\0') {\n *cp++ = '.';\n *cp++ = '0';\n *cp++ = '\\0';\n }\n}\n\n/* over-ride repr and str of array-scalar strings and unicode to \n remove NULL bytes and then call the corresponding functions \n of string and unicode. \n */\n\n/**begin repeat\n#name=string*2,unicode*2#\n#form=(repr,str)*2#\n#Name=String*2,Unicode*2#\n#NAME=STRING*2,UNICODE*2#\n#extra=AndSize*2,,#\n#type=char*2, Py_UNICODE*2#\n*/\nstatic PyObject *\n@name@type_@form@(PyObject *self)\n{\n\tconst @type@ *dptr, *ip;\n\tint len;\n\tPyObject *new;\n\tPyObject *ret;\n\n\tip = dptr = Py@Name@_AS_@NAME@(self);\n\tlen = Py@Name@_GET_SIZE(self);\n\tdptr += len-1;\n\twhile(len > 0 && *dptr-- == 0) len--;\n\tnew = Py@Name@_From@Name@@extra@(ip, len);\n\tif (new == NULL) return PyString_FromString(\"\");\n\tret = Py@Name@_Type.tp_@form@(new);\n\tPy_DECREF(new);\n\treturn ret;\n}\n/**end repeat**/\n\n\n\n#if SIZEOF_LONGDOUBLE == SIZEOF_DOUBLE\n#define PREC_REPR 17\n#define PREC_STR 17\n#else\n#define PREC_REPR 21\n#define PREC_STR 21\n#endif\n\nstatic PyObject *\nlongdoubletype_repr(PyObject *self)\n{\n static char buf[100];\n format_longdouble(buf, sizeof(buf), ((PyLongDoubleScalarObject *)self)->obval, PREC_REPR);\n return PyString_FromString(buf);\n}\n\nstatic PyObject *\nclongdoubletype_repr(PyObject *self)\n{\n static char buf1[100];\n static char buf2[100];\n\tstatic char buf3[202];\n clongdouble x;\n x = ((PyCLongDoubleScalarObject *)self)->obval;\n format_longdouble(buf1, sizeof(buf1), x.real, PREC_REPR);\n format_longdouble(buf2, sizeof(buf2), x.imag, PREC_REPR);\n\n\tsnprintf(buf3, sizeof(buf3), \"(%s+%sj)\", buf1, buf2);\n\treturn PyString_FromString(buf3);\n}\n\n#define longdoubletype_str longdoubletype_repr\n#define clongdoubletype_str clongdoubletype_repr\n\n/** Could improve this with a PyLong_FromLongDouble(longdouble ldval)\n but this would need some more work...\n**/\n\n/**begin repeat\n\n#name=(int, long, hex, oct, float)*2#\n#KIND=(Long*4, Float)*2#\n#char=,,,,,c*5#\n#CHAR=,,,,,C*5#\n#POST=,,,,,.real*5#\n*/\nstatic PyObject *\n@char@longdoubletype_@name@(PyObject *self)\n{\n\tdouble dval;\n\tPyObject *obj, *ret;\n\t\n\tdval = (double)(((Py@CHAR@LongDoubleScalarObject *)self)->obval)@POST@;\n\tobj = Py@KIND@_FromDouble(dval);\n\tret = obj->ob_type->tp_as_number->nb_@name@(obj);\n\tPy_DECREF(obj);\n\treturn ret;\n}\n/**end repeat**/\n\n#if PY_VERSION_HEX >= 0x02050000\n/* This needs a better implementation */\nstatic Py_ssize_t\ngentype_index(PyObject *self)\n{\n\tPyObject *obj;\n\tif (!(PyArray_IsScalar(self, Integer))) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"not an integer type.\");\n\t\treturn -1;\n\t}\n\tobj = gentype_int(self);\n\tif (obj == NULL) return -1;\n\treturn PyInt_AsSsize_t(obj);\t\n}\n#endif\n\n\nstatic PyNumberMethods gentype_as_number = {\n (binaryfunc)gentype_add,\t\t /*nb_add*/\n (binaryfunc)gentype_subtract,\t\t /*nb_subtract*/\n (binaryfunc)gentype_multiply,\t\t /*nb_multiply*/\n (binaryfunc)gentype_divide,\t\t /*nb_divide*/\n (binaryfunc)gentype_remainder,\t /*nb_remainder*/\n (binaryfunc)gentype_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)gentype_power,\t\t /*nb_power*/\n (unaryfunc)gentype_negative,\t \n (unaryfunc)gentype_positive, \t /*nb_pos*/ \n (unaryfunc)gentype_absolute,\t\t /*(unaryfunc)gentype_abs,*/\n (inquiry)gentype_nonzero_number,\t\t /*nb_nonzero*/\n (unaryfunc)gentype_invert,\t\t /*nb_invert*/\n (binaryfunc)gentype_lshift,\t /*nb_lshift*/\n (binaryfunc)gentype_rshift,\t /*nb_rshift*/\n (binaryfunc)gentype_and,\t /*nb_and*/\n (binaryfunc)gentype_xor,\t /*nb_xor*/\n (binaryfunc)gentype_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)gentype_int,\t\t /*nb_int*/\n (unaryfunc)gentype_long,\t\t /*nb_long*/\n (unaryfunc)gentype_float,\t\t /*nb_float*/\n (unaryfunc)gentype_oct,\t\t /*nb_oct*/\n (unaryfunc)gentype_hex,\t\t /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)gentype_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)gentype_true_divide,\t /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n\t(lenfunc)gentype_index, /* nb_index */\n#endif\n};\n\n\nstatic PyObject *\ngentype_richcompare(PyObject *self, PyObject *other, int cmp_op) \n{\n\n\tPyObject *arr, *ret;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tret = arr->ob_type->tp_richcompare(arr, other, cmp_op);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_ndim_get(PyObject *self)\n{\n\treturn PyInt_FromLong(0);\n}\n\nstatic PyObject *\ngentype_flags_get(PyObject *self)\n{\n return PyArray_NewFlagsObject(NULL);\n}\n\nstatic PyObject *\nvoidtype_flags_get(PyVoidScalarObject *self)\n{\n\treturn PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 1);\n}\n\nstatic PyObject *\nvoidtype_dtypedescr_get(PyVoidScalarObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n\nstatic PyObject *\ngentype_shape_get(PyObject *self)\n{\n\treturn PyTuple_New(0);\n}\n\n/*\nstatic int\ngentype_shape_set(PyObject *self, PyObject *val)\n{\n\tif (!PyTuple_Check(val) || PyTuple_GET_SIZE(val) > 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \\\n\t\t\t\t\"invalid shape for scalar\");\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n*/\n\nstatic PyObject *\ngentype_dataptr_get(PyObject *self)\n{\n\treturn Py_BuildValue(\"NO\",PyString_FromString(\"\"),Py_True);\n}\n\n\nstatic PyObject *\ngentype_data_get(PyObject *self)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\n\ttypecode = PyArray_DescrFromScalar(self);\n\tret = PyBuffer_FromObject(self, 0, typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\n\nstatic PyObject *\ngentype_itemsize_get(PyObject *self)\n{\t\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\n\ttypecode = PyArray_DescrFromScalar(self);\n\tret = PyInt_FromLong((long) typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_size_get(PyObject *self)\n{\n\treturn PyInt_FromLong(1);\n}\n\nstatic void\ngentype_struct_free(void *ptr, void *arr)\n{\n Py_DECREF((PyObject *)arr);\n _pya_free(ptr);\n}\n\nstatic PyObject *\ngentype_struct_get(PyObject *self)\n{\n PyArrayObject *arr;\n PyArrayInterface *inter;\n \n arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = 0;\n inter->flags = arr->flags;\n inter->typekind = arr->descr->kind;\n inter->itemsize = arr->descr->elsize;\n inter->strides = NULL;\n inter->shape = NULL;\n inter->data = arr->data;\n return PyCObject_FromVoidPtrAndDesc(inter, arr, gentype_struct_free);\n}\n\nstatic PyObject *\ngentype_typestr_get(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tret = PyObject_GetAttrString((PyObject *)arr->descr, \"str\");\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_descr_get(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tret = PyObject_GetAttrString((PyObject *)arr, \"__array_descr__\");\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\n\nstatic PyObject *\ngentype_typedescr_get(PyObject *self)\n{\n\treturn (PyObject *)PyArray_DescrFromScalar(self);\n}\n\n\nstatic PyObject *\ngentype_base_get(PyObject *self)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic PyArray_Descr *\n_realdescr_fromcomplexscalar(PyObject *self, int *typenum)\n{\n\tif PyArray_IsScalar(self, CDouble) {\n\t\t*typenum = PyArray_CDOUBLE;\n\t\treturn PyArray_DescrFromType(PyArray_DOUBLE);\n\t}\n\tif PyArray_IsScalar(self, CFloat) {\n\t\t*typenum = PyArray_CFLOAT;\n\t\treturn PyArray_DescrFromType(PyArray_FLOAT);\n\t}\n\tif PyArray_IsScalar(self, CLongDouble) {\n\t\t*typenum = PyArray_CLONGDOUBLE;\n\t\treturn PyArray_DescrFromType(PyArray_LONGDOUBLE);\n\t}\n\treturn NULL;\n}\n\nstatic PyObject *\ngentype_real_get(PyObject *self)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\tint typenum;\n\n\tif (PyArray_IsScalar(self, ComplexFloating)) {\n\t\ttypecode = _realdescr_fromcomplexscalar(self, &typenum);\n\t\tret = PyArray_Scalar(_SOFFSET_(self, typenum), typecode,\n\t\t\t\t NULL);\n\t\tPy_DECREF(typecode);\n\t\treturn ret;\n\t}\n\telse if PyArray_IsScalar(self, Object) {\n\t\tPyObject *obj = ((PyObjectScalarObject *)self)->obval;\n\t\tret = PyObject_GetAttrString(obj, \"real\");\n\t\tif (ret != NULL) return ret;\n\t\tPyErr_Clear();\n\t}\n\tPy_INCREF(self);\n\treturn (PyObject *)self;\n}\n\nstatic PyObject *\ngentype_imag_get(PyObject *self)\n{\t\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\t\n\tint typenum;\n\t\n\ttypecode = _realdescr_fromcomplexscalar(self, &typenum);\n\tif (PyArray_IsScalar(self, ComplexFloating)) {\n\t\tret = PyArray_Scalar(_SOFFSET_(self, typenum)\t\t\\\n\t\t\t\t + typecode->elsize, typecode, NULL);\n\t}\n\telse if PyArray_IsScalar(self, Object) {\n\t\tPyObject *obj = ((PyObjectScalarObject *)self)->obval;\n\t\tPyArray_Descr *newtype;\n\t\tret = PyObject_GetAttrString(obj, \"imag\");\n\t\tif (ret == NULL) {\n\t\t\tPyErr_Clear();\n\t\t\tobj = PyInt_FromLong(0);\n\t\t\tnewtype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\t\tret = PyArray_Scalar((char *)&obj, newtype, NULL);\n\t\t\tPy_DECREF(newtype);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tchar *temp;\n\t\ttemp = PyDataMem_NEW(typecode->elsize);\n\t\tmemset(temp, '\\0', typecode->elsize);\n\t\tret = PyArray_Scalar(temp, typecode, NULL);\n\t\tPyDataMem_FREE(temp);\n\t}\n\t\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_flat_get(PyObject *self)\n{\n\tPyObject *ret, *arr;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tret = PyArray_IterNew(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyGetSetDef gentype_getsets[] = {\n {\"ndim\", \n\t (getter)gentype_ndim_get, \n\t (setter) 0, \n\t \"number of array dimensions\"},\n {\"flags\", \n\t (getter)gentype_flags_get, \n\t (setter)0, \n\t \"integer value of flags\"},\n {\"shape\", \n\t (getter)gentype_shape_get, \n\t (setter)0, \n\t \"tuple of array dimensions\"},\n {\"strides\", \n\t (getter)gentype_shape_get, \n\t (setter) 0, \n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)gentype_data_get, \n\t (setter) 0, \n\t \"pointer to start of data\"},\n {\"itemsize\", \n\t (getter)gentype_itemsize_get, \n\t (setter)0, \n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)gentype_size_get,\n (setter)0,\n \"number of elements in the gentype\"},\n {\"nbytes\",\n (getter)gentype_itemsize_get,\n (setter)0,\n \"length of item in bytes\"},\n\t{\"base\",\n\t (getter)gentype_base_get,\n\t (setter)0,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)gentype_typedescr_get,\n\t NULL,\n\t \"get array data-descriptor\"},\n {\"real\", \n\t (getter)gentype_real_get, \n\t (setter)0,\n\t \"real part of scalar\"},\n {\"imag\", \n\t (getter)gentype_imag_get, \n\t (setter)0, \n\t \"imaginary part of scalar\"},\n\t{\"flat\", \n\t (getter)gentype_flat_get, \n\t (setter)0, \n\t \"a 1-d view of scalar\"}, \n\t{\"__array_data__\", \n\t (getter)gentype_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)gentype_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)gentype_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)gentype_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)gentype_shape_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)gentype_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t/* Does not have __array_priority__ because it is not a subtype.\n\t */\n \t{NULL, NULL, NULL, NULL} /* Sentinel */\n};\n\n\n/* 0-dim array from scalar object */\n\nstatic char doc_getarray[] = \"sc.__array__(|type) return 0-dim array\";\n\nstatic PyObject *\ngentype_getarray(PyObject *scalar, PyObject *args) \n{\n\tPyArray_Descr *outcode=NULL;\n\tPyObject *ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", &PyArray_DescrConverter,\n\t\t\t &outcode)) return NULL;\n\tret = PyArray_FromScalar(scalar, outcode);\n\treturn ret;\n}\n\nstatic char doc_sc_wraparray[] = \"sc.__array_wrap__(obj) return scalar from array\";\n\nstatic PyObject *\ngentype_wraparray(PyObject *scalar, PyObject *args)\n{\n\tPyObject *arr;\n\n\tif (PyTuple_Size(args) < 1) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"only accepts 1 argument.\");\n\t\treturn NULL;\n\t}\n\tarr = PyTuple_GET_ITEM(args, 0);\n\tif (!PyArray_Check(arr)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"can only be called with ndarray object\");\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_Scalar(PyArray_DATA(arr), PyArray_DESCR(arr), arr);\n}\n\n\n/**begin repeat\n\n#name=tolist, item, tostring, astype, copy, __deepcopy__, choose, searchsorted, reshape, view, swapaxes, conj, conjugate, nonzero, flatten, ravel, fill, transpose, newbyteorder#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *self, PyObject *args)\n{\n\treturn gentype_generic_method(self, args, NULL, \"@name@\");\n}\n/**end repeat**/\n\nstatic PyObject *\ngentype_squeeze(PyObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\tPy_INCREF(self);\n\treturn self;\n}\n\nstatic int\ngentype_getreadbuf(PyObject *, int, void **);\n\nstatic PyObject *\ngentype_byteswap(PyObject *self, PyObject *args)\n{\n\tBool inplace=FALSE;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter, &inplace))\n\t\treturn NULL;\n\t\n\tif (inplace) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot byteswap a scalar in-place\");\n\t\treturn NULL;\n\t}\n\telse {\n\t\t/* get the data, copyswap it and pass it to a new Array scalar\n\t\t */\n\t\tchar *data;\n\t\tint numbytes;\n\t\tPyArray_Descr *descr;\n\t\tPyObject *new;\n\t\tchar *newmem;\n\n\t\tnumbytes = gentype_getreadbuf(self, 0, (void **)&data);\n\t\tdescr = PyArray_DescrFromScalar(self);\n\t\tnewmem = _pya_malloc(descr->elsize);\n\t\tif (newmem == NULL) {Py_DECREF(descr); return PyErr_NoMemory();}\n\t\telse memcpy(newmem, data, descr->elsize);\n\t\tdescr->f->copyswap(newmem, NULL, 1, descr->elsize);\n\t\tnew = PyArray_Scalar(newmem, descr, NULL);\n\t\t_pya_free(newmem);\n\t\tPy_DECREF(descr);\n\t\treturn new;\n\t}\n}\n\n\n/**begin repeat\n\n#name=take, getfield, put, putmask, repeat, tofile, mean, trace, diagonal, clip, std, var, sum, cumsum, prod, cumprod, compress, sort, argsort, round, argmax, argmin, max, min, ptp, any, all, resize#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\treturn gentype_generic_method(self, args, kwds, \"@name@\");\n}\n/**end repeat**/\n\nstatic PyObject *\nvoidtype_getfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyObject *ret;\n\n\tret = gentype_generic_method((PyObject *)self, args, kwds, \"getfield\");\n\tif (!ret) return ret;\n\tif (PyArray_IsScalar(ret, Generic) &&\t\\\n\t (!PyArray_IsScalar(ret, Void))) {\n\t\tPyArray_Descr *new;\n\t\tif (!PyArray_ISNBO(self->descr->byteorder)) {\n\t\t\tnew = PyArray_DescrFromScalar(ret);\n\t\t\tnew->f->copyswap(_SOFFSET_(ret, \n\t\t\t\t\t\t new->type_num),\n\t\t\t\t\t NULL, 1, new->elsize);\n\t\t\tPy_DECREF(new);\n\t\t}\n\t}\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_setfield(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\t\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"Can't set fields in a non-void array scalar.\");\n\treturn NULL;\n}\t\n\nstatic PyObject *\nvoidtype_setfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *typecode;\n\tint offset = 0;\n\tPyObject *value, *src;\n\tint mysize;\n\tchar *dptr;\n\tstatic char *kwlist[] = {\"value\", \"dtype\", \"offset\", 0};/* XXX ? */\n\t\n\tif ((self->flags & WRITEABLE) != WRITEABLE) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"Can't write to memory\");\n\t\treturn NULL;\n\t}\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO&|i\", kwlist,\n\t\t\t\t\t &value,\n\t\t\t\t\t PyArray_DescrConverter, \n\t\t\t\t\t &typecode, &offset)) return NULL;\n\n\tmysize = self->ob_size;\n\t\n\tif (offset < 0 || (offset + typecode->elsize) > mysize) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need 0 <= offset <= %d for requested type \" \\\n\t\t\t \"but received offset = %d\",\n\t\t\t mysize-typecode->elsize, offset);\n\t\tPy_DECREF(typecode);\n\t\treturn NULL;\n\t}\t\n\n\tdptr = self->obval + offset;\n\n\t/* Copy data from value to correct place in dptr */\n src = PyArray_FromAny(value, typecode, 0, 0, CARRAY_FLAGS, NULL);\n if (src == NULL) return NULL;\n\ttypecode->f->copyswap(dptr, PyArray_DATA(src), \n\t\t\t !PyArray_ISNBO(self->descr->byteorder),\n\t\t\t PyArray_ITEMSIZE(src));\n\tPy_DECREF(src);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic PyObject *\ngentype_reduce(PyObject *self, PyObject *args)\n{\n\tPyObject *ret=NULL, *obj=NULL, *mod=NULL;\n\tconst char *buffer; \n\tint buflen;\n\n\t/* Return a tuple of (callable object, arguments) */\n\n\tret = PyTuple_New(2);\n\tif (ret == NULL) return NULL;\t\n\tif (PyObject_AsReadBuffer(self, (const void **)&buffer, &buflen)<0) {\n\t\tPy_DECREF(ret); return NULL;\n\t}\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) return NULL;\n\tobj = PyObject_GetAttrString(mod, \"scalar\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) return NULL;\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tobj = PyObject_GetAttrString((PyObject *)self, \"dtype\");\n\tif PyArray_IsScalar(self, Object) {\n\t\tmod = ((PyObjectScalarObject *)self)->obval;\n\t\tPyTuple_SET_ITEM(ret, 1,\n\t\t\t\t Py_BuildValue(\"NO\", obj, mod));\n\t}\n\telse {\n\t\tmod = PyString_FromStringAndSize(buffer, buflen);\n\t\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t\t Py_BuildValue(\"NN\", obj, mod));\n\t}\n\treturn ret;\n}\n\n/* ignores everything */\nstatic PyObject *\ngentype_setstate(PyObject *self, PyObject *args)\n{\n\tPy_INCREF(Py_None);\n\treturn (Py_None);\n}\n\nstatic PyObject *\ngentype_dump(PyObject *self, PyObject *args)\n{\n\tPyObject *file=NULL;\n\tint ret;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &file))\n\t\treturn NULL;\n\tret = PyArray_Dump(self, file, 2);\n\tif (ret < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyObject *\ngentype_dumps(PyObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\"))\n\t\treturn NULL;\n\treturn PyArray_Dumps(self, 2);\n}\n\n\n/* setting flags cannot be done for scalars */\nstatic PyObject *\ngentype_setflags(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* need to fill in doc-strings for these methods on import -- copy from \n array docstrings \n*/\nstatic PyMethodDef gentype_methods[] = {\n {\"tolist\",\t (PyCFunction)gentype_tolist,\t1, NULL},\n {\"item\", (PyCFunction)gentype_item, METH_VARARGS, NULL},\n\t{\"tofile\", (PyCFunction)gentype_tofile, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"tostring\", (PyCFunction)gentype_tostring, METH_VARARGS, NULL},\n {\"byteswap\", (PyCFunction)gentype_byteswap,1, NULL},\n {\"astype\", (PyCFunction)gentype_astype, 1, NULL},\n\t{\"getfield\", (PyCFunction)gentype_getfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{\"setfield\", (PyCFunction)gentype_setfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n {\"copy\", (PyCFunction)gentype_copy, 1, NULL}, \n {\"resize\", (PyCFunction)gentype_resize, 1, NULL}, \n\n\t{\"__array__\", (PyCFunction)gentype_getarray, 1, doc_getarray},\n\t{\"__array_wrap__\", (PyCFunction)gentype_wraparray, 1, doc_sc_wraparray},\n\n /* for the copy module */\n {\"__copy__\", (PyCFunction)gentype_copy, 1, NULL},\n {\"__deepcopy__\", (PyCFunction)gentype___deepcopy__, 1, NULL},\n\n\n {\"__reduce__\", (PyCFunction) gentype_reduce, 1, NULL},\t\n\t/* For consistency does nothing */\n\t{\"__setstate__\", (PyCFunction) gentype_setstate, 1, NULL},\n\n\t{\"dumps\", (PyCFunction) gentype_dumps, 1, NULL},\n\t{\"dump\", (PyCFunction) gentype_dump, 1, NULL},\n\n\t/* Methods for array */\n\t{\"fill\", (PyCFunction)gentype_fill,\n\t METH_VARARGS, NULL},\n\t{\"transpose\",\t(PyCFunction)gentype_transpose, \n\t METH_VARARGS, NULL},\n\t{\"take\",\t(PyCFunction)gentype_take, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"put\",\t(PyCFunction)gentype_put, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"putmask\",\t(PyCFunction)gentype_putmask, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"repeat\",\t(PyCFunction)gentype_repeat, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"choose\",\t(PyCFunction)gentype_choose, \n\t METH_VARARGS, NULL},\t\n\t{\"sort\",\t(PyCFunction)gentype_sort, \n\t METH_VARARGS, NULL},\n\t{\"argsort\",\t(PyCFunction)gentype_argsort, \n\t METH_VARARGS, NULL},\n\t{\"searchsorted\", (PyCFunction)gentype_searchsorted, \n\t METH_VARARGS, NULL},\t\n\t{\"argmax\",\t(PyCFunction)gentype_argmax, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"argmin\", (PyCFunction)gentype_argmin,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"reshape\",\t(PyCFunction)gentype_reshape, \n\t METH_VARARGS, NULL},\n\t{\"squeeze\",\t(PyCFunction)gentype_squeeze, \n\t METH_VARARGS, NULL},\n\t{\"view\", (PyCFunction)gentype_view, \n\t METH_VARARGS, NULL},\n\t{\"swapaxes\", (PyCFunction)gentype_swapaxes,\n\t METH_VARARGS, NULL},\n\t{\"max\", (PyCFunction)gentype_max,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"min\", (PyCFunction)gentype_min,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"ptp\", (PyCFunction)gentype_ptp,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"mean\", (PyCFunction)gentype_mean,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"trace\", (PyCFunction)gentype_trace,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"diagonal\", (PyCFunction)gentype_diagonal,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"clip\", (PyCFunction)gentype_clip,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"conj\", (PyCFunction)gentype_conj,\n\t METH_VARARGS, NULL},\n\t{\"conjugate\", (PyCFunction)gentype_conjugate,\n\t METH_VARARGS, NULL},\n\t{\"nonzero\", (PyCFunction)gentype_nonzero,\n\t METH_VARARGS, NULL},\n\t{\"std\", (PyCFunction)gentype_std,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"var\", (PyCFunction)gentype_var,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"sum\", (PyCFunction)gentype_sum,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"cumsum\", (PyCFunction)gentype_cumsum,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"prod\", (PyCFunction)gentype_prod,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"cumprod\", (PyCFunction)gentype_cumprod,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"all\", (PyCFunction)gentype_all,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"any\", (PyCFunction)gentype_any,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"compress\", (PyCFunction)gentype_compress,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"flatten\", (PyCFunction)gentype_flatten,\n\t METH_VARARGS, NULL},\n\t{\"ravel\", (PyCFunction)gentype_ravel,\n\t METH_VARARGS, NULL},\n\t{\"round\", (PyCFunction)gentype_round,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"setflags\", (PyCFunction)gentype_setflags,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"newbyteorder\", (PyCFunction)gentype_newbyteorder,\n\t METH_VARARGS, NULL},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\nstatic PyGetSetDef voidtype_getsets[] = {\n {\"flags\", \n\t (getter)voidtype_flags_get, \n\t (setter)0, \n\t \"integer value of flags\"},\n\t{\"dtype\",\n\t (getter)voidtype_dtypedescr_get,\n\t (setter)0,\n\t \"dtype object\"},\n\t{NULL, NULL}\n};\n\nstatic PyMethodDef voidtype_methods[] = {\n\t{\"getfield\", (PyCFunction)voidtype_getfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{\"setfield\", (PyCFunction)voidtype_setfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{NULL, NULL}\n};\n\n/************* As_mapping functions for void array scalar ************/\n\nstatic int\nvoidtype_length(PyVoidScalarObject *self) \n{\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\treturn 0;\n\t}\n\telse { /* return the number of fields */\n\t\tPyObject *key;\n\t\tPyObject *flist;\n\t\tkey = PyInt_FromLong(-1);\n\t\tflist = PyDict_GetItem(self->descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!flist) return 0;\n\t\treturn PyTuple_GET_SIZE(flist);\n\t}\n}\n\n/* get field by name or number */\nstatic PyObject *\nvoidtype_subscript(PyVoidScalarObject *self, PyObject *ind)\n{\n\tint n, m;\n\tchar *msg = \"invalid index\";\n\tPyObject *flist=NULL, *key, *fieldinfo;\n\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"can't index void scalar without fields\");\n\t\treturn NULL;\n\t}\n\n\tif (PyString_Check(ind) || PyUnicode_Check(ind)) {\n\t\t/* look up in fields */\n\t\tfieldinfo = PyDict_GetItem(self->descr->fields, ind);\n\t\tif (!fieldinfo) {\n\t\t\tPyErr_SetString(PyExc_IndexError, msg);\n\t\t\treturn NULL;\n\t\t}\n\t\treturn voidtype_getfield(self, fieldinfo, NULL);\n\t}\n\t\n\t/* try to convert it to a number */\n\tn = PyArray_PyIntAsIntp(ind);\n\tif (error_converting(n)) {\n\t\tPyErr_Clear();\n\t\tgoto fail;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tflist = PyDict_GetItem(self->descr->fields, key);\n\tPy_DECREF(key);\n\tif (!flist) m = 0; \n\tm = PyTuple_GET_SIZE(flist);\n\tif (n < 0) n += m;\n\tif (n < 0 || n >= m) goto fail;\n\tfieldinfo = PyDict_GetItem(self->descr->fields, \n\t\t\t\t PyTuple_GET_ITEM(flist, n));\n\treturn voidtype_getfield(self, fieldinfo, NULL);\n\n fail:\n\tPyErr_SetString(PyExc_IndexError, msg);\n\treturn NULL;\n}\n\nstatic int\nvoidtype_ass_subscript(PyVoidScalarObject *self, PyObject *ind, PyObject *val) \n{\n\tint n, m;\n\tchar *msg = \"invalid index\";\n\tPyObject *flist=NULL, *key, *fieldinfo, *newtup;\n\tPyObject *res;\n\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"can't index void scalar without fields\");\n\t\treturn -1;\n\t}\n\n\tif (PyString_Check(ind) || PyUnicode_Check(ind)) {\n\t\t/* look up in fields */\n\t\tfieldinfo = PyDict_GetItem(self->descr->fields, ind);\n\t\tif (!fieldinfo) {\n\t\t\tPyErr_SetString(PyExc_IndexError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tnewtup = Py_BuildValue(\"(OOO)\", val, \n\t\t\t\t PyTuple_GET_ITEM(fieldinfo, 0),\n\t\t\t\t PyTuple_GET_ITEM(fieldinfo, 1));\n\t\tres = voidtype_setfield(self, newtup, NULL);\n\t\tPy_DECREF(newtup);\n\t\tif (!res) return -1;\n\t\tPy_DECREF(res);\n\t\treturn 0;\n\t}\n\t\n\t/* try to convert it to a number */\n\tn = PyArray_PyIntAsIntp(ind);\n\tif (error_converting(n)) {\n\t\tPyErr_Clear();\n\t\tgoto fail;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tflist = PyDict_GetItem(self->descr->fields, key);\n\tPy_DECREF(key);\n\tif (!flist) m = 0; \n\tm = PyTuple_GET_SIZE(flist);\n\tif (n < 0) n += m;\n\tif (n < 0 || n >= m) goto fail;\n\tfieldinfo = PyDict_GetItem(self->descr->fields, \n\t\t\t\t PyTuple_GET_ITEM(flist, n));\n\tnewtup = Py_BuildValue(\"(OOO)\", val, \n\t\t\t PyTuple_GET_ITEM(fieldinfo, 0),\n\t\t\t PyTuple_GET_ITEM(fieldinfo, 1));\n\tres = voidtype_setfield(self, fieldinfo, NULL);\n\tPy_DECREF(newtup);\n\tif (!res) return -1;\n\tPy_DECREF(res);\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_IndexError, msg);\n\treturn -1;\n}\n\nstatic PyMappingMethods voidtype_as_mapping = {\n (inquiry)voidtype_length,\t\t /*mp_length*/\n (binaryfunc)voidtype_subscript,\t /*mp_subscript*/\n (objobjargproc)voidtype_ass_subscript,\t /*mp_ass_subscript*/\n};\n\n\nstatic int\ngentype_getreadbuf(PyObject *self, int segment, void **ptrptr)\n{\n\tint numbytes;\n\tPyArray_Descr *outcode;\n\t\n\tif (segment != 0) {\n\t\tPyErr_SetString(PyExc_SystemError, \n\t\t\t\t\"Accessing non-existent array segment\");\n\t\treturn -1;\n\t}\n\n\toutcode = PyArray_DescrFromScalar(self);\n\tnumbytes = outcode->elsize;\n\tif PyArray_IsScalar(self, Flexible) {\n\t\tif PyArray_IsScalar(self, String)\n\t\t\t*ptrptr = PyString_AS_STRING(self);\n\t\telse if PyArray_IsScalar(self, Unicode)\n\t\t\t*ptrptr = (char *)PyUnicode_AS_DATA(self);\n\t\telse if PyArray_IsScalar(self, Void)\n\t\t\t*ptrptr = ((PyVoidScalarObject *)self)->obval;\n\t}\n\telse \n\t\t*ptrptr = (void *)_SOFFSET_(self, outcode->type_num);\n\n\tPy_DECREF(outcode);\n\treturn numbytes;\n}\n\nstatic int\ngentype_getsegcount(PyObject *self, int *lenp)\n{\n\tPyArray_Descr *outcode;\n\n\toutcode = PyArray_DescrFromScalar(self);\n\tif (lenp)\n\t\t*lenp = outcode->elsize;\n\tPy_DECREF(outcode);\n\treturn 1;\n}\n\nstatic int\ngentype_getcharbuf(PyObject *self, int segment, const char **ptrptr)\n{\n\tif (PyArray_IsScalar(self, String) ||\t\\\n\t PyArray_IsScalar(self, Unicode))\n\t\treturn gentype_getreadbuf(self, segment, (void **)ptrptr);\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"Non-character array cannot be interpreted \"\\\n\t\t\t\t\"as character buffer.\");\n\t\treturn -1;\n\t}\n}\n\n\nstatic PyBufferProcs gentype_as_buffer = {\n (getreadbufferproc)gentype_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)0, /*bf_getwritebuffer*/\n (getsegcountproc)gentype_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)gentype_getcharbuf, /*bf_getcharbuffer*/\n};\n\n\n#define BASEFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES\n#define LEAFFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES\n\nstatic PyTypeObject PyGenericArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"genericscalar\",\t /*tp_name*/\n sizeof(PyObject),\t\t /*tp_basicsize*/\n};\n\nstatic void\nunicode_dealloc(PyObject *v) \n{\n\tPyDataMem_FREE(((PyVoidScalarObject *)v)->obval);\n\tv->ob_type->tp_free(v);\n}\n\nstatic void\nvoid_dealloc(PyVoidScalarObject *v) \n{\n\tif (v->flags & OWNDATA)\n\t\tPyDataMem_FREE(v->obval);\n\tPy_XDECREF(v->descr);\n\tPy_XDECREF(v->base);\n\tv->ob_type->tp_free(v);\n}\n\nstatic void\nobject_arrtype_dealloc(PyObject *v)\n{\n\tPy_XDECREF(((PyObjectScalarObject *)v)->obval);\n\tv->ob_type->tp_free(v);\n}\n\n/* string and unicode inherit from Python Type first and so GET_ITEM is different to\n get to the Python Type.\n */\n\n/**begin repeat \n#name=byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, object#\n#TYPE=BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, STRING, UNICODE, OBJECT#\n#num=1*16,0,0,1#\n*/\nstatic PyObject *\n@name@_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj=NULL;\n\tPyObject *arr;\n\tPyArray_Descr *typecode;\n\n\tif (type->tp_bases && (PyTuple_GET_SIZE(type->tp_bases)==2)) {\n\t\tPyTypeObject *sup;\n\t\tPyObject *ret;\n\t\t/* We are inheriting from a Python type as well so\n\t\t give it first dibs on conversion */\n\t\tsup = (PyTypeObject *)PyTuple_GET_ITEM(type->tp_bases, @num@);\n\t\tret = sup->tp_new(type, args, kwds);\n\t\tif (ret) return ret;\n\t\tPyErr_Clear();\n\t\t/* now do default conversion */\n\t}\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\n\ttypecode = PyArray_DescrFromType(PyArray_@TYPE@);\n\tarr = PyArray_FromAny(obj, typecode, 0, 0, FORCECAST, NULL);\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n/**end repeat**/\n\n/* bool->tp_new only returns Py_True or Py_False */\nstatic PyObject *\nbool_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj=NULL;\n\tPyObject *arr;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\tif (obj == Py_False)\n\t\tPyArrayScalar_RETURN_FALSE;\n\tif (obj == Py_True)\n\t\tPyArrayScalar_RETURN_TRUE;\n\tarr = PyArray_FROM_OTF(obj, PyArray_BOOL, FORCECAST);\n\tif (arr && 0 == PyArray_NDIM(arr)) {\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)PyArray_DATA(arr));\n\t}\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n\nstatic PyObject *\nbool_arrtype_and(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)&(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_and(a, b);\n}\n\nstatic PyObject *\nbool_arrtype_or(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)|(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_or(a, b);\n}\n\nstatic PyObject *\nbool_arrtype_xor(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)^(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_xor(a, b);\n}\n\nstatic int\nbool_arrtype_nonzero(PyObject *a)\n{\n\treturn a == PyArrayScalar_True;\n}\n\n/* Arithmetic methods -- only so we can override &, |, ^. */\nstatic PyNumberMethods bool_arrtype_as_number = {\n\tbool_arrtype_or,\t\t\t/* nb_add */\n\t0,\t\t\t\t\t/* nb_subtract */\n\tbool_arrtype_and,\t\t\t/* nb_multiply */\n\t0,\t\t\t\t\t/* nb_divide */\n\t0,\t\t\t\t\t/* nb_remainder */\n\t0,\t\t\t\t\t/* nb_divmod */\n\t0,\t\t\t\t\t/* nb_power */\n\t0,\t\t\t\t\t/* nb_negative */\n\t0,\t\t\t\t\t/* nb_positive */\n\t0,\t\t\t\t\t/* nb_absolute */\n\t(inquiry)bool_arrtype_nonzero,\t\t/* nb_nonzero */\n\t0,\t\t\t\t\t/* nb_invert */\n\t0,\t\t\t\t\t/* nb_lshift */\n\t0,\t\t\t\t\t/* nb_rshift */\n\t(binaryfunc)bool_arrtype_and,\t\t/* nb_and */\n\t(binaryfunc)bool_arrtype_xor,\t\t/* nb_xor */\n\t(binaryfunc)bool_arrtype_or,\t\t/* nb_or */\n};\n\nstatic PyObject *\nvoid_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj, *arr;\n\tulonglong memu=1;\n\tPyObject *new=NULL;\n\tchar *destptr;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\t/* For a VOID scalar first see if obj is an integer or long \n\t and create new memory of that size (filled with 0) for the scalar\n\t*/\n\n\tif (PyLong_Check(obj) || PyInt_Check(obj) || \\\n\t PyArray_IsScalar(obj, Integer) ||\n\t (PyArray_Check(obj) && PyArray_NDIM(obj)==0 &&\t\\\n\t PyArray_ISINTEGER(obj))) {\n\t\tnew = obj->ob_type->tp_as_number->nb_long(obj);\n\t}\n\tif (new && PyLong_Check(new)) {\n\t\tPyObject *ret;\n\t\tmemu = PyLong_AsUnsignedLongLong(new);\n\t\tPy_DECREF(new);\n\t\tif (PyErr_Occurred() || (memu > MAX_INT)) {\n\t\t\tPyErr_Clear();\n\t\t\tPyErr_Format(PyExc_OverflowError, \n\t\t\t\t \"size must be smaller than %d\",\n\t\t\t\t (int) MAX_INT);\n\t\t\treturn NULL;\n\t\t}\n\t\tdestptr = PyDataMem_NEW((int) memu);\n\t\tif (destptr == NULL) return PyErr_NoMemory();\n\t\tret = type->tp_alloc(type, 0);\n\t\tif (ret == NULL) {\n\t\t\tPyDataMem_FREE(destptr);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\t((PyVoidScalarObject *)ret)->obval = destptr;\n\t\t((PyVoidScalarObject *)ret)->ob_size = (int) memu;\n\t\t((PyVoidScalarObject *)ret)->descr = \\\n\t\t\tPyArray_DescrNewFromType(PyArray_VOID);\n\t\t((PyVoidScalarObject *)ret)->descr->elsize = (int) memu;\n\t\t((PyVoidScalarObject *)ret)->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t((PyVoidScalarObject *)ret)->base = NULL;\n\t\tmemset(destptr, '\\0', (size_t) memu);\n\t\treturn ret;\n\t}\n\n\tarr = PyArray_FROM_OTF(obj, PyArray_VOID, FORCECAST);\n return PyArray_Return((PyArrayObject *)arr);\n}\n\n\n/**************** Define Hash functions ********************/\n\n/**begin repeat\n#lname=bool,ubyte,ushort#\n#name=Bool,UByte, UShort#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n return (long)(((Py@name@ScalarObject *)obj)->obval);\n}\n/**end repeat**/\n\n/**begin repeat\n#lname=byte,short,uint,ulong#\n#name=Byte,Short,UInt,ULong#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((Py@name@ScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n/**end repeat**/\n\n#if SIZEOF_INT != SIZEOF_LONG\nstatic long\nint_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((PyIntScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n#endif\n\n/**begin repeat\n#char=,u#\n#Char=,U#\n#ext=&& (x >= LONG_MIN),#\n*/\n#if SIZEOF_LONG != SIZEOF_LONGLONG\n/* we assume SIZEOF_LONGLONG=2*SIZEOF_LONG */\nstatic long\n@char@longlong_arrtype_hash(PyObject *obj)\n{\n long y;\n @char@longlong x = (((Py@Char@LongLongScalarObject *)obj)->obval);\n\n if ((x <= LONG_MAX)@ext@) {\n y = (long) x;\n }\n else {\n union Mask {\n long hashvals[2];\n @char@longlong v;\n } both;\n\n both.v = x;\n y = both.hashvals[0] + (1000003)*both.hashvals[1];\n }\n if (y == -1) y = -2;\n return y;\n}\n#endif\n/**end repeat**/\n\n#if SIZEOF_LONG==SIZEOF_LONGLONG\nstatic long\nulonglong_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((PyULongLongScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n#endif\n\n\n\n/* Wrong thing to do for longdouble, but....*/\n/**begin repeat\n#lname=float, longdouble#\n#name=Float, LongDouble#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n return _Py_HashDouble((double) ((Py@name@ScalarObject *)obj)->obval);\n}\n\n/* borrowed from complex_hash */\nstatic long\nc@lname@_arrtype_hash(PyObject *obj)\n{\n long hashreal, hashimag, combined;\n hashreal = _Py_HashDouble((double) \\\n (((PyC@name@ScalarObject *)obj)->obval).real);\n\n if (hashreal == -1) return -1;\n hashimag = _Py_HashDouble((double) \\\n (((PyC@name@ScalarObject *)obj)->obval).imag);\n if (hashimag == -1) return -1;\n\n combined = hashreal + 1000003 * hashimag;\n if (combined == -1) combined = -2;\n return combined;\n}\n/**end repeat**/\n\nstatic long\nobject_arrtype_hash(PyObject *obj)\n{\n return PyObject_Hash(((PyObjectScalarObject *)obj)->obval);\n}\n\n/* just hash the pointer */\nstatic long\nvoid_arrtype_hash(PyObject *obj)\n{\n return _Py_HashPointer((void *)(((PyVoidScalarObject *)obj)->obval));\n}\n\n/*object arrtype getattro and setattro */\nstatic PyObject *\nobject_arrtype_getattro(PyObjectScalarObject *obj, PyObject *attr) {\n\tPyObject *res;\n\n\t/* first look in object and then hand off to generic type */\n\n\tres = PyObject_GenericGetAttr(obj->obval, attr);\t\n\tif (res) return res;\n\tPyErr_Clear();\n\treturn \tPyObject_GenericGetAttr((PyObject *)obj, attr);\n}\n\nstatic int\nobject_arrtype_setattro(PyObjectScalarObject *obj, PyObject *attr, PyObject *val) {\n\tint res;\n\t/* first look in object and then hand off to generic type */\n\n\tres = PyObject_GenericSetAttr(obj->obval, attr, val);\n\tif (res >= 0) return res;\n\tPyErr_Clear();\n\treturn PyObject_GenericSetAttr((PyObject *)obj, attr, val);\n}\n\nstatic PyObject *\nobject_arrtype_concat(PyObjectScalarObject *self, PyObject *other)\n{\n\treturn PySequence_Concat(self->obval, other);\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_length(PyObjectScalarObject *self) \n{\n\treturn PyObject_Length(self->obval);\n}\n\nstatic PyObject *\nobject_arrtype_repeat(PyObjectScalarObject *self, _int_or_ssize_t count)\n{\n\treturn PySequence_Repeat(self->obval, count);\n}\n\nstatic PyObject *\nobject_arrtype_subscript(PyObjectScalarObject *self, PyObject *key)\n{\n\treturn PyObject_GetItem(self->obval, key);\n}\n\nstatic int\nobject_arrtype_ass_subscript(PyObjectScalarObject *self, PyObject *key, \n\t\t\t PyObject *value)\n{\n\treturn PyObject_SetItem(self->obval, key, value);\n}\n\nstatic int\nobject_arrtype_contains(PyObjectScalarObject *self, PyObject *ob)\n{\n\treturn PySequence_Contains(self->obval, ob);\n}\n\nstatic PyObject *\nobject_arrtype_inplace_concat(PyObjectScalarObject *self, PyObject *o)\n{\n\treturn PySequence_InPlaceConcat(self->obval, o);\n}\n\nstatic PyObject *\nobject_arrtype_inplace_repeat(PyObjectScalarObject *self, _int_or_ssize_t count)\n{\n\treturn PySequence_InPlaceRepeat(self->obval, count);\n}\n\nstatic PySequenceMethods object_arrtype_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)object_arrtype_length, /*sq_length*/\n (binaryfunc)object_arrtype_concat, /*sq_concat*/\n (ssizeargfunc)object_arrtype_repeat, /*sq_repeat*/\n 0, /*sq_item*/\n 0, /*sq_slice*/\n 0, /* sq_ass_item */\n 0, /* sq_ass_slice */\n (objobjproc)object_arrtype_contains, /* sq_contains */\n (binaryfunc)object_arrtype_inplace_concat, /* sq_inplace_concat */\n (ssizeargfunc)object_arrtype_inplace_repeat, /* sq_inplace_repeat */\n#else\n (inquiry)object_arrtype_length, /*sq_length*/\n (binaryfunc)object_arrtype_concat, /*sq_concat*/\n (intargfunc)object_arrtype_repeat, /*sq_repeat*/\n 0, /*sq_item*/\n 0, /*sq_slice*/\n 0, /* sq_ass_item */\n 0, /* sq_ass_slice */\n (objobjproc)object_arrtype_contains, /* sq_contains */\n (binaryfunc)object_arrtype_inplace_concat, /* sq_inplace_concat */\n (intargfunc)object_arrtype_inplace_repeat, /* sq_inplace_repeat */\n#endif\n};\n\nstatic PyMappingMethods object_arrtype_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)object_arrtype_length,\n (binaryfunc)object_arrtype_subscript,\n (objobjargproc)object_arrtype_ass_subscript,\n#else\n (inquiry)object_arrtype_length,\n (binaryfunc)object_arrtype_subscript,\n (objobjargproc)object_arrtype_ass_subscript,\n#endif\n};\n\nstatic _int_or_ssize_t\nobject_arrtype_getsegcount(PyObjectScalarObject *self, _int_or_ssize_t *lenp) \n{\n\tint newlen;\n\tint cnt;\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\t\n\tif (pb == NULL || \\\n\t pb->bf_getsegcount == NULL || \\\n\t (cnt = (*pb->bf_getsegcount)(self->obval, &newlen)) != 1) \n\t\treturn 0;\n\t\n\tif (lenp) \n\t\t*lenp = newlen;\n\t\n\treturn cnt;\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_getreadbuf(PyObjectScalarObject *self, _int_or_ssize_t segment, void **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getreadbuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a readable buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getreadbuffer)(self->obval, segment, ptrptr);\n}\n\nstatic _int_or_ssize_t\nobject_arrtype_getwritebuf(PyObjectScalarObject *self, _int_or_ssize_t segment, void **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getwritebuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a writeable buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getwritebuffer)(self->obval, segment, ptrptr);\n}\n\nstatic _int_or_ssize_t \nobject_arrtype_getcharbuf(PyObjectScalarObject *self, _int_or_ssize_t segment, \n\t\t\t const char **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getcharbuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a character buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getcharbuffer)(self->obval, segment, ptrptr);\n}\n\nstatic PyBufferProcs object_arrtype_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)object_arrtype_getreadbuf,\n (writebufferproc)object_arrtype_getwritebuf,\n (segcountproc)object_arrtype_getsegcount,\n (charbufferproc)object_arrtype_getcharbuf,\n#else\n (getreadbufferproc)object_arrtype_getreadbuf,\n (getwritebufferproc)object_arrtype_getwritebuf,\n (getsegcountproc)object_arrtype_getsegcount,\n (getcharbufferproc)object_arrtype_getcharbuf,\n#endif\n};\n\nstatic PyObject *\nobject_arrtype_call(PyObjectScalarObject *obj, PyObject *args, PyObject *kwds)\n{\n\treturn PyObject_Call(obj->obval, args, kwds);\n}\n\nstatic PyTypeObject PyObjectArrType_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"objectscalar\",\t /*tp_name*/\n sizeof(PyObjectScalarObject),\t /*tp_basicsize*/\n 0, /* tp_itemsize */\n (destructor)object_arrtype_dealloc, /* tp_dealloc */\n 0, /* tp_print */\n 0, /* tp_getattr */\n 0, /* tp_setattr */\n 0, /* tp_compare */\n 0, /* tp_repr */\n 0, /* tp_as_number */\n &object_arrtype_as_sequence, /* tp_as_sequence */\n &object_arrtype_as_mapping, /* tp_as_mapping */\n 0, /* tp_hash */\n (ternaryfunc)object_arrtype_call, /* tp_call */\n 0, /* tp_str */\n (getattrofunc)object_arrtype_getattro, /* tp_getattro */\n (setattrofunc)object_arrtype_setattro, /* tp_setattro */\n &object_arrtype_as_buffer, /* tp_as_buffer */\n 0, /* tp_flags */\n};\n\n/**begin repeat\n#name=bool, string, unicode, void#\n#NAME=Bool, String, Unicode, Void#\n*/\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@scalar\",\t /*tp_name*/\n sizeof(Py@NAME@ScalarObject),\t /*tp_basicsize*/\n};\n/**end repeat**/\n\n/**begin repeat\n#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n#name=int*5, uint*5, float*3, complex*3#\n#CNAME=(CHAR, SHORT, INT, LONG, LONGLONG)*2, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n*/\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@\" STRBITSOF_@CNAME@ \"scalar\",\t /*tp_name*/\n sizeof(Py@NAME@ScalarObject),\t /*tp_basicsize*/\n};\n\n/**end repeat**/\n\n\nstatic PyNumberMethods longdoubletype_as_number;\nstatic PyNumberMethods clongdoubletype_as_number;\n\n\nstatic void\ninitialize_numeric_types(void)\n{\n\tPyGenericArrType_Type.tp_dealloc = (destructor)gentype_dealloc;\n\tPyGenericArrType_Type.tp_as_number = &gentype_as_number;\n\tPyGenericArrType_Type.tp_as_buffer = &gentype_as_buffer;\n\tPyGenericArrType_Type.tp_flags = BASEFLAGS;\n\tPyGenericArrType_Type.tp_methods = gentype_methods;\n\tPyGenericArrType_Type.tp_getset = gentype_getsets;\n\tPyGenericArrType_Type.tp_new = NULL;\n PyGenericArrType_Type.tp_alloc = gentype_alloc;\n\tPyGenericArrType_Type.tp_free = _pya_free;\n\tPyGenericArrType_Type.tp_repr = gentype_repr;\n\tPyGenericArrType_Type.tp_str = gentype_str;\n\tPyGenericArrType_Type.tp_richcompare = gentype_richcompare;\n\n\tPyBoolArrType_Type.tp_as_number = &bool_arrtype_as_number;\n\n\tPyStringArrType_Type.tp_alloc = NULL;\n\tPyStringArrType_Type.tp_free = NULL;\n\t\n\tPyStringArrType_Type.tp_repr = stringtype_repr;\n\tPyStringArrType_Type.tp_str = stringtype_str;\n\n\tPyUnicodeArrType_Type.tp_repr = unicodetype_repr;\n\tPyUnicodeArrType_Type.tp_str = unicodetype_str;\n\n\tPyVoidArrType_Type.tp_methods = voidtype_methods;\n\tPyVoidArrType_Type.tp_getset = voidtype_getsets;\n\tPyVoidArrType_Type.tp_as_mapping = &voidtype_as_mapping;\n\t\n\t/**begin repeat\n#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating, \nComplexFloating, Flexible, Character#\n\t*/\n Py@NAME@ArrType_Type.tp_flags = BASEFLAGS;\n\t/**end repeat**/\n\n\t/**begin repeat\n#name=bool, byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, void, object#\n#NAME=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, String, Unicode, Void, Object#\n\t*/\n\tPy@NAME@ArrType_Type.tp_flags = LEAFFLAGS;\n\tPy@NAME@ArrType_Type.tp_new = @name@_arrtype_new;\n\tPy@NAME@ArrType_Type.tp_richcompare = gentype_richcompare;\n\t/**end repeat**/\n\t/* Allow the Void type to be subclassed -- for adding new types */\n\tPyVoidArrType_Type.tp_flags = BASEFLAGS;\n\n /**begin repeat\n#name=bool, byte, short, ubyte, ushort, uint, ulong, ulonglong, float, longdouble, cfloat, clongdouble, void, object#\n#NAME=Bool, Byte, Short, UByte, UShort, UInt, ULong, ULongLong, Float, LongDouble, CFloat, CLongDouble, Void, Object#\n */\n Py@NAME@ArrType_Type.tp_hash = @name@_arrtype_hash;\n /**end repeat**/\n\n#if SIZEOF_INT != SIZEOF_LONG\n /* We won't be inheriting from Python Int type. */\n PyIntArrType_Type.tp_hash = int_arrtype_hash;\n#endif\n\n#if SIZEOF_LONG != SIZEOF_LONGLONG\n /* We won't be inheriting from Python Int type. */\n PyLongLongArrType_Type.tp_hash = longlong_arrtype_hash;\n#endif\n\n\t/* These need to be coded specially because getitem does not\n\t return a normal Python type\n\t*/\n\tPyLongDoubleArrType_Type.tp_as_number = &longdoubletype_as_number;\n\tPyCLongDoubleArrType_Type.tp_as_number = &clongdoubletype_as_number;\n\n\t/**begin repeat\n#name=int, long, hex, oct, float, repr, str#\n#kind=tp_as_number->nb*5, tp*2#\n\t*/\n\tPyLongDoubleArrType_Type.@kind@_@name@ = longdoubletype_@name@;\n\tPyCLongDoubleArrType_Type.@kind@_@name@ = clongdoubletype_@name@;\n\t/**end repeat**/\n\n\tPyStringArrType_Type.tp_itemsize = sizeof(char);\n\tPyVoidArrType_Type.tp_dealloc = (destructor) void_dealloc;\n\tPyUnicodeArrType_Type.tp_dealloc = unicode_dealloc;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMapIter_Type.tp_iter = PyObject_SelfIter;\n\n/**begin repeat\n#name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,#\n#num=BOOL, BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, OBJECT, NTYPES#\n**/\n PyArrayScalar_Offset[PyArray_@num@] = (int) offsetof(Py@name@ScalarObject, obval);\n/**end repeat**/\n}\n\n\n/* the order of this table is important */\nstatic PyTypeObject *typeobjects[] = {\n &PyBoolArrType_Type,\n &PyByteArrType_Type,\n\t&PyUByteArrType_Type,\n &PyShortArrType_Type,\n &PyUShortArrType_Type,\n\t&PyIntArrType_Type,\n\t&PyUIntArrType_Type,\n\t&PyLongArrType_Type,\n\t&PyULongArrType_Type,\n\t&PyLongLongArrType_Type,\n\t&PyULongLongArrType_Type,\n\t&PyFloatArrType_Type,\n\t&PyDoubleArrType_Type,\n\t&PyLongDoubleArrType_Type,\n\t&PyCFloatArrType_Type,\n\t&PyCDoubleArrType_Type,\n\t&PyCLongDoubleArrType_Type,\n\t&PyObjectArrType_Type,\n\t&PyStringArrType_Type,\n\t&PyUnicodeArrType_Type,\n\t&PyVoidArrType_Type\n};\n\nstatic int\n_typenum_fromtypeobj(PyObject *type, int user)\n{\n\tint typenum, i;\n\n\ttypenum = PyArray_NOTYPE;\n i = 0;\n\twhile(i < PyArray_NTYPES) {\n\t\tif (type == (PyObject *)typeobjects[i]) {\n\t\t\ttypenum = i;\n\t\t\tbreak;\n\t\t}\n i++;\n\t}\n\t\n\tif (!user) return typenum;\n\n\t/* Search any registered types */\n\ti = 0;\n\twhile (i < PyArray_NUMUSERTYPES) {\n\t\tif (type == (PyObject *)(userdescrs[i]->typeobj)) {\n\t\t\ttypenum = i + PyArray_USERDEF;\n\t\t\tbreak;\n\t\t}\n\t\ti++;\n\t}\n\treturn typenum;\n}\n\n/* new reference */\nstatic PyArray_Descr *\nPyArray_DescrFromTypeObject(PyObject *type)\n{\t\n\tint typenum;\n\tPyArray_Descr *new, *conv=NULL;\n\n\t/* if it's a builtin type, then use the typenumber */\n\ttypenum = _typenum_fromtypeobj(type,1);\t\n\tif (typenum != PyArray_NOTYPE) {\n\t\tnew = PyArray_DescrFromType(typenum);\n\t\tif (PyTypeNum_ISUSERDEF(typenum)) goto finish;\n\t\treturn new;\n\t}\n\n\t/* Check the generic types */\n\tif ((type == (PyObject *) &PyNumberArrType_Type) ||\t\t\\\n\t (type == (PyObject *) &PyInexactArrType_Type) ||\t\t\\\n\t (type == (PyObject *) &PyFloatingArrType_Type))\n\t\ttypenum = PyArray_DOUBLE;\n\telse if (type == (PyObject *)&PyComplexFloatingArrType_Type)\n\t\ttypenum = PyArray_CDOUBLE;\n\telse if ((type == (PyObject *)&PyIntegerArrType_Type) ||\t\\\n\t\t (type == (PyObject *)&PySignedIntegerArrType_Type))\n\t\ttypenum = PyArray_LONG;\n\telse if (type == (PyObject *) &PyUnsignedIntegerArrType_Type)\n\t\ttypenum = PyArray_ULONG;\n\telse if (type == (PyObject *) &PyCharacterArrType_Type)\n\t\ttypenum = PyArray_STRING;\n\telse if ((type == (PyObject *) &PyGenericArrType_Type) || \\\n\t\t (type == (PyObject *) &PyFlexibleArrType_Type))\n\t\ttypenum = PyArray_VOID;\n\n\tif (typenum != PyArray_NOTYPE) {\n\t\treturn PyArray_DescrFromType(typenum);\n\t}\n\t\n\t/* Otherwise --- type is a sub-type of an array scalar\n\t currently only VOID allows it -- use it as the type-object.\n\t*/\n\t/* look for a dtypedescr attribute */\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\n finish:\n\tconv = _arraydescr_fromobj(type);\n\tif (conv) {\n\t\tnew->fields = conv->fields;\n\t\tPy_INCREF(new->fields);\n\t\tnew->elsize = conv->elsize;\n\t\tnew->subarray = conv->subarray;\n\t\tconv->subarray = NULL;\n\t\tPy_DECREF(conv);\n\t}\n Py_DECREF(new->typeobj);\n new->typeobj = (PyTypeObject *)type;\n Py_INCREF(type);\n\treturn new;\n}\n\n/* New reference */\n/*OBJECT_API\n Return descr object from array scalar.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromScalar(PyObject *sc)\n{\n\tint type_num;\n\tPyArray_Descr *descr;\n\n\tif PyArray_IsScalar(sc, Void) {\n\t\tdescr = ((PyVoidScalarObject *)sc)->descr;\n\t\tPy_INCREF(descr);\n\t\treturn descr;\n\t}\n descr = PyArray_DescrFromTypeObject((PyObject *)sc->ob_type);\n if (descr->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(descr);\n type_num = descr->type_num;\n\t\tif (type_num == PyArray_STRING) \n\t\t\tdescr->elsize = PyString_GET_SIZE(sc);\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tdescr->elsize = PyUnicode_GET_DATA_SIZE(sc);\n#ifndef Py_UNICODE_WIDE\n\t\t\tdescr->elsize <<= 1;\n#endif\t\t\n\t\t}\n\t\telse {\n\t\t\tdescr->elsize =\t\t\t\t\t\\\n\t\t\t\t((PyVoidScalarObject *)sc)->ob_size;\n\t\t\tdescr->fields = PyObject_GetAttrString(sc, \"fields\");\n\t\t\tif (!descr->fields || !PyDict_Check(descr->fields) || \\\n\t\t\t (descr->fields == Py_None)) {\n\t\t\t\tPy_XDECREF(descr->fields);\n\t\t\t\tdescr->fields = NULL;\n\t\t\t}\n\t\t\tPyErr_Clear();\n\t\t}\n }\n\treturn descr;\n}\n\n/* New reference */\n/*OBJECT_API\n Get a typeobject from a type-number\n*/\nstatic PyObject *\nPyArray_TypeObjectFromType(int type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr == NULL) return NULL;\n\tobj = (PyObject *)descr->typeobj;\n\tPy_INCREF(obj);\n\tPy_DECREF(descr);\n\treturn obj;\n}\n\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "#name=tolist, item, tostring, astype, copy, __deepcopy__, choose, searchsorted, view, swapaxes, conj, conjugate, nonzero, flatten, ravel, fill, transpose, newbyteorder#", + "#name=take, getfield, put, putmask, repeat, tofile, mean, trace, diagonal, clip, std, var, sum, cumsum, prod, cumprod, compress, sort, argsort, round, argmax, argmin, max, min, ptp, any, all, resize, reshape#", + " {\"resize\", (PyCFunction)gentype_resize,", + "\t METH_VARARGS|METH_KEYWORDS, NULL},", + "\t METH_VARARGS|METH_KEYWORDS, NULL}," + ], + "deleted": [ + "#name=tolist, item, tostring, astype, copy, __deepcopy__, choose, searchsorted, reshape, view, swapaxes, conj, conjugate, nonzero, flatten, ravel, fill, transpose, newbyteorder#", + "#name=take, getfield, put, putmask, repeat, tofile, mean, trace, diagonal, clip, std, var, sum, cumsum, prod, cumprod, compress, sort, argsort, round, argmax, argmin, max, min, ptp, any, all, resize#", + " {\"resize\", (PyCFunction)gentype_resize, 1, NULL},", + "\t METH_VARARGS, NULL}," + ] + } + } + ] + } +] \ No newline at end of file